Skip to content

Commit a5d1373

Browse files
authored
Merge pull request #178 from endlessm/T35536-renames
T35536 renames
2 parents 63db182 + b970b43 commit a5d1373

File tree

26 files changed

+191
-234
lines changed

26 files changed

+191
-234
lines changed

addons/block_code/block_code_node/block_code.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class_name BlockCode
44
extends Node
55

6-
@export var block_script: BlockScriptData = null
6+
@export var block_script: BlockScriptSerialization = null
77

88

99
func _ready():
@@ -25,10 +25,10 @@ func _enter_tree():
2525

2626
# Create script
2727
if block_script == null:
28-
var new_bsd: BlockScriptData = load("res://addons/block_code/ui/bsd_templates/default_bsd.tres").duplicate(true)
29-
new_bsd.script_inherits = _get_custom_or_native_class(get_parent())
30-
new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits)
31-
block_script = new_bsd
28+
var new_block_script: BlockScriptSerialization = load("res://addons/block_code/serialization/default_block_script.tres").duplicate(true)
29+
new_block_script.script_inherits = _get_custom_or_native_class(get_parent())
30+
new_block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits)
31+
block_script = new_block_script
3232

3333

3434
func _update_parent_script():

addons/block_code/block_code_plugin.gd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ var _selected_block_code: BlockCode
1919
var old_feature_profile: String = ""
2020

2121
const DISABLED_CLASSES := [
22-
"BlockScriptData",
2322
"Block",
2423
"ControlBlock",
2524
"ParameterBlock",
2625
"StatementBlock",
2726
"SnapPoint",
28-
"SerializedBlockTreeNodeArray",
29-
"SerializedBlockTreeNode",
30-
"SerializedBlock",
27+
"BlockSerialization",
28+
"BlockSerializedProperties",
29+
"BlockScriptSerialization",
3130
"CategoryFactory",
3231
]
3332

addons/block_code/blocks_catalog.gd renamed to addons/block_code/code_generation/blocks_catalog.gd

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

3-
const BlockDefinition = preload("res://addons/block_code/block_definition.gd")
3+
const BlockDefinition = preload("res://addons/block_code/code_generation/block_definition.gd")
44
const Types = preload("res://addons/block_code/types/types.gd")
55

66
static var _catalog: Dictionary
@@ -18,7 +18,7 @@ static func setup():
1818
block_definition.category = "Lifecycle"
1919
_catalog[&"ready_block"] = block_definition
2020

21-
block_definition = BlockDefinition.new(&"print", Types.BlockType.EXECUTE)
21+
block_definition = BlockDefinition.new(&"print", Types.BlockType.STATEMENT)
2222
block_definition.label_template = "print {text: STRING}"
2323
block_definition.code_template = "print({text})"
2424
block_definition.defaults = {"text": "Hello"}

addons/block_code/examples/pong_game/pong_game.tscn

Lines changed: 58 additions & 83 deletions
Large diffs are not rendered by default.

addons/block_code/block_script_data/block_script_data.gd renamed to addons/block_code/serialization/block_script_serialization.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
class_name BlockScriptData
1+
class_name BlockScriptSerialization
22
extends Resource
33

44
@export var script_inherits: String
5-
@export var block_trees: SerializedBlockTreeNodeArray
5+
@export var block_trees: Array[BlockSerialization]
66
@export var variables: Array[VariableResource]
77
@export var generated_script: String
88
@export var version: int
99

1010

11-
func _init(p_script_inherits: String = "", p_block_trees: SerializedBlockTreeNodeArray = null, p_variables: Array[VariableResource] = [], p_generated_script: String = "", p_version = 0):
11+
func _init(p_script_inherits: String = "", p_block_trees: Array[BlockSerialization] = [], p_variables: Array[VariableResource] = [], p_generated_script: String = "", p_version = 0):
1212
script_inherits = p_script_inherits
1313
block_trees = p_block_trees
1414
generated_script = p_generated_script
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
class_name SerializedBlockTreeNode
1+
class_name BlockSerialization
22
extends Resource
33

44
@export var name: StringName
55
@export var position: Vector2
66
@export var path_child_pairs: Array
77

88
# TODO: Remove once the data/UI decouple is done.
9-
@export var serialized_block: SerializedBlock
9+
@export var block_serialized_properties: BlockSerializedProperties
1010

1111

12-
func _init(p_name: StringName, p_position: Vector2 = Vector2.ZERO, p_serialized_block: SerializedBlock = null, p_path_child_pairs: Array = []):
12+
func _init(p_name: StringName, p_position: Vector2 = Vector2.ZERO, p_block_serialized_properties: BlockSerializedProperties = null, p_path_child_pairs: Array = []):
1313
name = p_name
1414
position = p_position
15-
serialized_block = p_serialized_block
15+
block_serialized_properties = p_block_serialized_properties
1616
path_child_pairs = p_path_child_pairs

addons/block_code/ui/block_canvas/serialized_block.gd renamed to addons/block_code/serialization/block_serialized_properties.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
class_name SerializedBlock
1+
class_name BlockSerializedProperties
22
extends Resource
33

4+
# TODO: Remove this class after removing the remaining serialization.
5+
46
@export var block_class: StringName
57
@export var serialized_props: Array
68

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[gd_resource type="Resource" script_class="BlockScriptSerialization" load_steps=6 format=3 uid="uid://dit7fykhl3h48"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="1_barc5"]
4+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialized_properties.gd" id="2_cgfpx"]
5+
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="4_cqq7x"]
6+
7+
[sub_resource type="Resource" id="Resource_b0aen"]
8+
script = ExtResource("2_cgfpx")
9+
block_class = &"EntryBlock"
10+
serialized_props = [["color", Color(0.92549, 0.231373, 0.34902, 1)], ["scope", ""], ["param_input_strings", {}]]
11+
12+
[sub_resource type="Resource" id="Resource_1h6wi"]
13+
script = ExtResource("1_barc5")
14+
name = &"ready_block"
15+
position = Vector2(54, 47)
16+
path_child_pairs = []
17+
block_serialized_properties = SubResource("Resource_b0aen")
18+
19+
[resource]
20+
script = ExtResource("4_cqq7x")
21+
script_inherits = "INHERIT_DEFAULT"
22+
block_trees = Array[ExtResource("1_barc5")]([SubResource("Resource_1h6wi")])
23+
variables = Array[Resource("res://addons/block_code/ui/block_canvas/variable_resource.gd")]([])
24+
generated_script = "extends INHERIT_DEFAULT"
25+
version = 0

addons/block_code/simple_nodes/simple_character/simple_character.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static func get_custom_blocks() -> Array[Block]:
118118
# Movement
119119
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
120120
b.block_name = "simplecharacter_move"
121-
b.block_type = Types.BlockType.EXECUTE
121+
b.block_type = Types.BlockType.STATEMENT
122122
b.block_format = "Move with {player: OPTION} buttons as {kind: OPTION}"
123123
# TODO: delta here is assumed to be the parameter name of
124124
# the _process or _physics_process method:

addons/block_code/simple_nodes/simple_scoring/simple_scoring.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ static func get_custom_blocks() -> Array[Block]:
7070
for player in _POSITIONS_FOR_PLAYER:
7171
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
7272
b.block_name = "simplescoring_set_score"
73-
b.block_type = Types.BlockType.EXECUTE
73+
b.block_type = Types.BlockType.STATEMENT
7474
b.block_format = "Set player %s score to {score: INT}" % player
7575
b.statement = "score_%s = {score}" % _POSITIONS_FOR_PLAYER[player]
7676
b.category = "Info | Score"
7777
block_list.append(b)
7878

7979
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
8080
b.block_name = "simplescoring_change_score"
81-
b.block_type = Types.BlockType.EXECUTE
81+
b.block_type = Types.BlockType.STATEMENT
8282
b.block_format = "Change player %s score by {score: INT}" % player
8383
b.statement = "score_%s += {score}" % _POSITIONS_FOR_PLAYER[player]
8484
b.category = "Info | Score"

addons/block_code/types/types.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ extends Node
33
enum BlockType {
44
NONE,
55
ENTRY,
6-
EXECUTE,
6+
STATEMENT,
77
VALUE,
8+
CONTROL,
89
}
910

1011
const VARIANT_TYPE_TO_STRING: Dictionary = {

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ZOOM_FACTOR: float = 1.1
3333
@onready var _mouse_override: Control = %MouseOverride
3434
@onready var _zoom_label: Label = %ZoomLabel
3535

36-
var _current_bsd: BlockScriptData
36+
var _current_block_script: BlockScriptSerialization
3737
var _block_scenes_by_class = {}
3838
var _panning := false
3939
var zoom: float:
@@ -96,12 +96,12 @@ func set_child(n: Node):
9696
set_child(c)
9797

9898

99-
func bsd_selected(bsd: BlockScriptData):
99+
func block_script_selected(block_script: BlockScriptSerialization):
100100
clear_canvas()
101101

102102
var edited_node = EditorInterface.get_inspector().get_edited_object() as Node
103103

104-
if bsd != _current_bsd:
104+
if block_script != _current_block_script:
105105
_window.position = Vector2(0, 0)
106106
zoom = 1
107107

@@ -115,18 +115,18 @@ func bsd_selected(bsd: BlockScriptData):
115115
_open_scene_button.disabled = true
116116
_replace_block_code_button.disabled = true
117117

118-
if bsd != null:
119-
_load_bsd(bsd)
118+
if block_script != null:
119+
_load_block_script(block_script)
120120
_window.visible = true
121121
_zoom_label.visible = true
122122

123-
if bsd != _current_bsd:
123+
if block_script != _current_block_script:
124124
reset_window_position()
125125
elif edited_node == null:
126126
_empty_box.visible = true
127127
elif BlockCodePlugin.node_has_block_code(edited_node):
128128
# If the selected node has a block code node, but BlockCodePlugin didn't
129-
# provide it to bsd_selected, we assume the block code itself is not
129+
# provide it to block_script_selected, we assume the block code itself is not
130130
# editable. In that case, provide options to either edit the node's
131131
# scene file, or override the BlockCode node. This is mostly to avoid
132132
# creating a situation where a node has multiple BlockCode nodes.
@@ -139,35 +139,28 @@ func bsd_selected(bsd: BlockScriptData):
139139
_selected_node_label.text = _selected_node_label_format.format({"node": edited_node.name})
140140
_add_block_code_button.disabled = false
141141

142-
_current_bsd = bsd
142+
_current_block_script = block_script
143143

144144

145-
func _load_bsd(bsd: BlockScriptData):
146-
for tree in bsd.block_trees.array:
145+
func _load_block_script(block_script: BlockScriptSerialization):
146+
for tree in block_script.block_trees:
147147
load_tree(_window, tree)
148148

149149

150-
func scene_has_bsd_nodes() -> bool:
151-
var scene_root = EditorInterface.get_edited_scene_root()
152-
if not scene_root:
153-
return false
154-
return scene_root.find_children("*", "BlockCode").size() > 0
155-
156-
157150
func clear_canvas():
158151
for child in _window.get_children():
159152
_window.remove_child(child)
160153
child.queue_free()
161154

162155

163-
func load_tree(parent: Node, node: SerializedBlockTreeNode):
156+
func load_tree(parent: Node, node: BlockSerialization):
164157
var scene: Block = Util.instantiate_block(node.name)
165158

166159
# TODO: Remove once the data/UI decouple is done.
167160
if scene == null:
168-
var _block_scene_path = _block_scenes_by_class[node.serialized_block.block_class]
161+
var _block_scene_path = _block_scenes_by_class[node.block_serialized_properties.block_class]
169162
scene = load(_block_scene_path).instantiate()
170-
for prop_pair in node.serialized_block.serialized_props:
163+
for prop_pair in node.block_serialized_properties.serialized_props:
171164
scene.set(prop_pair[0], prop_pair[1])
172165

173166
scene.position = node.position
@@ -182,14 +175,14 @@ func load_tree(parent: Node, node: SerializedBlockTreeNode):
182175

183176

184177
func rebuild_block_trees(undo_redo):
185-
var block_trees_array: Array[SerializedBlockTreeNode]
178+
var block_trees: Array[BlockSerialization]
186179
for c in _window.get_children():
187-
block_trees_array.append(build_tree(c, undo_redo))
188-
undo_redo.add_undo_property(_current_bsd.block_trees, "array", _current_bsd.block_trees.array)
189-
undo_redo.add_do_property(_current_bsd.block_trees, "array", block_trees_array)
180+
block_trees.append(build_tree(c, undo_redo))
181+
undo_redo.add_undo_property(_current_block_script, "block_trees", _current_block_script.block_trees)
182+
undo_redo.add_do_property(_current_block_script, "block_trees", block_trees)
190183

191184

192-
func build_tree(block: Block, undo_redo: EditorUndoRedoManager) -> SerializedBlockTreeNode:
185+
func build_tree(block: Block, undo_redo: EditorUndoRedoManager) -> BlockSerialization:
193186
var path_child_pairs = []
194187
block.update_resources(undo_redo)
195188

@@ -326,6 +319,6 @@ func set_mouse_override(override: bool):
326319
_mouse_override.mouse_default_cursor_shape = Control.CURSOR_ARROW
327320

328321

329-
func generate_script_from_current_window(bsd: BlockScriptData) -> String:
322+
func generate_script_from_current_window(block_script: BlockScriptSerialization) -> String:
330323
# TODO: implement multiple windows
331-
return BlockTreeUtil.generate_script_from_nodes(_window.get_children(), bsd)
324+
return BlockTreeUtil.generate_script_from_nodes(_window.get_children(), block_script)

addons/block_code/ui/block_canvas/serialized_block_tree_node_array.gd

Lines changed: 0 additions & 8 deletions
This file was deleted.

addons/block_code/ui/block_tree_util.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extends Object
33
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
44

55

6-
static func generate_script_from_nodes(nodes: Array[Node], bsd: BlockScriptData) -> String:
6+
static func generate_script_from_nodes(nodes: Array[Node], block_script: BlockScriptSerialization) -> String:
77
var entry_blocks_by_entry_statement: Dictionary = {}
88

99
for block in nodes:
@@ -18,9 +18,9 @@ static func generate_script_from_nodes(nodes: Array[Node], bsd: BlockScriptData)
1818

1919
var script: String = ""
2020

21-
script += "extends %s\n\n" % bsd.script_inherits
21+
script += "extends %s\n\n" % block_script.script_inherits
2222

23-
for variable in bsd.variables:
23+
for variable in block_script.variables:
2424
script += "var %s: %s\n\n" % [variable.var_name, type_string(variable.var_type)]
2525

2626
script += "\n"

addons/block_code/ui/blocks/block/block.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class_name Block
33
extends MarginContainer
44

5-
const BlocksCatalog = preload("res://addons/block_code/blocks_catalog.gd")
5+
const BlocksCatalog = preload("res://addons/block_code/code_generation/blocks_catalog.gd")
66
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
77
const Types = preload("res://addons/block_code/types/types.gd")
88

@@ -19,7 +19,7 @@ signal modified
1919
@export var color: Color = Color(1., 1., 1.)
2020

2121
## Type of block to check if can be attached to snap point
22-
@export var block_type: Types.BlockType = Types.BlockType.EXECUTE
22+
@export var block_type: Types.BlockType = Types.BlockType.STATEMENT
2323

2424
## Category to add the block to
2525
@export var category: String
@@ -32,7 +32,7 @@ signal modified
3232
@export var scope: String = ""
3333

3434
## The resource containing the block properties and the snapped blocks
35-
@export var resource: SerializedBlockTreeNode
35+
@export var resource: BlockSerialization
3636

3737
# FIXME: Add export to this variable and remove bottom_snap_path above.
3838
# There is a bug in Godot 4.2 that prevents using SnapPoint directly:
@@ -117,8 +117,8 @@ func get_instruction_node() -> InstructionTree.TreeNode:
117117

118118
func update_resources(undo_redo: EditorUndoRedoManager):
119119
if resource == null:
120-
var serialized_block = SerializedBlock.new(get_block_class(), get_serialized_props())
121-
resource = SerializedBlockTreeNode.new(block_name, position, serialized_block)
120+
var block_serialized_properties = BlockSerializedProperties.new(get_block_class(), get_serialized_props())
121+
resource = BlockSerialization.new(block_name, position, block_serialized_properties)
122122
return
123123

124124
if resource.position != position:
@@ -127,9 +127,9 @@ func update_resources(undo_redo: EditorUndoRedoManager):
127127

128128
var serialized_props = get_serialized_props()
129129

130-
if serialized_props != resource.serialized_block.serialized_props:
131-
undo_redo.add_undo_property(resource.serialized_block, "serialized_props", resource.serialized_block.serialized_props)
132-
undo_redo.add_do_property(resource.serialized_block, "serialized_props", serialized_props)
130+
if serialized_props != resource.block_serialized_properties.serialized_props:
131+
undo_redo.add_undo_property(resource.block_serialized_properties, "serialized_props", resource.block_serialized_properties.serialized_props)
132+
undo_redo.add_do_property(resource.block_serialized_properties, "serialized_props", serialized_props)
133133

134134

135135
# Override this method to add more serialized properties

addons/block_code/ui/blocks/statement_block/statement_block.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var param_input_strings: Dictionary # Only loaded from serialized
1919
func _ready():
2020
super()
2121

22-
if block_type != Types.BlockType.EXECUTE:
22+
if block_type != Types.BlockType.STATEMENT:
2323
_background.show_top = false
2424
_background.color = color
2525

addons/block_code/ui/blocks/utilities/snap_point/snap_point.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extends MarginContainer
44

55
const Types = preload("res://addons/block_code/types/types.gd")
66

7-
@export var block_type: Types.BlockType = Types.BlockType.EXECUTE
7+
@export var block_type: Types.BlockType = Types.BlockType.STATEMENT
88

99
@export var snapped_block: Block:
1010
get:

0 commit comments

Comments
 (0)