Skip to content

Commit 20f5f54

Browse files
committed
Add version to block script data
In the plugin, add a new constant for the current data version. This will start in 0 and be bumped each time the data format changes. In the BlockScriptData resource, add an integer version field which defaults to zero. The version will be set to the current version when the resource is saved. The actual migration is TBD. Only a warning is printed for now. https://phabricator.endlessm.com/T35547
1 parent 60cd9c4 commit 20f5f54

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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: int
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 = 0):
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/constants.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends Object
22

3+
const CURRENT_DATA_VERSION = 0
4+
35
const KNOB_X = 10.0
46
const KNOB_W = 20.0
57
const KNOB_H = 5.0

addons/block_code/ui/main_panel.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extends Control
1515
@onready var _icon_collapse := EditorInterface.get_editor_theme().get_icon("Back", "EditorIcons")
1616
@onready var _icon_expand := EditorInterface.get_editor_theme().get_icon("Forward", "EditorIcons")
1717

18+
const Constants = preload("res://addons/block_code/ui/constants.gd")
19+
1820
var _current_block_code_node: BlockCode
1921
var _block_code_nodes: Array
2022
var _collapsed: bool = false
@@ -82,6 +84,14 @@ func _on_delete_dialog_confirmed(block_code_node: BlockCode):
8284
undo_redo.commit_action()
8385

8486

87+
func _try_migration():
88+
var version: int = _current_block_code_node.block_script.version
89+
if version == Constants.CURRENT_DATA_VERSION:
90+
# No migration needed.
91+
return
92+
push_warning("Migration not implemented from %d to %d" % [version, Constants.CURRENT_DATA_VERSION])
93+
94+
8595
func switch_scene(scene_root: Node):
8696
_title_bar.scene_selected(scene_root)
8797

@@ -90,6 +100,8 @@ func switch_block_code_node(block_code_node: BlockCode):
90100
var block_script: BlockScriptData = block_code_node.block_script if block_code_node else null
91101
_current_block_code_node = block_code_node
92102
_delete_node_button.disabled = _current_block_code_node == null
103+
if _current_block_code_node != null:
104+
_try_migration()
93105
_picker.bsd_selected(block_script)
94106
_title_bar.bsd_selected(block_script)
95107
_block_canvas.bsd_selected(block_script)
@@ -129,6 +141,7 @@ func save_script():
129141
var generated_script = _block_canvas.generate_script_from_current_window(block_script.script_inherits)
130142
block_script.block_trees = block_trees
131143
block_script.generated_script = generated_script
144+
block_script.version = Constants.CURRENT_DATA_VERSION
132145

133146
undo_redo.add_do_property(_current_block_code_node.block_script, "block_trees", block_trees)
134147
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", generated_script)

0 commit comments

Comments
 (0)