-
Notifications
You must be signed in to change notification settings - Fork 27
Serialization: Reuse SerializedBlock resources #137
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
We can do something similar to SerializedBlockTreeNode and SerializedBlockTreeNodeArray. But this totally breaks the undo/redo. The benefit of having the tree of resources being rebuilt each time is that it makes undo/redo so trivial. So marking this as draft for now. |
if resource == null: | ||
resource = SerializedBlock.new() | ||
resource.block_class = get_block_class() | ||
resource.serialized_props = get_serialized_props() |
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 might be nice to have this check if there are changes and return a boolean indicating that. That might help with the undo/redo functionality as there's no reason to add a change point if nothing has changed. Otherwise I think you'd have to pass the EditorUndoRedoManager
into here.
I certainly like that. Can you pass the |
496572d
to
5b8c349
Compare
Good point, yes I did so. Now the undo/redo works with block properties, like changing a parameter or moving the block to another position. Then I tried to do the same for the children blocks (path_child_pairs), but is not behaving correctly. I'm running out of ideas, it seems to be the tree being built recursively. Any help welcome! |
addons/block_code/ui/main_panel.gd
Outdated
if generated_script != block_script.generated_script: | ||
undo_redo.add_undo_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script) | ||
block_script.generated_script = generated_script | ||
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script) |
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.
We shouldn't be changing the generated_script property on our own here, and we should consistently use the var block_script: BlockScriptData
we defined earlier:
if generated_script != block_script.generated_script: | |
undo_redo.add_undo_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script) | |
block_script.generated_script = generated_script | |
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script) | |
if generated_script != block_script.generated_script: | |
undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script) | |
undo_redo.add_do_property(block_script, "generated_script", generated_script) |
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.
Turns out we're doing this in a lot of places. I included this and a bunch of similar fixes in #140.
@@ -38,6 +38,8 @@ var zoom: float: | |||
get: | |||
return _window.scale.x | |||
|
|||
var _undo_redo: EditorUndoRedoManager |
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.
Personally I would just pass this down in to build_tree
rather than stashing it in the object. It's only called internally to this object, so there's no danger of it breaking another user.
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 I though about that, I did it like this because is also used in the build_tree()
method that's called recursively. But yes it can be passed around to build_tree()
as parameter.
48bf072
to
f079f18
Compare
This is now ready for review thanks to @dylanmccall fixes. The undo-redo is now piling actions to the history instead of going back as before. I couldn't find how to fix it. But is usable (can undo, can redo). |
f079f18
to
eb1f780
Compare
The undo-redo piling actions was an issue in the input parameter, fixed in: #142 |
func update_resources(undo_redo: EditorUndoRedoManager): | ||
if resource == null: | ||
resource = SerializedBlockTreeNode.new() | ||
resource.serialized_block = SerializedBlock.new(get_block_class(), get_serialized_props()) |
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 you can return early here. There's no need to compare the serialized properties again if the serialized block was just constructed with them.
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 added a fixup commit for this. Hopefully it won't conflict with Dylan's changes in the same function when automerging.
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.
Looks good to me. From my perspective, feel free to merge after squashing the fixup.
Add a resource property to blocks. The resource will be updated before building the tree. This mitigates having a huge diff in scenes with blocks for minimum changes like moving a block in the canvas.
In block_canvas.gd, instead of modifying _current_bsd.block_trees.array outside of the UndoRedo action, use add_undo_property and add_do_property.
Pass it around.
261f08d
to
22ef121
Compare
Add a resource property to blocks of type SerializedBlock. The resource will be updated before building the tree.
This mitigates having a huge diff in scenes with blocks for minimum changes like moving a block in the canvas.
https://phabricator.endlessm.com/T35565