Conversation
1164e21 to
3024dd7
Compare
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.
3024dd7 to
42cbcdd
Compare
|
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.