-
Notifications
You must be signed in to change notification settings - Fork 26
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
BlockScriptSerialization: Re-generate block definition for object property blocks #316
Merged
+125
−57
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be8f7f8
blocks_catalog: Introduce get_variable_(get|set)ter_block_definition()
starnight 98db5ef
BlockCanvas: Introduce get_property_(get|set)ter_block_definition for…
starnight 3b0aa95
BlockScriptSerialization: Build the bidirectional link between the bl…
starnight c7062ba
BlockScriptSerialization: Re-generate block definition for object pro…
starnight 5c3358d
BlockCanvas: Only can drop properties of the BlockCode's parent node
starnight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ const SCENE_PER_TYPE = { | |
@export var generated_script: String | ||
@export var version: int | ||
|
||
var block_code_node: BlockCode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A potential future improvement here would be to cache the parent properties when set so that |
||
|
||
var _available_blocks: Array[BlockDefinition] | ||
var _categories: Array[BlockCategory] | ||
|
||
|
@@ -81,22 +83,26 @@ func instantiate_block_by_name(block_name: String) -> Block: | |
|
||
func get_block_definition(block_name: String) -> BlockDefinition: | ||
var split := block_name.split(":", true, 1) | ||
var block_definition: BlockDefinition | ||
|
||
if len(split) > 1: | ||
return _get_parameter_block_definition(split[0], split[1]) | ||
|
||
var block_definition = _get_base_block_definition(block_name) | ||
block_definition = _get_base_block_definition(block_name) | ||
if block_definition != null: | ||
return block_definition | ||
|
||
if block_definition == null: | ||
# FIXME: This is a workaround for old-style output block references. | ||
# These were generated ahead of time using a block name that has | ||
# a "_" before the parameter name. Now, these parameter blocks | ||
# are generated on demand for any block name containing a ":". | ||
# Please remove this fallback when it is no longer necessary. | ||
split = block_name.rsplit("_", true, 1) | ||
return _get_parameter_block_definition(split[0], split[1]) | ||
block_definition = _get_obj_property_block_definition(block_name) | ||
if block_definition != null: | ||
return block_definition | ||
|
||
return block_definition | ||
# FIXME: This is a workaround for old-style output block references. | ||
# These were generated ahead of time using a block name that has | ||
# a "_" before the parameter name. Now, these parameter blocks | ||
# are generated on demand for any block name containing a ":". | ||
# Please remove this fallback when it is no longer necessary. | ||
split = block_name.rsplit("_", true, 1) | ||
return _get_parameter_block_definition(split[0], split[1]) | ||
|
||
|
||
func _get_base_block_definition(block_name: String) -> BlockDefinition: | ||
|
@@ -133,6 +139,49 @@ func _get_parameter_block_definition(block_name: String, parameter_name: String) | |
return block_definition | ||
|
||
|
||
func _get_obj_property_block_definition(block_name: String) -> BlockDefinition: | ||
var block_definition: BlockDefinition | ||
var variable: VariableDefinition | ||
var property_name: String | ||
var is_getter = true | ||
|
||
if block_name.begins_with("get_var_"): | ||
property_name = block_name.get_slice("get_var_", 1) | ||
elif block_name.begins_with("set_var_"): | ||
property_name = block_name.get_slice("set_var_", 1) | ||
is_getter = false | ||
else: | ||
return null | ||
|
||
# Getter block needs the property's variant type information by visiting the | ||
# block_code_node's parent node because the type is not saved as a key of | ||
# the resource in the scene file | ||
var property_info := _get_parent_node_property_info(property_name) | ||
if not property_info.has("type"): | ||
return null | ||
|
||
if is_getter: | ||
variable = VariableDefinition.new(property_name, property_info["type"]) | ||
block_definition = BlocksCatalog.get_property_getter_block_definition(variable) | ||
else: | ||
variable = VariableDefinition.new(property_name, property_info["type"]) | ||
block_definition = BlocksCatalog.get_property_setter_block_definition(variable) | ||
|
||
return block_definition | ||
|
||
|
||
func _get_parent_node_property_info(property_name: String) -> Dictionary: | ||
if not block_code_node: | ||
return {} | ||
|
||
var properties := block_code_node.get_parent().get_property_list() | ||
for property in properties: | ||
if property["name"] == property_name: | ||
return property | ||
|
||
return {} | ||
|
||
|
||
func _update_block_definitions(): | ||
_available_blocks.clear() | ||
_available_blocks.append_array(_get_inherited_block_definitions()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's a bit unfortunate that these property blocks will be in the Variables section, but I can't think of a better place at the moment.