-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_options.gd
56 lines (47 loc) · 1.78 KB
/
global_options.gd
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
extends Node
@export var music_volume: float = 0.5
@export var sound_volume: float = 0.5
@export var music_muted: bool = false
@export var sound_muted: bool = false
@export var highscore: int
var current_dir = OS.get_executable_path().get_base_dir()
var savefile = current_dir + "/savedata.save"
signal celebrate
# Store the original dB values to adjust relatively
var original_music_dbs: Dictionary = {}
var original_sound_dbs: Dictionary = {}
func apply_volume_settings():
# Adjust all music nodes, based on their original volume_db settings
for node in get_tree().get_nodes_in_group("Music"):
if not original_music_dbs.has(node):
# Store the original db value for each node
original_music_dbs[node] = node.volume_db
if music_volume <= 0.0 or music_muted:
node.volume_db = -80 # Mute
else:
# Adjust relative to the original db value
node.volume_db = original_music_dbs[node] + 10 * log(music_volume)
# Adjust all sound nodes, based on their original volume_db settings
for node in get_tree().get_nodes_in_group("Sounds"):
if not original_sound_dbs.has(node):
# Store the original db value for each node
original_sound_dbs[node] = node.volume_db
if sound_volume <= 0.0 or sound_muted:
node.volume_db = -80 # Mute
else:
# Adjust relative to the original db value
node.volume_db = original_sound_dbs[node] + 10 * log(sound_volume)
# Save highscore logic
func save_highscore(highscore):
var file = FileAccess.open(savefile, FileAccess.WRITE_READ)
file.store_32(highscore)
# Load highscore logic
func load_highscore():
var file = FileAccess.open(savefile, FileAccess.READ)
if FileAccess.file_exists(savefile):
highscore = file.get_32()
else:
push_error("File system error!")
func trigger_celebration() -> void:
emit_signal("celebrate")
print("Party!")