Added SoundManager

This commit is contained in:
2025-12-25 17:57:33 +03:00
parent 8fca19a4a8
commit 26c00847c1
17 changed files with 242 additions and 16 deletions
+1
View File
@@ -1,2 +1,3 @@
*.png filter=lfs diff=lfs merge=lfs -text lockable
*.aseprite filter=lfs diff=lfs merge=lfs -text lockable
*.wav filter=lfs diff=lfs merge=lfs -text lockable
+7 -5
View File
@@ -1,6 +1,11 @@
class_name CSaveManager
extends Node
@export var save_file_path := "user://save.bin"
@export var save_file_pass := "save_file_data"
const WEAPONS : Array[WeaponData] = [
preload("res://game/data/weapons/cannon_data.tres"),
preload("res://game/data/weapons/gatling_data.tres"),
@@ -13,9 +18,6 @@ const WEAPONS : Array[WeaponData] = [
preload("res://game/data/weapons/tesla_data.tres"),
]
const SAVE_FILE = "user://save.bin"
const SAVE_FILE_PASS = "save_file_data"
const CATEGORY_GAME = "game"
const GAME_SEED = "seed"
const GAME_AREA_INDEX = "current_area_index"
@@ -53,7 +55,7 @@ func save() -> void:
_set_game_values()
_set_player_values()
_save_file.save_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS)
_save_file.save_encrypted_pass(save_file_path, save_file_pass)
func new_game(game_seed: String) -> void:
@@ -68,7 +70,7 @@ func delete_game_data() -> void:
func _load() -> void:
if _save_file.load_encrypted_pass(SAVE_FILE, SAVE_FILE_PASS) == OK:
if _save_file.load_encrypted_pass(save_file_path, save_file_pass) == OK:
_process_save_file()
save()
+6
View File
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://q22qjob2m35j"]
[ext_resource type="Script" uid="uid://calwg6oh6lv0r" path="res://game/managers/save_manager.gd" id="1_c6jim"]
[node name="SaveManager" type="Node"]
script = ExtResource("1_c6jim")
+16 -9
View File
@@ -1,8 +1,10 @@
class_name CSettingsManager
extends Node
const CONFIG_FILE = "user://settings.cfg"
const BASE_SIZE = Vector2i(640, 360)
@export var config_file_path := "user://settings.cfg"
@export var window_base_size := Vector2i(640, 360)
const CATEGORY_VIDEO = "video"
const SETTING_FULLSCREEN = "fullscreen"
@@ -79,7 +81,7 @@ func _ready() -> void:
func _load_settings() -> void:
if _config.load(CONFIG_FILE) == OK:
if _config.load(config_file_path) == OK:
_fullscreen = _config.get_value(CATEGORY_VIDEO, SETTING_FULLSCREEN, _fullscreen)
_window_factor = _config.get_value(CATEGORY_VIDEO, SETTING_WINDOW_FACTOR, _window_factor)
@@ -103,7 +105,7 @@ func _save_settings() -> void:
_config.set_value(CATEGORY_AUDIO, SETTING_SFX_VOLUME, _sfx_volume)
_config.set_value(CATEGORY_AUDIO, SETTING_MUSIC_VOLUME, _music_volume)
_config.save(CONFIG_FILE)
_config.save(config_file_path)
func _apply_all_settings() -> void:
@@ -120,16 +122,21 @@ func _apply_video_settings() -> void:
func _apply_audio_settings() -> void:
AudioServer.set_bus_volume_linear(AudioServer.get_bus_index("Master"), _master_volume/100.0)
AudioServer.set_bus_volume_linear(AudioServer.get_bus_index("UI"), _ui_volume/100.0)
AudioServer.set_bus_volume_linear(AudioServer.get_bus_index("SFX"), _sfx_volume/100.0)
AudioServer.set_bus_volume_linear(AudioServer.get_bus_index("Music"), _music_volume/100.0)
var master_bus := AudioServer.get_bus_index(CSoundManager.MASTER_BUS)
var ui_bus := AudioServer.get_bus_index(CSoundManager.UI_BUS)
var sfx_bus := AudioServer.get_bus_index(CSoundManager.SFX_BUS)
var music_bus := AudioServer.get_bus_index(CSoundManager.MUSIC_BUS)
AudioServer.set_bus_volume_linear(master_bus, _master_volume/100.0)
AudioServer.set_bus_volume_linear(ui_bus, _ui_volume/100.0)
AudioServer.set_bus_volume_linear(sfx_bus, _sfx_volume/100.0)
AudioServer.set_bus_volume_linear(music_bus, _music_volume/100.0)
func _apply_window_scale() -> void:
if _fullscreen: return
var new_size := BASE_SIZE * _window_factor
var new_size := window_base_size * _window_factor
var current_position := DisplayServer.window_get_position()
var current_size := DisplayServer.window_get_size()
+6
View File
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bulv8b0rwxd2g"]
[ext_resource type="Script" uid="uid://d2k5y0xd4hl22" path="res://game/managers/settings_manager.gd" id="1_4nipk"]
[node name="SettingsManager" type="Node"]
script = ExtResource("1_4nipk")
+78
View File
@@ -0,0 +1,78 @@
class_name CSoundManager
extends Node
const MASTER_BUS = "Master"
const UI_BUS = "UI"
const SFX_BUS = "SFX"
const MUSIC_BUS = "Music"
enum UISound {
UI_ACCEPT,
UI_DECLINE,
UI_NEXT,
UI_PREVIOUS,
}
enum SFXSound {
}
enum Music {
}
@export_group("Number of players", "player_count")
@export_range(1, 10) var player_count_ui := 1
@export_range(1, 100) var player_count_sfx := 1
@export_group("UI Sounds", "ui")
@export var ui_accept : AudioStream
@export var ui_decline : AudioStream
@export var ui_next : AudioStream
@export var ui_previous : AudioStream
var ui_players : Array[AudioStreamPlayer] = []
var sfx_players : Array[AudioStreamPlayer2D] = []
var music_player : AudioStreamPlayer
func _ready() -> void:
_create_ui_players()
_create_sfx_players()
_create_music_player()
func play_ui_sound(sound: UISound) -> void:
pass
func play_sfx_sound(sound: SFXSound) -> void:
pass
func play_music(music: Music) -> void:
pass
func _create_ui_players() -> void:
for i in range(player_count_ui):
var player : AudioStreamPlayer = AudioStreamPlayer.new()
player.bus = UI_BUS
ui_players.append(player)
func _create_sfx_players() -> void:
for i in range(player_count_sfx):
var player : AudioStreamPlayer2D = AudioStreamPlayer2D.new()
player.bus = SFX_BUS
sfx_players.append(player)
func _create_music_player() -> void:
var player : AudioStreamPlayer = AudioStreamPlayer.new()
player.bus = MUSIC_BUS
music_player = player
+1
View File
@@ -0,0 +1 @@
uid://cx5qcukr66whc
+16
View File
@@ -0,0 +1,16 @@
[gd_scene load_steps=6 format=3 uid="uid://bc0np3ldfspq4"]
[ext_resource type="Script" uid="uid://cx5qcukr66whc" path="res://game/managers/sound_manager.gd" id="1_cg0sy"]
[ext_resource type="AudioStream" uid="uid://bqcqigmj23ub5" path="res://sound/ui/ui_accept.wav" id="2_agyxs"]
[ext_resource type="AudioStream" uid="uid://buo5vn18yd5w0" path="res://sound/ui/ui_decline.wav" id="3_0i6kl"]
[ext_resource type="AudioStream" uid="uid://bmlticluh8uqd" path="res://sound/ui/ui_next.wav" id="4_fpnh3"]
[ext_resource type="AudioStream" uid="uid://bm1qd04yh32i8" path="res://sound/ui/ui_previous.wav" id="5_22ptj"]
[node name="SoundManager" type="Node"]
script = ExtResource("1_cg0sy")
player_count_ui = 4
player_count_sfx = 50
ui_accept = ExtResource("2_agyxs")
ui_decline = ExtResource("3_0i6kl")
ui_next = ExtResource("4_fpnh3")
ui_previous = ExtResource("5_22ptj")
+3 -2
View File
@@ -19,8 +19,9 @@ config/icon="res://icon.svg"
[autoload]
SettingsManager="*res://game/managers/settings_manager.gd"
SaveManager="*res://game/managers/save_manager.gd"
SaveManager="*res://game/managers/save_manager.tscn"
SettingsManager="*res://game/managers/settings_manager.tscn"
SoundManager="*res://game/managers/sound_manager.tscn"
[debug]
BIN
View File
Binary file not shown.
+24
View File
@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bqcqigmj23ub5"
path="res://.godot/imported/ui_accept.wav-41ce5727fb12b862dc2882c8769ab277.sample"
[deps]
source_file="res://sound/ui/ui_accept.wav"
dest_files=["res://.godot/imported/ui_accept.wav-41ce5727fb12b862dc2882c8769ab277.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
BIN
View File
Binary file not shown.
+24
View File
@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://buo5vn18yd5w0"
path="res://.godot/imported/ui_decline.wav-8d576685c3790bf5abed2309b4344f90.sample"
[deps]
source_file="res://sound/ui/ui_decline.wav"
dest_files=["res://.godot/imported/ui_decline.wav-8d576685c3790bf5abed2309b4344f90.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
BIN
View File
Binary file not shown.
+24
View File
@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bmlticluh8uqd"
path="res://.godot/imported/ui_next.wav-5da888996e7e30726e36145562d16fb4.sample"
[deps]
source_file="res://sound/ui/ui_next.wav"
dest_files=["res://.godot/imported/ui_next.wav-5da888996e7e30726e36145562d16fb4.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
Binary file not shown.
+24
View File
@@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bm1qd04yh32i8"
path="res://.godot/imported/ui_previous.wav-40c48892c96302141d49784cf1321da4.sample"
[deps]
source_file="res://sound/ui/ui_previous.wav"
dest_files=["res://.godot/imported/ui_previous.wav-40c48892c96302141d49784cf1321da4.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2