nodebox / seed

Procedural Content Generator
https://seed.emrg.be/
MIT License
22 stars 8 forks source link

Add syntax for using items only once #31

Open fdb opened 6 years ago

fdb commented 6 years ago

When creating a new project it's often useful to only use terms once.

E.g. if you have a list of names or topics, you only want Seed to select from the list, but never show the same thing more than once.

We already have a syntax for re-using a selection:

{{ topic:one }}

I propose using the syntax for distinct elements:

{{ topic:~site }}

Internally what this does is generate a list of indices, one for each option, shuffled in random order. E.g. if a list of topics has 5 items the indices could look like this:

4 2 1 0 3

This implies that if you have 5 items, you can only use the {{ topic:~site }} token 5 times. If you use it more than 5 times, the list of indices is repeated (e.g. 4 2 1 0 3 4 2 1 0 3 ...).

kunal-mohta commented 6 years ago

@fdb I wasn't quite able to understand it. Could you make a sample sketch with comments as an aid?

fdb commented 6 years ago

Here's a demonstration for a news site generator:

https://seed.emrg.be/sketch/-L6GFAVSkAzLiyg3bu-s

screen shot 2018-02-26 at 09 36 37

Note that the topic "Lifestyle" occurs twice. I want to create a special syntax that forces the system to pick each topic only once, with the exception that if you use repeat more then there are topics, it will loop.

So if we have the topics News, Sports, Entertainment, Business, Politics, Lifestyle, Travel, the system will create a random ordering for the topic:~site key, e.g. indices 6 2 4 3 0 1 5. Each time you request topic:~site it will pick the next one from that randomly ordered list.

kunal-mohta commented 6 years ago

Okay, so the final syntax should be something like this -

root:
- <h1>Fake News Gazette<h1/>
  {{ module|repeat(5) }}

module:
- <h2>{{ topic:~site }}</h2>
  {{ article|repeat(3) }}

topic:
- News
- Sports
- Entertainment
- Business
- Politics
- Lifestyle
- Travel

article:
- <p>Article goes here...</p>

? And shouldn't the user be provided with an option to set a particular ordering of the topic:~site key along with the alternative of having a random order.