Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3024dd7

Browse files
committed
WIP: Add named classes for final blocks
Instead of defining blocks in category_factory.gd, define blocks aheadof time, each in their own GDScript file. Although it is not a conceptin GDScript itself, we can consider block classes such as EntryBlock tobe abstract block types.By doing this, we are able to reduce duplication in the block scriptresource associated with each BlockCode node. In particular, theserialized data can simply refer to "PrintBlock", and all of theEntryBlock properties expected for the print block are implied.This commit only adds ReadyBlock and PrintBlock as an example, andlikely breaks everything else.
1 parentf98cdc0 commit3024dd7

File tree

6 files changed

+122
-13
lines changed

6 files changed

+122
-13
lines changed

‎addons/block_code/drag_manager/drag_manager.gd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func drag_block(block: Block, copied_from: Block = null):
117117

118118

119119
funccopy_block(block:Block)->Block:
120-
returnblock.duplicate(DUPLICATE_USE_INSTANTIATION)# use instantiation
120+
returnblock.copy_block()
121121

122122

123123
funccopy_picked_block_and_drag(block:Block):

‎addons/block_code/ui/block_canvas/block_canvas.gd‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,16 @@ func clear_canvas():
7171

7272
funcload_tree(parent:Node,node:SerializedBlockTreeNode):
7373
var_block_scene_path=_block_scenes_by_class[node.serialized_block.block_class]
74-
varscene:Block=load(_block_scene_path).instantiate()
74+
var_block_scene_resource=load(_block_scene_path)
75+
varscene:Block
76+
if_block_scene_resourceisPackedScene:
77+
scene=_block_scene_resource.instantiate()
78+
elif_block_scene_resourceisScript:
79+
scene=_block_scene_resource.new()
80+
else:
81+
push_error("Unable to instantiate block type: ",_block_scene_path)
82+
return
83+
7584
forprop_pairinnode.serialized_block.serialized_props:
7685
scene.set(prop_pair[0],prop_pair[1])
7786

‎addons/block_code/ui/picker/categories/category_factory.gd‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ static func get_general_categories() -> Array[BlockCategory]:
1515

1616
# Lifecycle
1717
varlifecycle_list:Array[Block]= []
18-
b=BLOCKS["entry_block"].instantiate()
19-
b.block_name="ready_block"
20-
b.block_format="On Ready"
21-
b.statement="func _ready():"
22-
lifecycle_list.append(b)
18+
19+
lifecycle_list.append(ReadyBlock.new())
2320

2421
b=BLOCKS["entry_block"].instantiate()
2522
b.block_name="process_block"
@@ -78,11 +75,7 @@ static func get_general_categories() -> Array[BlockCategory]:
7875
# Test
7976
vartest_list:Array[Block]= []
8077

81-
b=BLOCKS["statement_block"].instantiate()
82-
b.block_format="print{text: STRING}"
83-
b.statement="print({text})"
84-
b.defaults= {"text":"Hello"}
85-
test_list.append(b)
78+
test_list.append(PrintBlock.new())
8679

8780
vartest_category:BlockCategory=BlockCategory.new("Test",test_list,Color("9989df"))
8881

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@tool
2+
class_namePrintBlock
3+
extendsStatementBlock
4+
5+
func_init():
6+
var_block=load(StatementBlock.get_scene_path()).instantiate()asNode
7+
_block.replace_by(self,true)
8+
block_name=_block.block_name
9+
label=_block.label
10+
color=_block.color
11+
block_type=_block.block_type
12+
bottom_snap_path=_block.bottom_snap_path
13+
_block.queue_free()
14+
15+
block_name="print_block"
16+
block_format="print{text: STRING}"
17+
statement="print({text})"
18+
color=Color("9989df")
19+
20+
funccopy_block():
21+
returnPrintBlock.new()
22+
23+
staticfuncget_block_class():
24+
return"PrintBlock"
25+
26+
staticfuncget_scene_path():
27+
return"res://addons/block_code/ui/picker/categories/print_block.gd"
28+
29+
# Strip out properties that never change for this block type
30+
funcget_serialized_props()->Array:
31+
varprops=super()
32+
returnprops.filter(func(prop):returnprop[0]notin ["block_name","label","color","block_type","block_format","statement"])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@tool
2+
class_nameReadyBlock
3+
extendsEntryBlock
4+
5+
func_init():
6+
var_block=load(EntryBlock.get_scene_path()).instantiate()asNode
7+
_block.replace_by(self,true)
8+
block_name=_block.block_name
9+
label=_block.label
10+
color=_block.color
11+
block_type=_block.block_type
12+
bottom_snap_path=_block.bottom_snap_path
13+
_block.queue_free()
14+
15+
block_name="ready_block"
16+
block_format="On Ready"
17+
statement="func _ready():"
18+
color=Color("fa5956")
19+
20+
funccopy_block():
21+
returnReadyBlock.new()
22+
23+
staticfuncget_block_class():
24+
return"ReadyBlock"
25+
26+
staticfuncget_scene_path():
27+
return"res://addons/block_code/ui/picker/categories/ready_block.gd"
28+
29+
# Strip out properties that never change for this block type
30+
funcget_serialized_props()->Array:
31+
varprops=super()
32+
returnprops.filter(func(prop):returnprop[0]notin ["block_name","label","color","block_type","block_format","statement"])

‎test_game/test_game.tscn‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_sceneload_steps=177format=3uid="uid://bbwmxee7ukgul"]
1+
[gd_sceneload_steps=183format=3uid="uid://bbwmxee7ukgul"]
22

33
[ext_resourcetype="PackedScene"uid="uid://ddx1cd5q6t61o"path="res://addons/block_code/simple_nodes/simple_character/simple_character.tscn"id="1_hrpwq"]
44
[ext_resourcetype="Script"path="res://addons/block_code/block_code_node/block_code.gd"id="2_ewral"]
@@ -8,6 +8,45 @@
88
[ext_resourcetype="Script"path="res://addons/block_code/block_script_data/block_script_data.gd"id="5_q37d3"]
99
[ext_resourcetype="Texture2D"uid="uid://dr8e0tvfxjy1f"path="res://icon.svg"id="7_a27o8"]
1010

11+
[sub_resourcetype="Resource"id="Resource_bkrpj"]
12+
script =ExtResource("3_dpt5n")
13+
block_class = &"PrintBlock"
14+
serialized_props = [["position",Vector2(0,0)], ["param_input_strings", {
15+
"text":"test"
16+
}]]
17+
18+
[sub_resourcetype="Resource"id="Resource_8i26i"]
19+
script =ExtResource("2_pqvcj")
20+
serialized_block =SubResource("Resource_bkrpj")
21+
path_child_pairs = []
22+
23+
[sub_resourcetype="Resource"id="Resource_l25ts"]
24+
script =ExtResource("3_dpt5n")
25+
block_class = &"ReadyBlock"
26+
serialized_props = [["position",Vector2(156,133)], ["param_input_strings", {}]]
27+
28+
[sub_resourcetype="Resource"id="Resource_o5do6"]
29+
script =ExtResource("2_pqvcj")
30+
serialized_block =SubResource("Resource_l25ts")
31+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"),SubResource("Resource_8i26i")]]
32+
33+
[sub_resourcetype="Resource"id="Resource_vhdmi"]
34+
script =ExtResource("4_xt862")
35+
array = Array[ExtResource("2_pqvcj")]([SubResource("Resource_o5do6")])
36+
37+
[sub_resourcetype="Resource"id="Resource_t3mtx"]
38+
script =ExtResource("5_q37d3")
39+
script_inherits ="Camera2D"
40+
block_trees =SubResource("Resource_vhdmi")
41+
generated_script ="extends Camera2D
42+
43+
var VAR_DICT := {}
44+
45+
func _ready():
46+
print('test')
47+
48+
"
49+
1150
[sub_resourcetype="Resource"id="Resource_uwmna"]
1251
script =ExtResource("3_dpt5n")
1352
block_class = &"StatementBlock"
@@ -1109,6 +1148,10 @@ func _process(delta):
11091148

11101149
[nodename="Camera2D"type="Camera2D"parent="."]
11111150

1151+
[nodename="BlockCode"type="Node"parent="Camera2D"]
1152+
script =ExtResource("2_ewral")
1153+
block_script =SubResource("Resource_t3mtx")
1154+
11121155
[nodename="Will"parent="."instance=ExtResource("1_hrpwq")]
11131156
position =Vector2(-71,-18)
11141157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp