aboutsummaryrefslogtreecommitdiff
path: root/client/audio/play_random.gd
blob: 1efced30354f6a799a64b6bd62bdfc79754d132b (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
# Undercooked - a game about cooking
# Copyright 2024 tpart
#
# 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
class_name PlayRandom

@onready var sounds = get_children()

var autoplay := false

func _ready():
	for s in sounds:
		s.connect("finished", sound_finished)

func play_random():
	var s = sounds[randi_range(0, sounds.size() - 1)]
	s.pitch_scale = randf_range(0.9, 1.1)
	s.play()

func start_autoplay():
	autoplay = true
	play_random()

func stop_autoplay():
	autoplay = false

func sound_finished():
	if autoplay:
		play_random()