Skip to content

Commit 2772a46

Browse files
authored
Merge pull request #27 from endlessm/add-sound-block
Add simple sound node
2 parents caee3ae + 5c3e16b commit 2772a46

File tree

4 files changed

+144
-41
lines changed

4 files changed

+144
-41
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ static func get_general_categories() -> Array[BlockCategory]:
235235
var input_list: Array[Block] = _get_input_blocks()
236236
var input_category: BlockCategory = BlockCategory.new("Input", input_list, Color.SLATE_GRAY)
237237

238+
# Sound
239+
var sound_list: Array[Block] = []
240+
241+
b = BLOCKS["statement_block"].instantiate()
242+
b.block_type = Types.BlockType.EXECUTE
243+
b.block_format = "Load file {file_path: STRING} as sound {name: STRING}"
244+
b.statement = "var sound = AudioStreamPlayer.new()\nsound.name = {name}\nsound.set_stream(load({file_path}))\nadd_child(sound)\nsound.set_owner(self)"
245+
sound_list.append(b)
246+
247+
b = BLOCKS["statement_block"].instantiate()
248+
b.block_type = Types.BlockType.EXECUTE
249+
b.block_format = "Play the sound {name: STRING} with Volume dB {db: FLOAT} and Pitch Scale {pitch: FLOAT}"
250+
b.statement = "var sound = find_child({name})\nsound.volume_db = {db}\nsound.pitch_scale = {pitch}\nsound.play()"
251+
sound_list.append(b)
252+
253+
var sound_category: BlockCategory = BlockCategory.new("Sound", sound_list, Color("e30fc0"))
254+
238255
return [
239256
lifecycle_category,
240257
signal_category,
@@ -244,6 +261,7 @@ static func get_general_categories() -> Array[BlockCategory]:
244261
logic_category,
245262
variable_category,
246263
input_category,
264+
sound_category,
247265
]
248266

249267

test_game/test_audio.ogg

11.2 KB
Binary file not shown.

test_game/test_audio.ogg.import

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[remap]
2+
3+
importer="oggvorbisstr"
4+
type="AudioStreamOggVorbis"
5+
uid="uid://dm0l3peg0ecpe"
6+
path="res://.godot/imported/test_audio.ogg-b11846356471724ec6b59b00f5e31b53.oggvorbisstr"
7+
8+
[deps]
9+
10+
source_file="res://test_game/test_audio.ogg"
11+
dest_files=["res://.godot/imported/test_audio.ogg-b11846356471724ec6b59b00f5e31b53.oggvorbisstr"]
12+
13+
[params]
14+
15+
loop=false
16+
loop_offset=0
17+
bpm=0
18+
beat_count=0
19+
bar_beats=4

test_game/test_game.tscn

Lines changed: 107 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=169 format=3 uid="uid://bbwmxee7ukgul"]
1+
[gd_scene load_steps=177 format=3 uid="uid://bbwmxee7ukgul"]
22

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

11-
[sub_resource type="Resource" id="Resource_bq364"]
11+
[sub_resource type="Resource" id="Resource_uwmna"]
1212
script = ExtResource("3_dpt5n")
1313
block_class = &"StatementBlock"
14-
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.290196, 0.52549, 0.835294, 1)], ["block_type", 1], ["position", Vector2(0, 0)], ["block_format", "Move with player 2 buttons, speed {speed: INT}"], ["statement", "velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*{speed}
15-
move_and_slide()"], ["param_input_strings", {
16-
"speed": "600"
14+
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.890196, 0.0588235, 0.752941, 1)], ["block_type", 2], ["position", Vector2(0, 0)], ["block_format", "Load file {file_path: STRING} as sound {name: STRING}"], ["statement", "var sound = AudioStreamPlayer.new()
15+
sound.name = {name}
16+
sound.set_stream(load({file_path}))
17+
add_child(sound)
18+
sound.set_owner(self)"], ["param_input_strings", {
19+
"file_path": "res://test_game/test_audio.ogg",
20+
"name": "testsound"
1721
}]]
1822

19-
[sub_resource type="Resource" id="Resource_y4nnw"]
23+
[sub_resource type="Resource" id="Resource_5jnoq"]
2024
script = ExtResource("2_pqvcj")
21-
serialized_block = SubResource("Resource_bq364")
25+
serialized_block = SubResource("Resource_uwmna")
2226
path_child_pairs = []
2327

24-
[sub_resource type="Resource" id="Resource_a8l73"]
25-
script = ExtResource("3_dpt5n")
26-
block_class = &"EntryBlock"
27-
serialized_props = [["block_name", "physics_process_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 2], ["position", Vector2(460, 94)], ["block_format", "On Physics Process"], ["statement", "func _physics_process(delta):"], ["param_input_strings", {}]]
28-
29-
[sub_resource type="Resource" id="Resource_cel1g"]
30-
script = ExtResource("2_pqvcj")
31-
serialized_block = SubResource("Resource_a8l73")
32-
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_y4nnw")]]
33-
34-
[sub_resource type="Resource" id="Resource_xcbw7"]
28+
[sub_resource type="Resource" id="Resource_2niad"]
3529
script = ExtResource("3_dpt5n")
3630
block_class = &"StatementBlock"
3731
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.941176, 0.764706, 0, 1)], ["block_type", 1], ["position", Vector2(0, 0)], ["block_format", "Send signal {signal: STRING} to group {group: STRING}"], ["statement", "var signal_manager = get_tree().root.get_node_or_null(\"SignalManager\")
@@ -41,67 +35,139 @@ if signal_manager:
4135
"signal": "will_hi"
4236
}]]
4337

44-
[sub_resource type="Resource" id="Resource_8fbr0"]
38+
[sub_resource type="Resource" id="Resource_hb8ii"]
4539
script = ExtResource("2_pqvcj")
46-
serialized_block = SubResource("Resource_xcbw7")
47-
path_child_pairs = []
40+
serialized_block = SubResource("Resource_2niad")
41+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_5jnoq")]]
4842

49-
[sub_resource type="Resource" id="Resource_k0oqj"]
43+
[sub_resource type="Resource" id="Resource_nfmdk"]
5044
script = ExtResource("3_dpt5n")
5145
block_class = &"StatementBlock"
5246
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.941176, 0.764706, 0, 1)], ["block_type", 1], ["position", Vector2(0, 0)], ["block_format", "Add to group {group: STRING}"], ["statement", "add_to_group({group})"], ["param_input_strings", {
5347
"group": "Player"
5448
}]]
5549

56-
[sub_resource type="Resource" id="Resource_itbdf"]
50+
[sub_resource type="Resource" id="Resource_kiuvv"]
5751
script = ExtResource("2_pqvcj")
58-
serialized_block = SubResource("Resource_k0oqj")
59-
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_8fbr0")]]
52+
serialized_block = SubResource("Resource_nfmdk")
53+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_hb8ii")]]
6054

61-
[sub_resource type="Resource" id="Resource_mg1oj"]
55+
[sub_resource type="Resource" id="Resource_4xja7"]
6256
script = ExtResource("3_dpt5n")
6357
block_class = &"StatementBlock"
6458
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.6, 0.537255, 0.87451, 1)], ["block_type", 1], ["position", Vector2(0, 0)], ["block_format", "print {text: STRING}"], ["statement", "print({text})"], ["param_input_strings", {
6559
"text": "Hi Manuel!"
6660
}]]
6761

68-
[sub_resource type="Resource" id="Resource_3b5w0"]
62+
[sub_resource type="Resource" id="Resource_u6g84"]
6963
script = ExtResource("2_pqvcj")
70-
serialized_block = SubResource("Resource_mg1oj")
71-
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_itbdf")]]
64+
serialized_block = SubResource("Resource_4xja7")
65+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_kiuvv")]]
7266

73-
[sub_resource type="Resource" id="Resource_hu4fg"]
67+
[sub_resource type="Resource" id="Resource_6xoyl"]
7468
script = ExtResource("3_dpt5n")
7569
block_class = &"EntryBlock"
76-
serialized_props = [["block_name", "ready_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 2], ["position", Vector2(104, 85)], ["block_format", "On Ready"], ["statement", "func _ready():"], ["param_input_strings", {}]]
70+
serialized_props = [["block_name", "ready_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 1], ["position", Vector2(84, 33)], ["block_format", "On Ready"], ["statement", "func _ready():"], ["param_input_strings", {}]]
71+
72+
[sub_resource type="Resource" id="Resource_xdg8y"]
73+
script = ExtResource("2_pqvcj")
74+
serialized_block = SubResource("Resource_6xoyl")
75+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_u6g84")]]
76+
77+
[sub_resource type="Resource" id="Resource_7ot84"]
78+
script = ExtResource("3_dpt5n")
79+
block_class = &"ParameterBlock"
80+
serialized_props = [["block_name", "parameter_block"], ["label", "Param"], ["color", Color(0.439216, 0.501961, 0.564706, 1)], ["block_type", 3], ["position", Vector2(0, 0)], ["block_format", "Is action ui_right pressed"], ["statement", "Input.is_action_pressed(\"ui_right\")"], ["param_input_strings", {}]]
7781

78-
[sub_resource type="Resource" id="Resource_pyh8n"]
82+
[sub_resource type="Resource" id="Resource_xyinc"]
7983
script = ExtResource("2_pqvcj")
80-
serialized_block = SubResource("Resource_hu4fg")
81-
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_3b5w0")]]
84+
serialized_block = SubResource("Resource_7ot84")
85+
path_child_pairs = []
8286

83-
[sub_resource type="Resource" id="Resource_j1v52"]
87+
[sub_resource type="Resource" id="Resource_2ykxc"]
88+
script = ExtResource("3_dpt5n")
89+
block_class = &"StatementBlock"
90+
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.890196, 0.0588235, 0.752941, 1)], ["block_type", 2], ["position", Vector2(0, 0)], ["block_format", "Play the sound {name: STRING} with Volume dB {db: FLOAT} and Pitch Scale {pitch: FLOAT}"], ["statement", "var sound = find_child({name})
91+
sound.volume_db = {db}
92+
sound.pitch_scale = {pitch}
93+
sound.play()"], ["param_input_strings", {
94+
"db": "0.0",
95+
"name": "testsound",
96+
"pitch": "1.0"
97+
}]]
98+
99+
[sub_resource type="Resource" id="Resource_s07iu"]
100+
script = ExtResource("2_pqvcj")
101+
serialized_block = SubResource("Resource_2ykxc")
102+
path_child_pairs = []
103+
104+
[sub_resource type="Resource" id="Resource_tu70f"]
105+
script = ExtResource("3_dpt5n")
106+
block_class = &"ControlBlock"
107+
serialized_props = [["block_name", "control_block"], ["label", "Control Block"], ["color", Color(1, 0.678431, 0.462745, 1)], ["block_type", 2], ["position", Vector2(0, 0)], ["block_formats", ["if {cond: BOOL}"]], ["statements", ["if {cond}:"]], ["param_input_strings_array", [{
108+
"cond": ""
109+
}]]]
110+
111+
[sub_resource type="Resource" id="Resource_2hh05"]
112+
script = ExtResource("2_pqvcj")
113+
serialized_block = SubResource("Resource_tu70f")
114+
path_child_pairs = [[NodePath("VBoxContainer/MarginContainer/Rows/Row0/RowHBoxContainer/RowHBox/ParameterInput0/SnapPoint"), SubResource("Resource_xyinc")], [NodePath("VBoxContainer/MarginContainer/Rows/SnapContainer0/SnapPoint"), SubResource("Resource_s07iu")]]
115+
116+
[sub_resource type="Resource" id="Resource_iskmc"]
117+
script = ExtResource("3_dpt5n")
118+
block_class = &"StatementBlock"
119+
serialized_props = [["block_name", "statement_block"], ["label", "StatementBlock"], ["color", Color(0.290196, 0.52549, 0.835294, 1)], ["block_type", 1], ["position", Vector2(0, 0)], ["block_format", "Move with player 2 buttons, speed {speed: INT}"], ["statement", "velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*{speed}
120+
move_and_slide()"], ["param_input_strings", {
121+
"speed": "600"
122+
}]]
123+
124+
[sub_resource type="Resource" id="Resource_xmana"]
125+
script = ExtResource("2_pqvcj")
126+
serialized_block = SubResource("Resource_iskmc")
127+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_2hh05")]]
128+
129+
[sub_resource type="Resource" id="Resource_1yx4d"]
130+
script = ExtResource("3_dpt5n")
131+
block_class = &"EntryBlock"
132+
serialized_props = [["block_name", "physics_process_block"], ["label", "EntryBlock"], ["color", Color(0.980392, 0.34902, 0.337255, 1)], ["block_type", 1], ["position", Vector2(79, 270)], ["block_format", "On Physics Process"], ["statement", "func _physics_process(delta):"], ["param_input_strings", {}]]
133+
134+
[sub_resource type="Resource" id="Resource_eifs0"]
135+
script = ExtResource("2_pqvcj")
136+
serialized_block = SubResource("Resource_1yx4d")
137+
path_child_pairs = [[NodePath("VBoxContainer/SnapPoint"), SubResource("Resource_xmana")]]
138+
139+
[sub_resource type="Resource" id="Resource_2hn5u"]
84140
script = ExtResource("4_xt862")
85-
array = Array[ExtResource("2_pqvcj")]([SubResource("Resource_cel1g"), SubResource("Resource_pyh8n")])
141+
array = Array[ExtResource("2_pqvcj")]([SubResource("Resource_xdg8y"), SubResource("Resource_eifs0")])
86142

87143
[sub_resource type="Resource" id="Resource_l007i"]
88144
script = ExtResource("5_q37d3")
89145
script_inherits = "SimpleCharacter"
90-
block_trees = SubResource("Resource_j1v52")
146+
block_trees = SubResource("Resource_2hn5u")
91147
generated_script = "extends SimpleCharacter
92148
93149
var VAR_DICT := {}
94150
95-
func _physics_process(delta):
96-
velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*600
97-
move_and_slide()
98-
99151
func _ready():
100152
print('Hi Manuel!')
101153
add_to_group('Player')
102154
var signal_manager = get_tree().root.get_node_or_null(\"SignalManager\")
103155
if signal_manager:
104156
signal_manager.broadcast_signal('Player', 'will_hi')
157+
var sound = AudioStreamPlayer.new()
158+
sound.name = 'testsound'
159+
sound.set_stream(load('res://test_game/test_audio.ogg'))
160+
add_child(sound)
161+
sound.set_owner(self)
162+
163+
func _physics_process(delta):
164+
velocity = Input.get_vector(\"player_2_left\", \"player_2_right\", \"player_2_up\", \"player_2_down\")*600
165+
move_and_slide()
166+
if Input.is_action_pressed(\"ui_right\"):
167+
var sound = find_child('testsound')
168+
sound.volume_db = 0.0
169+
sound.pitch_scale = 1.0
170+
sound.play()
105171
106172
"
107173

0 commit comments

Comments
 (0)