mirror of
https://github.com/kodzukye/scrap-signal.git
synced 2026-04-26 22:37:35 +00:00
- Add AudioManager autoload with music and sfx players - Add ambiance tracks for entrepot, atelier and cour zones - Add SFX for footstep, item_pickup, interact, door_unlock, repair_success, vrac_talking, iris_talking - Add crossfade transition between ambiance zones - Add loop via finished signal on music_player - Set ambiance volume to -12dB to balance with SFX - Set PROCESS_MODE_ALWAYS to prevent audio cut during dialogues - Add stop_ambiance() call on main_menu to reset music after credits
68 lines
2.1 KiB
GDScript
68 lines
2.1 KiB
GDScript
extends Node
|
|
|
|
var music_player : AudioStreamPlayer
|
|
var sfx_player : AudioStreamPlayer
|
|
|
|
const AMBIANCE_VOLUME_DB := -12.0
|
|
|
|
const AMBIANCES := {
|
|
"entrepot": preload("res://assets/audio/music/entrepot.ogg"),
|
|
"atelier": preload("res://assets/audio/music/atelier.ogg"),
|
|
"cour": preload("res://assets/audio/music/cour.ogg"),
|
|
}
|
|
|
|
const SFX := {
|
|
"footstep": preload("res://assets/audio/sfx/footsteps.ogg"),
|
|
"item_pickup": preload("res://assets/audio/sfx/item_pickup.ogg"),
|
|
"interact": preload("res://assets/audio/sfx/iteract.ogg"),
|
|
"door_unlock": preload("res://assets/audio/sfx/door_unlocking.ogg"),
|
|
"repair_success": preload("res://assets/audio/sfx/succesful_repair.ogg"),
|
|
"vrac_talking": preload("res://assets/audio/sfx/vrac_talking.ogg"),
|
|
"iris_talking": preload("res://assets/audio/sfx/iris_talking.ogg"),
|
|
}
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
music_player = AudioStreamPlayer.new()
|
|
music_player.name = "MusicPlayer"
|
|
music_player.bus = "Ambient"
|
|
music_player.volume_db = AMBIANCE_VOLUME_DB
|
|
add_child(music_player)
|
|
music_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
sfx_player = AudioStreamPlayer.new()
|
|
sfx_player.name = "SfxPlayer"
|
|
sfx_player.bus = "SFX"
|
|
add_child(sfx_player)
|
|
sfx_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
func _on_music_finished() -> void:
|
|
music_player.play()
|
|
|
|
func play_ambiance(zone: String) -> void:
|
|
if not AMBIANCES.has(zone):
|
|
return
|
|
if music_player.stream == AMBIANCES[zone] and music_player.playing:
|
|
return
|
|
|
|
var tween := create_tween()
|
|
tween.tween_property(music_player, "volume_db", -40.0, 0.8)
|
|
tween.tween_callback(func():
|
|
music_player.stream = AMBIANCES[zone]
|
|
music_player.play()
|
|
)
|
|
tween.tween_property(music_player, "volume_db", AMBIANCE_VOLUME_DB, 1.2)
|
|
|
|
func stop_ambiance() -> void:
|
|
var tween := create_tween()
|
|
tween.tween_property(music_player, "volume_db", -40.0, 1.0)
|
|
tween.tween_callback(music_player.stop)
|
|
|
|
func play_sfx(sfx_name: String) -> void:
|
|
if not SFX.has(sfx_name):
|
|
push_warning("SFX introuvable : " + sfx_name)
|
|
return
|
|
sfx_player.stream = SFX[sfx_name]
|
|
sfx_player.play()
|