Skip to content

Commit f6c8698

Browse files
authored
Merge pull request #280 from goatchurchprime/block-code-demo-scene
updates to make reloading of the blockcode work in game
2 parents a3b6ce2 + 71c97ea commit f6c8698

File tree

8 files changed

+100
-41
lines changed

8 files changed

+100
-41
lines changed

addons/block_code/block_code_plugin.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ static func is_block_code_editable(block_code: BlockCode) -> bool:
174174
if not block_code:
175175
return false
176176

177+
if not Engine.is_editor_hint():
178+
return true
179+
177180
# A BlockCode node can be edited if it belongs to the edited scene, or it
178181
# is an editable instance.
179182

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func _on_context_changed():
9898

9999
if Engine.is_editor_hint():
100100
edited_node = EditorInterface.get_inspector().get_edited_object() as Node
101-
101+
102102
if _context.block_script != _current_block_script:
103103
_window.position = Vector2(0, 0)
104104
zoom = 1

addons/block_code/ui/main_panel.gd

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func _on_undo_redo_version_changed():
6060

6161
func _on_show_script_button_pressed():
6262
var script: String = _block_canvas.generate_script_from_current_window()
63+
print("_on_show_script_button_pressed ", _block_canvas._context.block_code_node)
6364

6465
script_window_requested.emit(script)
6566

@@ -132,10 +133,7 @@ func save_script():
132133
print("No script loaded to save.")
133134
return
134135

135-
if not Engine.is_editor_hint():
136-
return
137-
138-
var scene_node = EditorInterface.get_edited_scene_root()
136+
var scene_node = EditorInterface.get_edited_scene_root() if Engine.is_editor_hint() else null
139137

140138
if not BlockCodePlugin.is_block_code_editable(_context.block_code_node):
141139
print("Block code for {node} is not editable.".format({"node": _context.block_code_node}))
@@ -146,29 +144,36 @@ func save_script():
146144
var resource_path_split = block_script.resource_path.split("::", true, 1)
147145
var resource_scene = resource_path_split[0]
148146

149-
undo_redo.create_action("Modify %s's block code script" % _context.parent_node.name, UndoRedo.MERGE_DISABLE, _context.block_code_node)
147+
if undo_redo:
148+
undo_redo.create_action("Modify %s's block code script" % _context.parent_node.name, UndoRedo.MERGE_DISABLE, _context.block_code_node)
150149

151-
if resource_scene and resource_scene != scene_node.scene_file_path:
150+
if resource_scene and scene_node and resource_scene != scene_node.scene_file_path:
152151
# This resource is from another scene. Since the user is changing it
153152
# here, we'll make a copy for this scene rather than changing it in the
154153
# other scene file.
155-
undo_redo.add_undo_property(_context.block_code_node, "block_script", _context.block_script)
154+
if undo_redo:
155+
undo_redo.add_undo_property(_context.block_code_node, "block_script", _context.block_script)
156156
block_script = block_script.duplicate(true)
157-
undo_redo.add_do_property(_context.block_code_node, "block_script", block_script)
157+
if undo_redo:
158+
undo_redo.add_do_property(_context.block_code_node, "block_script", block_script)
158159

159-
undo_redo.add_undo_property(block_script, "block_serialization_trees", block_script.block_serialization_trees)
160+
if undo_redo:
161+
undo_redo.add_undo_property(block_script, "block_serialization_trees", block_script.block_serialization_trees)
160162
_block_canvas.rebuild_ast_list()
161163
_block_canvas.rebuild_block_serialization_trees()
162-
undo_redo.add_do_property(block_script, "block_serialization_trees", block_script.block_serialization_trees)
164+
if undo_redo:
165+
undo_redo.add_do_property(block_script, "block_serialization_trees", block_script.block_serialization_trees)
163166

164167
var generated_script = _block_canvas.generate_script_from_current_window()
165168
if generated_script != block_script.generated_script:
166-
undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script)
167-
undo_redo.add_do_property(block_script, "generated_script", generated_script)
168-
169+
if undo_redo:
170+
undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script)
171+
undo_redo.add_do_property(block_script, "generated_script", generated_script)
172+
169173
block_script.version = Constants.CURRENT_DATA_VERSION
170174

171-
undo_redo.commit_action()
175+
if undo_redo:
176+
undo_redo.commit_action()
172177

173178

174179
func _input(event):
@@ -278,13 +283,18 @@ func _create_variable(variable: VariableDefinition):
278283

279284
var block_script: BlockScriptSerialization = _context.block_script
280285

281-
undo_redo.create_action("Create variable %s in %s's block code script" % [variable.var_name, _context.parent_node.name])
282-
undo_redo.add_undo_property(_context.block_script, "variables", _context.block_script.variables)
286+
if undo_redo:
287+
undo_redo.create_action("Create variable %s in %s's block code script" % [variable.var_name, _context.parent_node.name])
288+
undo_redo.add_undo_property(_context.block_script, "variables", _context.block_script.variables)
283289

284-
var new_variables = block_script.variables.duplicate()
285-
new_variables.append(variable)
290+
var new_variables = block_script.variables.duplicate()
291+
new_variables.append(variable)
286292

287-
undo_redo.add_do_property(_context.block_script, "variables", new_variables)
288-
undo_redo.commit_action()
293+
undo_redo.add_do_property(_context.block_script, "variables", new_variables)
294+
undo_redo.commit_action()
295+
else:
296+
var new_variables = block_script.variables.duplicate()
297+
new_variables.append(variable)
298+
block_script.variables = new_variables
289299

290300
_picker.reload_blocks()

0 commit comments

Comments
 (0)