- Notifications
You must be signed in to change notification settings - Fork32
WIP: Add named classes for final blocks#58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
1164e21 to3024dd7CompareInstead of defining blocks in category_factory.gd, define blocks aheadof time, each in their own GDScript file. Although it is not a conceptin GDScript itself, we can consider block classes such as EntryBlock tobe abstract block types.By doing this, we are able to reduce duplication in the block scriptresource associated with each BlockCode node. In particular, theserialized data can simply refer to "PrintBlock", and all of theEntryBlock properties expected for the print block are implied.This commit only adds ReadyBlock and PrintBlock as an example, andlikely breaks everything else.
wjt commentedJun 24, 2024
At a high level I think this is the right direction: ignoring the Godot type system and scene/script split for a moment, I think conceptually it makes more sense for “Print block” to be a type, which gets instantiated; and the only data that should need persisting is where it is in the program, its type, and the user-supplied parameter. The current setup where the prototype print block in the sidebar is actually an instance of the statement block type, with its label in the block editor and the template for the generated GDScript, doesn't quite feel right, particularly because those properties get persisted into the user's game once per instance of the block despite being shared between all print blocks (and so you can't adjust the generated code without recreating every print statement or manually editing the scene files). The big block of boilerplate in Having experimented a little, and with the hint about abstract types in your commit message, I think we could do this a bit differently with less boilerplate. In Then define (I did a quick experiment and calling Then to instantiate the print block we have 3 options:
and (apart from infinite recursion issues) I think you could actually move this to the superclass (!).
I do not know how to persist that to disk, but if you |
Instead of defining blocks in category_factory.gd, define blocks ahead of time, each in their own GDScript file. Although it is not a concept in GDScript itself, we can consider block classes such as EntryBlock to be abstract block types.
By doing this, we are able to reduce duplication in the block script resource associated with each BlockCode node. In particular, the serialized data can simply refer to "PrintBlock", and all of the EntryBlock properties expected for the print block are implied.
This commit only adds ReadyBlock and PrintBlock as an example, and likely breaks everything else.