-
Notifications
You must be signed in to change notification settings - Fork 28
Add version to block script data #122
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
extends Object | ||
|
||
const CURRENT_DATA_VERSION = 0 | ||
|
||
const KNOB_X = 10.0 | ||
const KNOB_W = 20.0 | ||
const KNOB_H = 5.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ extends Control | |
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons") | ||
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons") | ||
|
||
const Constants = preload("res://addons/block_code/ui/constants.gd") | ||
|
||
var _current_block_code_node: BlockCode | ||
var _block_code_nodes: Array | ||
var _collapsed: bool = false | ||
|
@@ -82,6 +84,14 @@ func _on_delete_dialog_confirmed(block_code_node: BlockCode): | |
undo_redo.commit_action() | ||
|
||
|
||
func _try_migration(): | ||
var version: int = _current_block_code_node.block_script.version | ||
if version == Constants.CURRENT_DATA_VERSION: | ||
# No migration needed. | ||
return | ||
push_warning("Migration not implemented from %d to %d" % [version, Constants.CURRENT_DATA_VERSION]) | ||
|
||
|
||
func switch_scene(scene_root: Node): | ||
_title_bar.scene_selected(scene_root) | ||
|
||
|
@@ -90,6 +100,8 @@ func switch_block_code_node(block_code_node: BlockCode): | |
var block_script: BlockScriptData = block_code_node.block_script if block_code_node else null | ||
_current_block_code_node = block_code_node | ||
_delete_node_button.disabled = _current_block_code_node == null | ||
if _current_block_code_node != null: | ||
_try_migration() | ||
_picker.bsd_selected(block_script) | ||
_title_bar.bsd_selected(block_script) | ||
_block_canvas.bsd_selected(block_script) | ||
|
@@ -129,6 +141,7 @@ func save_script(): | |
var generated_script = _block_canvas.generate_script_from_current_window(block_script.script_inherits) | ||
block_script.block_trees = block_trees | ||
block_script.generated_script = generated_script | ||
block_script.version = Constants.CURRENT_DATA_VERSION | ||
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. Can we arbitrarily update the version in the saved script if it hasn't been migrated? This is probably fine for now but eventually I'd expect 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. Yes, this is TBD. I guess we'll try a migration and if that fails the blocks shouldn't be editable at all, can't be saved. |
||
|
||
undo_redo.add_do_property(_current_block_code_node.block_script, "block_trees", block_trees) | ||
undo_redo.add_do_property(_current_block_code_node.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.
I think this is good enough for now, but in the future we might want to beef this up. If the stored data version is less than the current data version, migrate it. If the stored data version is greater than the current data version, then someone has already migrated the data to a newer plugin version and is now trying to run an older version of the plugin. Since the older plugin version by definition doesn't know about the newer data format, I think the only thing to do there would be to refuse to load the script and bring up some kind of error message.