blob: ac30acf8b3b8fa2867202f812f2ddcdc6b776f3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# Hurry Curry! - a game about cooking
# Copyright 2024 nokoe
# Copyright 2024 tpart
# Copyright 2024 metamuffin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
extends Node
@onready var click_sound = $UI/Click
@onready var hover_sound = $UI/Hover
var item_sounds: Dictionary = {}
var item_id: int = 0
func play_click():
click_sound.play()
func play_hover():
hover_sound.play()
func play_hover_maybe(element):
if element is Button:
if element.is_hovered():
return
play_hover()
func item_progress(item: Item, running: AudioStream, stopping: AudioStream, volume=0.) -> int:
item_id += 1
var running_player: AudioStreamPlayer3D = AudioStreamPlayer3D.new()
running_player.stream = running
running_player.name = "Running%d" % item_id
running_player.volume_db = volume
add_child(running_player)
var stopping_player: AudioStreamPlayer3D = AudioStreamPlayer3D.new()
stopping_player.stream = stopping
stopping_player.name = "Stopping%d" % item_id
stopping_player.volume_db = volume
running_player.play()
add_child(stopping_player)
item_sounds[item_id] = [item, running_player, stopping_player, false]
return item_id
func item_finished(id: int):
var running_player: AudioStreamPlayer3D = item_sounds[id][1]
var stopping_player: AudioStreamPlayer3D = item_sounds[id][2]
item_sounds[id][3] = true
running_player.stop()
stopping_player.play()
stopping_player.finished.connect(func():
free_sound(id)
)
func free_sound(id: int):
var running_player: AudioStreamPlayer3D = item_sounds[id][1]
var stopping_player: AudioStreamPlayer3D = item_sounds[id][2]
running_player.queue_free()
stopping_player.queue_free()
item_sounds.erase(id)
func _physics_process(_delta):
for k in item_sounds.keys():
if item_sounds[k][0] != null:
var position: Vector3 = item_sounds[k][0].position
item_sounds[k][1].position = position
item_sounds[k][2].position = position
elif not item_sounds[k][3]:
item_finished(k)
|