-
Notifications
You must be signed in to change notification settings - Fork 27
T35591 more block definitions #199
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add target node class to the definition for class-specific blocks. For example, "On body entered / exited" block is specific to a node that inherits RigidBody2D. https://phabricator.endlessm.com/T35591
Here is more porting to the new block definitions. Compared with @wnbaum PR, this is using resource files, not through code like in f390ae8#diff-d355da8c634915f2c506c52aaf96eba422696b3c4b7cf0362804bd673b3a4767R431-R438 |
Should we transform the data type of raw_input, before assign to
|
Yes, thanks for pointing @starnight. I'll do it. The original PR has this in 0946f37 but that commit doesn't work well in isolation. |
I migrated the property blocks and the custom blocks. But now I have to change the tests. |
As defined by the target class in the resource file.
703e5d1
to
16eac33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read through all this and it looks good to me! It would be nice to make the InputMap stuff happen without the hack in blocks_catalog
, but I don't feel like we need to do that here. (And I was going to mess around with that type of thing in #191). This already lands us a significant upgrade from the previous setup :)
static func get_blocks_by_class(_class_name: String): | ||
if not _class_name in _by_class_name: | ||
return [] | ||
var block_definitions = _by_class_name[_class_name] as Dictionary | ||
return block_definitions.values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Is the aim for this to replace the setup_custom_blocks
thing we have right now (like with SimpleCharacter
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately no. See 028fa10 how I ported the custom blocks. Do you think they should be defined in resource files and added automatically to the catalog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that made sense to me once I got to the later commits :) I think that would be very clever if custom blocks were defined in resource files, but I can see how that's a tangent from the purpose of this branch. I'm tempted to play with that in another branch after I've done some more pressing things. A start would be to make BlocksCatalog._BLOCKS_PATH
a list and solve from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylanmccall you made me think that the ResourceLoader is already loading these resource files, so we are actually loading them twice using DirAccess. In fact, the DirAccess docs say "use ResourceLoader to access imported resources". So maybe a better idea would be:
- Add a custom extension to these resource files like
.block
or.blockdef
. - Add a ResourceFormatLoader that can handle that extension and add the block definitions to the catalog as they load.
Then custom resource files can be added to the user project without caring about the filesystem path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we had a custom extension it would also help later for translation since we likely need a custom translation parser that matches by file extension. That said, I think we should punt for the moment and try to get this work landed.
b = Util.instantiate_block(block_name) | ||
b = Util.instantiate_block_by_name(block_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here (already changing most references to b
), can we switch away from the single-letter variable name, maybe in a commit right before this one? I will find this nicer to read if we change b
to block
, especially now that there's much less else going on here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! It was bugging me as well.
return serialize_props(["color", "scope"]) | ||
return serialize_props(["scope"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooray!
Thanks for taking a deep look @dylanmccall . Now it should also work and tests are passing again. This is because the last commit which is basically @wnbaum 0946f37 plus some of 073eddd (the |
Adressed in commit 8d18e33 |
@starnight @dylanmccall @dbnicholson I think this is ready for a final review. Compared with the original PR #147:
|
Thank you @manuq! It is a big code refactoring. However, I notice if I add BlockCode under SimpleCharater and SimpleScoring node, it shows error:
|
I see it now, thanks. It seems that the block catalog is trying to add their blocks too early. If I switch to another BlockCode and then back to the SimpleCharacter one, I see the custom blocks. |
This is now fixed with the 2 last fixups. And the picker logic for custom blocks is much cleaner now! Because the
This would welcome a unit test. |
I just redid the Pong example with the new blocks in the PR. While doing it, I've found that there is a hack adding suffix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good to me besides some nitpicks. Feel free to squash and merge when you're ready!
_: | ||
return "%s" % input | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is unnecessary since the _
case will catch everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same when looking at @wnbaum branch. But if I remove this line, the syntax parser complains for the function saying "Not all code paths return a value.". So I understand why he added it.
addons/block_code/ui/util.gd
Outdated
@@ -50,7 +50,7 @@ static func instantiate_block_by_name(block_name: StringName) -> Block: | |||
return instantiate_block(block_definition) | |||
|
|||
|
|||
static func _get_subclasses(_class_name: String) -> Array[String]: | |||
static func _get_builtin_subclasses(_class_name: String) -> Array[String]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick. These aren't subclasses (classes that inherit this class), they're parent or inherited classes (what this class inherits from).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh of course! Good catch, I'll rename the function.
For this, the previous instantiate_block is renamed to instantiate_block_by_name.
And remove them from the category factory. Also add a default value for speed in the characterbody2d_move block. https://phabricator.endlessm.com/T35591
And change the body type from NODE_PATH to OBJECT, as in previous definitions. https://phabricator.endlessm.com/T35591
Port the property setter/changer/getter blocks to the new block definition. These are not loaded from resource files, they are defined in code. https://phabricator.endlessm.com/T35591
Add a way in the blocks catalog to add custom blocks. Port SimpleScoring and SimpleCharacter to the new block definitions. Change the picker logic to instantiate these blocks. https://phabricator.endlessm.com/T35591
For easier debugging.
And split obtaining the inputmap action names to a inner function. https://phabricator.endlessm.com/T35591
Using the new block definition. These are the only blocks that are not stored in the catalog. Instead, they are dynamically generated when the BlockScriptSerialization changes. Also: Move constant for the builtin category properties to the constants.gd script. Also: Finally remove the preloaded scene blocks from the category_factory.gd script. The single place where those scenes are now instantiated is the ui/util.gd script. https://phabricator.endlessm.com/T35591
Stop persisting the color in the serialization. https://phabricator.endlessm.com/T35591
Co-authored-by: Manuel Quiñones <[email protected]>
To avoid single character names.
64efb30
to
9dec121
Compare
https://phabricator.endlessm.com/T35591