Skip to content

Commit 9f6ab77

Browse files
authored
Merge pull request #141 from endlessm/T35545-instantiate-simple-nodes
Change Simple node scripts to instantiate themselves
2 parents 2516bd1 + 5893a5a commit 9f6ab77

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

addons/block_code/examples/pong_game/pong_game.tscn

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
[ext_resource type="PackedScene" uid="uid://cg8ibi18um3vg" path="res://addons/block_code/examples/pong_game/space.tscn" id="1_y56ac"]
44
[ext_resource type="Script" path="res://addons/block_code/block_code_node/block_code.gd" id="3_6jaq8"]
5-
[ext_resource type="PackedScene" uid="uid://ddx1cd5q6t61o" path="res://addons/block_code/simple_nodes/simple_character/simple_character.tscn" id="3_hjpbs"]
5+
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_character/simple_character.gd" id="3_mdrcv"]
66
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block_tree_node.gd" id="4_qtggh"]
77
[ext_resource type="Texture2D" uid="uid://tplpgtnfeda0" path="res://addons/block_code/examples/pong_game/assets/paddle.png" id="4_ra7bh"]
88
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block.gd" id="5_wr38c"]
99
[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/serialized_block_tree_node_array.gd" id="6_ppdc3"]
1010
[ext_resource type="Script" path="res://addons/block_code/block_script_data/block_script_data.gd" id="7_uuuue"]
11-
[ext_resource type="PackedScene" uid="uid://bis7afjjuwypq" path="res://addons/block_code/simple_nodes/simple_scoring/simple_scoring.tscn" id="8_yg457"]
1211
[ext_resource type="PackedScene" uid="uid://c7l70grmkauij" path="res://addons/block_code/examples/pong_game/ball.tscn" id="9_xrqll"]
1312
[ext_resource type="PackedScene" uid="uid://fhoapg3anjsu" path="res://addons/block_code/examples/pong_game/goal_area.tscn" id="12_nqmxu"]
13+
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_scoring/simple_scoring.gd" id="13_tg3yk"]
1414

1515
[sub_resource type="Resource" id="Resource_k6jw1"]
1616
script = ExtResource("5_wr38c")
@@ -796,20 +796,22 @@ version = 0
796796

797797
[node name="Space" parent="." instance=ExtResource("1_y56ac")]
798798

799-
[node name="PaddleLeft" parent="." groups=["paddles"] instance=ExtResource("3_hjpbs")]
799+
[node name="PaddleLeft" type="CharacterBody2D" parent="." groups=["paddles"]]
800800
modulate = Color(0.509804, 0.360784, 0.972549, 1)
801801
position = Vector2(64, 544)
802802
collision_mask = 5
803+
script = ExtResource("3_mdrcv")
803804
texture = ExtResource("4_ra7bh")
804805

805806
[node name="BlockCode" type="Node" parent="PaddleLeft"]
806807
script = ExtResource("3_6jaq8")
807808
block_script = SubResource("Resource_qmak3")
808809

809-
[node name="PaddleRight" parent="." groups=["paddles"] instance=ExtResource("3_hjpbs")]
810+
[node name="PaddleRight" type="CharacterBody2D" parent="." groups=["paddles"]]
810811
modulate = Color(0.509804, 0.360784, 0.972549, 1)
811812
position = Vector2(1856, 544)
812813
collision_mask = 5
814+
script = ExtResource("3_mdrcv")
813815
texture = ExtResource("4_ra7bh")
814816

815817
[node name="BlockCode" type="Node" parent="PaddleRight"]
@@ -839,8 +841,9 @@ position = Vector2(1984, 544)
839841
script = ExtResource("3_6jaq8")
840842
block_script = SubResource("Resource_6drva")
841843

842-
[node name="SimpleScoring" parent="." instance=ExtResource("8_yg457")]
844+
[node name="SimpleScoring" type="CanvasLayer" parent="." groups=["hud"]]
843845
follow_viewport_enabled = true
846+
script = ExtResource("13_tg3yk")
844847

845848
[node name="BlockCode" type="Node" parent="SimpleScoring"]
846849
script = ExtResource("3_6jaq8")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@tool
2+
extends SimpleCharacter
3+
4+
5+
func _init():
6+
# Disable the SimpleCharacter _init function. We expect this script is
7+
# already bound to _simple_character.tscn.
8+
pass
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[gd_scene load_steps=3 format=3 uid="uid://ddx1cd5q6t61o"]
22

3-
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_character/simple_character.gd" id="1_oqwef"]
3+
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_character/_simple_character.gd" id="1_idjqv"]
44

5-
[sub_resource type="RectangleShape2D" id="RectangleShape2D_104qs"]
6-
size = Vector2(16, 16)
5+
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ffh0f"]
6+
size = Vector2(100, 100)
77

88
[node name="SimpleCharacter" type="CharacterBody2D"]
9-
script = ExtResource("1_oqwef")
9+
script = ExtResource("1_idjqv")
1010

1111
[node name="Sprite2D" type="Sprite2D" parent="."]
1212

1313
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
14-
shape = SubResource("RectangleShape2D_104qs")
14+
shape = SubResource("RectangleShape2D_ffh0f")

addons/block_code/simple_nodes/simple_character/simple_character.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func on_gravity_changed(new_gravity):
5252
gravity = new_gravity
5353

5454

55+
func _init():
56+
if self.get_parent():
57+
return
58+
59+
var node = preload("res://addons/block_code/simple_nodes/simple_character/_simple_character.tscn").instantiate() as Node
60+
node.replace_by(self, true)
61+
node.queue_free()
62+
scene_file_path = ""
63+
64+
5565
func _ready():
5666
add_to_group("affected_by_gravity")
5767
simple_setup()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@tool
2+
extends SimpleScoring
3+
4+
5+
func _init():
6+
# Disable the SimpleScoring _init function. We expect this script is
7+
# already bound to _simple_scoring.tscn.
8+
pass

addons/block_code/simple_nodes/simple_scoring/simple_scoring.tscn renamed to addons/block_code/simple_nodes/simple_scoring/_simple_scoring.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[gd_scene load_steps=2 format=3 uid="uid://bis7afjjuwypq"]
22

3-
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_scoring/simple_scoring.gd" id="1_yyb01"]
3+
[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_scoring/_simple_scoring.gd" id="1_lc5bg"]
44

55
[node name="SimpleScoring" type="CanvasLayer" groups=["hud"]]
6-
script = ExtResource("1_yyb01")
6+
script = ExtResource("1_lc5bg")
77

88
[node name="PlayerLeftScore" type="Label" parent="."]
99
unique_name_in_owner = true

addons/block_code/simple_nodes/simple_scoring/simple_scoring.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ const _POSITIONS_FOR_PLAYER = {
1919
}
2020

2121

22+
func _init():
23+
if self.get_parent():
24+
return
25+
26+
var node = preload("res://addons/block_code/simple_nodes/simple_scoring/_simple_scoring.tscn").instantiate() as Node
27+
node.replace_by(self, true)
28+
node.queue_free()
29+
print_tree_pretty()
30+
scene_file_path = ""
31+
32+
2233
func get_custom_class():
2334
return "SimpleScoring"
2435

0 commit comments

Comments
 (0)