nodebox / seed

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

Allow sketches to import other sketches #5

Closed fdb closed 6 years ago

fdb commented 6 years ago

As a user I want to bring in other sketches in my sketches so I can re-use existing work/

As an example, you could create a "fake title" generator that could be used in a "fake news website" generator. Imagine we have a fake title generator saved as sketch -L41HTgXT1z6Vaxno2eR. This is how we could import it:

%import "-L41HTgXT1z6Vaxno2eR" as headline

root:
- <html><body><h1>Fake Gazette</h1>{{ article * 10 }}</body></html>

article:
- <article><h1>{{ headline }}</h1><a href="#">Read More...</a></article>

Because sketch URLs are immutable there are no version conflicts (although it makes it harder to upgrade them with new features).

This depends on #4 (preamble syntax).

kunal-mohta commented 6 years ago

Can I try this, if work not yet started on it?

stebanos commented 6 years ago

@kunal-mohta afaik, noone is working on this yet.

On a further note, I am wondering if, in the above example, 'headline' could serve as a namespace.

article would become then:

article:
- <article><h1>{{ headline.root }}</h1><a href="#">Read More...</a></article>

That way, individual pieces of a sketch could be reused. I'm not sure if we really need to go this far though.

kunal-mohta commented 6 years ago

That would be really nice. Let me first try getting the #import work, then we can further discuss on how far we need to go.

kunal-mohta commented 6 years ago

Are these lines meant for #import only? Or should I start with a different block?

stebanos commented 6 years ago

No, lines starting with # are considered comment lines and are now skipped. #import would be an exception to the rule.

kunal-mohta commented 6 years ago

Okay, I will take that into consideration. Currently I am facing some trouble handling the asynchronicity of the firebase.database() function. Is it fine if I take some more time to figure it out?

kunal-mohta commented 6 years ago

One more query, do we only have to import the code of the saved sketch, or the seed as well? What I mean is, should the code imported from the import statement follow the present seed or the one in which it was saved?

stebanos commented 6 years ago

No, I don't see any reason to import the seed value of the imported sketch.

kunal-mohta commented 6 years ago

I have tried something. It is not complete, but before working further on it I want to show it you so that we can figure out whether I am going in the right direction or not. Should I send a PR?

stebanos commented 6 years ago

Maybe you could set it up as a different branch on your forked repo of Seed? I could take a look at it then.

kunal-mohta commented 6 years ago

Sure. I will do that and send a PR?

stebanos commented 6 years ago

Ok.

stebanos commented 6 years ago

Okay so I have the basic case for 'import' covered, currently living inside the 'asyncPhrasebook' branch. It could be interesting to see how it could be further extended to the namespace thing I described above. Since the name of a block can contain period signs (except for two consecutively, this is reserved for ranges), this may require some extra attention.

kunal-mohta commented 6 years ago

Okay, I will have a look at your code. So should I continue working on this, or are you planning to implement it?

stebanos commented 6 years ago

If you can improve upon it, that would be great. I don't know yet if I have much time to work on it the next couple of days.

kunal-mohta commented 6 years ago

I can try it.

kunal-mohta commented 6 years ago

That is a very nice piece of code you have written. I wanted to clarify something. Are periods allowed in the names of the import statements. For example, is #import "key" as head.line valid?

kunal-mohta commented 6 years ago

Further, you have stored the data of the imported sketch in this format - screenshot 2018-02-19 19 26 01 So when a user writes , say for example {{ headline.root }}, what all things do you plan to display? Because the root key of the headline object is as screenshot 2018-02-19 19 29 20

stebanos commented 6 years ago

Well, if you 'import something as headline' then {{ headline.root }} should call root in 'something'. Now {{ headline }} automatically calls root, which is good, but I think {{ headline.root }} should also work.

But the syntax for imports also needs to change from the # character to the % character. It belongs to the preamble. Lines starting with a # should stay comments.

fdb commented 6 years ago

I also prefer the % over the # character, since # could be confused with comments.

fdb commented 6 years ago

This is now fixed in 9b44c587ef69ca51365d4161e4c6735b2056a964. We still need the documentation. At least in the cheat sheet, but perhaps this deserves its own reference page.

stebanos commented 6 years ago

The base issue has been covered and nobody is reading this anymore so I made two follow-up issues.