From b5e6a4cde0dd7bc84b49f4b4a2f53e010f57d3a8 Mon Sep 17 00:00:00 2001 From: teatov Date: Tue, 8 Oct 2024 06:53:45 +1000 Subject: [PATCH] rename `AudioStreamPlayerPolyphonic` to `SoundEffectsPlayer` --- scenes/structures/Anthill.tscn | 4 ++-- scenes/units/abstract/unit.tscn | 4 ++-- scenes/units/components/gathering.tscn | 4 ++-- scripts/anthill.gd | 6 +++--- scripts/audio_stream_player_polyphonic.gd | 4 ++-- scripts/sound_effects_player.gd | 23 +++++++++++++++++++++++ scripts/units/components/gathering.gd | 12 ++++++------ scripts/units/unit.gd | 4 ++-- 8 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 scripts/sound_effects_player.gd diff --git a/scenes/structures/Anthill.tscn b/scenes/structures/Anthill.tscn index 71c69c2..db6c494 100644 --- a/scenes/structures/Anthill.tscn +++ b/scenes/structures/Anthill.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://scripts/anthill.gd" id="1_8k02d"] [ext_resource type="Material" uid="uid://f0nlf4tdpvbd" path="res://resources/materials/indicators/hover_indicator_mat.tres" id="2_44p2d"] -[ext_resource type="Script" path="res://scripts/audio_stream_player_polyphonic.gd" id="3_vp3nf"] +[ext_resource type="Script" path="res://scripts/sound_effects_player.gd" id="3_vp3nf"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_x8apu"] @@ -35,6 +35,6 @@ mesh = SubResource("QuadMesh_2gykr") [node name="NavigationObstacle3D" type="NavigationObstacle3D" parent="."] radius = 0.57 -[node name="AudioStreamPlayerPolyphonic" type="AudioStreamPlayer3D" parent="."] +[node name="SoundEffectsPlayer" type="AudioStreamPlayer3D" parent="."] unit_size = 20.0 script = ExtResource("3_vp3nf") diff --git a/scenes/units/abstract/unit.tscn b/scenes/units/abstract/unit.tscn index f3e8937..a54ee4f 100644 --- a/scenes/units/abstract/unit.tscn +++ b/scenes/units/abstract/unit.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://scripts/units/unit.gd" id="1_ulhs6"] [ext_resource type="Material" uid="uid://f0nlf4tdpvbd" path="res://resources/materials/indicators/hover_indicator_mat.tres" id="2_uk1jy"] -[ext_resource type="Script" path="res://scripts/audio_stream_player_polyphonic.gd" id="3_wl62h"] +[ext_resource type="Script" path="res://scripts/sound_effects_player.gd" id="3_wl62h"] [sub_resource type="QuadMesh" id="QuadMesh_igohi"] material = ExtResource("2_uk1jy") @@ -45,5 +45,5 @@ transform = Transform3D(0.438547, 0, 0, 0, 0.438547, 0, 0, 0, 0.438547, 0, 0.906 visible = false mesh = SubResource("BoxMesh_hvf81") -[node name="AudioStreamPlayerPolyphonic" type="AudioStreamPlayer3D" parent="."] +[node name="SoundEffectsPlayer" type="AudioStreamPlayer3D" parent="."] script = ExtResource("3_wl62h") diff --git a/scenes/units/components/gathering.tscn b/scenes/units/components/gathering.tscn index dd1b952..e199a71 100644 --- a/scenes/units/components/gathering.tscn +++ b/scenes/units/components/gathering.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://scripts/units/components/gathering.gd" id="1_ciwtf"] [ext_resource type="Material" uid="uid://jkh5iskawwry" path="res://resources/materials/indicators/gathering_radius_mat.tres" id="2_r26em"] -[ext_resource type="Script" path="res://scripts/audio_stream_player_polyphonic.gd" id="4_alybx"] +[ext_resource type="Script" path="res://scripts/sound_effects_player.gd" id="4_alybx"] [sub_resource type="QuadMesh" id="QuadMesh_ks8es"] material = ExtResource("2_r26em") @@ -22,5 +22,5 @@ cast_shadow = 0 mesh = SubResource("QuadMesh_ks8es") skeleton = NodePath("../..") -[node name="AudioStreamPlayerPolyphonic" type="AudioStreamPlayer3D" parent="."] +[node name="SoundEffectsPlayer" type="AudioStreamPlayer3D" parent="."] script = ExtResource("4_alybx") diff --git a/scripts/anthill.gd b/scripts/anthill.gd index 3722761..51ef24a 100644 --- a/scripts/anthill.gd +++ b/scripts/anthill.gd @@ -13,8 +13,8 @@ var ant_gatherer := preload("res://scenes/units/ant_gatherer.tscn") @onready var ui_origin: Node3D = $UiOrigin @onready var nitwits_holder: Node = $/root/World/Units/Nitwits @onready var gatherers_holder: Node = $/root/World/Units/Gatherers -@onready var audio_player: AudioStreamPlayerPolyphonic = ( - $AudioStreamPlayerPolyphonic +@onready var audio_player: SoundEffectsPlayer = ( + $SoundEffectsPlayer ) @@ -80,5 +80,5 @@ func _create_unit(unit_scene: PackedScene, cost: int) -> ControlledUnit: new_pos ) ) - audio_player.play_polyphonic(SoundManager.ding()) + audio_player.play_sound(SoundManager.ding()) return new_unit diff --git a/scripts/audio_stream_player_polyphonic.gd b/scripts/audio_stream_player_polyphonic.gd index 3a694f1..0673921 100644 --- a/scripts/audio_stream_player_polyphonic.gd +++ b/scripts/audio_stream_player_polyphonic.gd @@ -1,5 +1,5 @@ extends AudioStreamPlayer3D -class_name AudioStreamPlayerPolyphonic +class_name SoundEffectsPlayer var playback: AudioStreamPlaybackPolyphonic @@ -9,7 +9,7 @@ func _ready() -> void: play() playback = get_stream_playback() -func play_polyphonic( +func play_sound( new_stream: AudioStream, from_offset: float = 0, new_volume_db: float = 0, diff --git a/scripts/sound_effects_player.gd b/scripts/sound_effects_player.gd new file mode 100644 index 0000000..0673921 --- /dev/null +++ b/scripts/sound_effects_player.gd @@ -0,0 +1,23 @@ +extends AudioStreamPlayer3D +class_name SoundEffectsPlayer + +var playback: AudioStreamPlaybackPolyphonic + + +func _ready() -> void: + stream = AudioStreamPolyphonic.new() + play() + playback = get_stream_playback() + +func play_sound( + new_stream: AudioStream, + from_offset: float = 0, + new_volume_db: float = 0, + new_pitch_scale: float = 1.0, +) -> void: + playback.play_stream( + new_stream, + from_offset, + new_volume_db, + new_pitch_scale, + ) diff --git a/scripts/units/components/gathering.gd b/scripts/units/components/gathering.gd index 481438c..6d06fed 100644 --- a/scripts/units/components/gathering.gd +++ b/scripts/units/components/gathering.gd @@ -36,8 +36,8 @@ var showing_after_set: bool = false @onready var radius_indicator: VisualInstance3D = ( $NearbyItemsSearch/GatheringRadius ) -@onready var audio_player: AudioStreamPlayerPolyphonic = ( - $AudioStreamPlayerPolyphonic +@onready var audio_player: SoundEffectsPlayer = ( + $SoundEffectsPlayer ) @@ -160,11 +160,11 @@ func _pick_up() -> void: carrying_items.append(target) target.set_carried(true) - audio_player.play_polyphonic(SoundManager.swoosh()) + audio_player.play_sound(SoundManager.swoosh()) await target.start_moving( _get_nth_pile_pos(carrying_items.size() - 1) ).moved - audio_player.play_polyphonic(SoundManager.pop()) + audio_player.play_sound(SoundManager.pop()) await get_tree().create_timer(pickup_interval).timeout if carrying_items.size() >= max_carrying or nearest == null: @@ -186,9 +186,9 @@ func _deposit() -> void: return var item := carrying_items.pop_back() as Honeydew - audio_player.play_polyphonic(SoundManager.swoosh()) + audio_player.play_sound(SoundManager.swoosh()) await item.start_moving(anthill.global_position).moved - audio_player.play_polyphonic(SoundManager.tok()) + audio_player.play_sound(SoundManager.tok()) item.remove_from_spawner() _erase_honeydew(item) item.queue_free() diff --git a/scripts/units/unit.gd b/scripts/units/unit.gd index 1b41988..7928452 100644 --- a/scripts/units/unit.gd +++ b/scripts/units/unit.gd @@ -25,8 +25,8 @@ var advance_anim_delta_accum: float = 0 $VisibleOnScreenNotifier3D ) @onready var main_camera: MainCamera = $/root/World/MainCamera -@onready var audio_player: AudioStreamPlayerPolyphonic = ( - $AudioStreamPlayerPolyphonic +@onready var audio_player: SoundEffectsPlayer = ( + $SoundEffectsPlayer )