Skip to content

Commit 8acf1f2

Browse files
committed
Add version to block script data
1 parent b7cbac1 commit 8acf1f2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

addons/block_code/block_code_plugin.gd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ const DISABLED_CLASSES := [
4444
]
4545

4646

47+
func _get_version():
48+
var version: String = get_plugin_version()
49+
if version.match("$*$"):
50+
return "development"
51+
return version
52+
53+
4754
func _enter_tree():
4855
Types.init_cast_graph()
4956

5057
editor_inspector = EditorInterface.get_inspector()
5158

5259
main_panel = MainPanel.instantiate()
53-
main_panel.undo_redo = get_undo_redo()
60+
main_panel.setup(_get_version(), get_undo_redo())
5461

5562
# Add the main panel to the editor's main viewport.
5663
EditorInterface.get_editor_main_screen().add_child(main_panel)

addons/block_code/block_script_data/block_script_data.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ extends Resource
44
@export var script_inherits: String
55
@export var block_trees: SerializedBlockTreeNodeArray
66
@export var generated_script: String
7+
@export var version: String
78

89

9-
func _init(p_script_inherits: String = "", p_block_trees: SerializedBlockTreeNodeArray = null, p_generated_script: String = ""):
10+
func _init(p_script_inherits: String = "", p_block_trees: SerializedBlockTreeNodeArray = null, p_generated_script: String = "", p_version: String = ""):
1011
script_inherits = p_script_inherits
1112
block_trees = p_block_trees
1213
generated_script = p_generated_script
14+
version = p_version

addons/block_code/ui/main_panel.gd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var _scene_root: Node
1818
var _block_code_nodes: Array
1919
var _collapsed: bool = false
2020

21+
var plugin_version: String
2122
var undo_redo: EditorUndoRedoManager
2223

2324

@@ -33,6 +34,11 @@ func _ready():
3334
_collapse_button.icon = _icon_collapse
3435

3536

37+
func setup(p_plugin_version: String, p_undo_redo: EditorUndoRedoManager):
38+
plugin_version = p_plugin_version
39+
undo_redo = p_undo_redo
40+
41+
3642
func _on_undo_redo_version_changed():
3743
if _current_block_code_node == null:
3844
return
@@ -47,6 +53,16 @@ func _on_button_pressed():
4753
_print_generated_script()
4854

4955

56+
func _try_migration():
57+
var script_version = _current_block_code_node.block_script.version
58+
if script_version == plugin_version:
59+
# No migration needed.
60+
return
61+
if script_version.is_empty():
62+
script_version = "none"
63+
push_warning("Migration not implemented from %s to %s" % [script_version, plugin_version])
64+
65+
5066
func switch_scene(scene_root: Node):
5167
_title_bar.scene_selected(scene_root)
5268

@@ -58,6 +74,7 @@ func switch_script(block_code_node: BlockCode):
5874
_title_bar.bsd_selected(block_script)
5975
_block_canvas.bsd_selected(block_script)
6076
if block_code_node:
77+
_try_migration()
6178
EditorInterface.set_main_screen_editor("Block Code")
6279

6380

@@ -76,6 +93,7 @@ func save_script():
7693
var generated_script = _block_canvas.generate_script_from_current_window(block_script.script_inherits)
7794
block_script.block_trees = block_trees
7895
block_script.generated_script = generated_script
96+
block_script.version = plugin_version
7997

8098
undo_redo.add_do_property(_current_block_code_node.block_script, "block_trees", block_trees)
8199
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", generated_script)

0 commit comments

Comments
 (0)