Skip to content

Commit 3acee8b

Browse files
committed
Add sound blocks
Add blocks: * Load the audio file as the sound * Play the sound with dB and pitch https://phabricator.endlessm.com/T35501
1 parent 80b227a commit 3acee8b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
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

0 commit comments

Comments
 (0)