Add sound effects, ambient music and volume mixing (0.5.0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-11 22:57:37 +02:00
parent dbf513e686
commit 2d7001105d
40 changed files with 665 additions and 26 deletions
+20
View File
@@ -0,0 +1,20 @@
class_name AudioBuses
extends RefCounted
## Bus audio du jeu, crees a l'execution (pas de fichier de disposition a
## maintenir) : « Music » et « Effects » sont des enfants du bus principal,
## dont le volume est le volume general. Les voix des dictees restent sur le
## bus principal : elles ne sont jamais couvertes par la musique.
const MUSIC := "Music"
const EFFECTS := "Effects"
## Cree les bus manquants. Idempotent.
static func ensure() -> void:
for bus_name in [MUSIC, EFFECTS]:
if AudioServer.get_bus_index(bus_name) != -1:
continue
AudioServer.add_bus()
var index := AudioServer.bus_count - 1
AudioServer.set_bus_name(index, bus_name)
AudioServer.set_bus_send(index, "Master")
+1
View File
@@ -0,0 +1 @@
uid://04s3ocs22q7g
+27
View File
@@ -0,0 +1,27 @@
class_name SoundCatalog
extends RefCounted
## Identifiants des effets sonores et des musiques, resolus vers un fichier
## d'un repertoire fixe (jamais de chemin libre : voir CLAUDE.md). Code pur.
const SFX_DIR := "res://assets/audio/sfx"
const MUSIC_DIR := "res://assets/audio/music"
const SFX_IDS: Array[String] = ["click", "success", "try_again", "star", "fanfare"]
const MUSIC_IDS: Array[String] = ["forest", "marsh"]
static func sfx_path(sfx_id: String) -> String:
if not SFX_IDS.has(sfx_id):
return ""
return "%s/%s.ogg" % [SFX_DIR, sfx_id]
static func music_path(music_id: String) -> String:
if not MUSIC_IDS.has(music_id):
return ""
return "%s/%s.ogg" % [MUSIC_DIR, music_id]
## Musique d'une region selon le niveau scolaire de la regle.
static func music_for_level(level: String) -> String:
return "marsh" if level == "CE2" else "forest"
+1
View File
@@ -0,0 +1 @@
uid://dvg367cd47sam
+6
View File
@@ -20,6 +20,8 @@ static func defaults() -> Dictionary:
return {
"format_version": FORMAT_VERSION,
"volume": 0.8,
"music_volume": 0.5,
"effects_volume": 0.8,
"text_scale_index": 0,
"animations_enabled": true,
}
@@ -35,6 +37,10 @@ static func sanitize(raw: Variant) -> Dictionary:
var volume: Variant = source.get("volume")
if typeof(volume) == TYPE_FLOAT or typeof(volume) == TYPE_INT:
result["volume"] = clampf(float(volume), 0.0, 1.0)
for key: String in ["music_volume", "effects_volume"]:
var other: Variant = source.get(key)
if typeof(other) == TYPE_FLOAT or typeof(other) == TYPE_INT:
result[key] = clampf(float(other), 0.0, 1.0)
var index: Variant = source.get("text_scale_index")
if typeof(index) == TYPE_FLOAT or typeof(index) == TYPE_INT:
result["text_scale_index"] = clampi(int(index), 0, TEXT_SCALES.size() - 1)