From 51cd4d8a2d69c795298b1ebc949eae3dd5739340 Mon Sep 17 00:00:00 2001 From: Jian-Hong Pan Date: Fri, 14 Jun 2024 18:23:29 +0800 Subject: [PATCH] Add simple sound node https://phabricator.endlessm.com/T35501 --- .../simple_nodes/simple_sound/simple_sound.gd | 23 +++++++++++++++++++ .../simple_sound/simple_sound.tscn | 6 +++++ 2 files changed, 29 insertions(+) create mode 100644 addons/block_code/simple_nodes/simple_sound/simple_sound.gd create mode 100644 addons/block_code/simple_nodes/simple_sound/simple_sound.tscn diff --git a/addons/block_code/simple_nodes/simple_sound/simple_sound.gd b/addons/block_code/simple_nodes/simple_sound/simple_sound.gd new file mode 100644 index 00000000..f2532603 --- /dev/null +++ b/addons/block_code/simple_nodes/simple_sound/simple_sound.gd @@ -0,0 +1,23 @@ +@tool +class_name SimpleSound +extends AudioStreamPlayer + + +func get_class(): + return "SimpleSound" + + +static func get_custom_blocks() -> Array[BlockCategory]: + var b: Block + + # Play the sound + var sound_list: Array[Block] = [] + b = CategoryFactory.BLOCKS["statement_block"].instantiate() + b.block_type = Types.BlockType.EXECUTE + b.block_format = "Play the sound with Volume dB {db: FLOAT} and Pitch Scale {pitch: FLOAT}" + b.statement = "volume_db={db}\npitch_scale={pitch}\n" + "play()" + sound_list.append(b) + + var sound_cat: BlockCategory = BlockCategory.new("PlaySound", sound_list, Color("e30fc0")) + + return [sound_cat] diff --git a/addons/block_code/simple_nodes/simple_sound/simple_sound.tscn b/addons/block_code/simple_nodes/simple_sound/simple_sound.tscn new file mode 100644 index 00000000..51c26e26 --- /dev/null +++ b/addons/block_code/simple_nodes/simple_sound/simple_sound.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://dnea31ja51r43"] + +[ext_resource type="Script" path="res://addons/block_code/simple_nodes/simple_sound/simple_sound.gd" id="1_7dbg7"] + +[node name="SimpleSound" type="AudioStreamPlayer"] +script = ExtResource("1_7dbg7")