Ajout de la cinématique de début et refonte du système audio
Et toujours un peu de correction de bug par ci par là
This commit is contained in:
@@ -18,7 +18,7 @@ force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_mode=2
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=2
|
||||
|
||||
@@ -3,12 +3,15 @@ extends Node
|
||||
const MIN_VOLUME = -60.
|
||||
const MAX_VOLUME = 24.
|
||||
|
||||
const DEFAULT_FADE_TIME : float = 0.5
|
||||
|
||||
@onready var settings : SettingsData = GameInfo.settings_data
|
||||
|
||||
@export var default_fade_time = 0.5
|
||||
|
||||
@export var playing_music : AudioStreamPlayer = null
|
||||
@export var playing_ambiance : AudioStreamPlayer = null
|
||||
var music_action : AudioAction
|
||||
var ambiance_action : AudioAction
|
||||
var playing_music : AudioStreamPlayer = null
|
||||
var playing_ambiance : AudioStreamPlayer = null
|
||||
|
||||
var default_volumes := {}
|
||||
|
||||
@@ -23,23 +26,93 @@ func _ready():
|
||||
)
|
||||
SceneManager.scene_loaded.connect(_on_change_scene)
|
||||
Dialogic.timeline_started.connect(_on_timeline_started)
|
||||
Dialogic.timeline_ended.connect(_on_timeline_ended)
|
||||
|
||||
func _process(_d):
|
||||
if music_action:
|
||||
playing_music = process_audio_action(
|
||||
music_action,
|
||||
%Musics,
|
||||
playing_music
|
||||
)
|
||||
music_action = null
|
||||
|
||||
if ambiance_action:
|
||||
playing_ambiance = process_audio_action(
|
||||
ambiance_action,
|
||||
%Ambiance,
|
||||
playing_ambiance
|
||||
)
|
||||
ambiance_action = null
|
||||
|
||||
func process_audio_action(
|
||||
audio_action : AudioAction,
|
||||
player_search_node: Node,
|
||||
current_player: AudioStreamPlayer = null
|
||||
) -> AudioStreamPlayer:
|
||||
if audio_action is AudioLaunch:
|
||||
return process_audio_launch(audio_action, player_search_node, current_player)
|
||||
elif audio_action is AudioStop and current_player and current_player.playing:
|
||||
stop_player(current_player)
|
||||
|
||||
return null
|
||||
|
||||
func process_audio_launch(
|
||||
audio_launch : AudioLaunch,
|
||||
player_search_node: Node,
|
||||
current_player: AudioStreamPlayer = null,
|
||||
) -> AudioStreamPlayer:
|
||||
var player = player_search_node.find_child(audio_launch.player_name)
|
||||
if not player:
|
||||
printerr("Player %s not found in category %s" % [audio_launch.player_name, player_search_node.name])
|
||||
return null
|
||||
if current_player and current_player.playing and current_player.name == audio_launch.player_name:
|
||||
return current_player
|
||||
elif current_player:
|
||||
stop_player(current_player)
|
||||
|
||||
start_player(player, audio_launch.from_random_time, audio_launch.fade_time)
|
||||
return player
|
||||
|
||||
func _on_change_scene(scene : Scene):
|
||||
play_ambiance()
|
||||
stop_ambiance()
|
||||
|
||||
match scene.scene_id:
|
||||
"TITLE":
|
||||
play_music("Title")
|
||||
play_music("Title", false, 0.0)
|
||||
"REGION":
|
||||
play_music("Region")
|
||||
play_ambiance("Exterior")
|
||||
play_music("Region", true)
|
||||
play_ambiance("Exterior", true)
|
||||
"COCKPIT":
|
||||
play_music("Truck")
|
||||
play_music("Truck", true)
|
||||
|
||||
func _on_timeline_started():
|
||||
var timeline_name = Dialogic.current_timeline.resource_path.split("/")[-1].trim_suffix(".dtl")
|
||||
# Timeline name et le nom du fichier de timeline, par exemple demeter_intro
|
||||
# Amuse toi Niels ;)
|
||||
# Amuse toi Nilou ;)
|
||||
|
||||
func _on_timeline_ended():
|
||||
_on_change_scene(SceneManager.actual_scene)
|
||||
|
||||
func play_music(player_name : String = "", from_random_time := false, fade_time := DEFAULT_FADE_TIME):
|
||||
music_action = AudioLaunch.new(
|
||||
player_name,
|
||||
from_random_time,
|
||||
fade_time
|
||||
)
|
||||
|
||||
func stop_music():
|
||||
music_action = AudioStop.new()
|
||||
|
||||
func play_ambiance(player_name : String = "", from_random_time := false, fade_time := DEFAULT_FADE_TIME):
|
||||
ambiance_action = AudioLaunch.new(
|
||||
player_name,
|
||||
from_random_time,
|
||||
fade_time
|
||||
)
|
||||
|
||||
func stop_ambiance():
|
||||
ambiance_action = AudioStop.new()
|
||||
|
||||
func fetch_default_volumes():
|
||||
var all_players := get_all_players()
|
||||
@@ -79,13 +152,30 @@ func get_players_from_node(node : Node) -> Array[AudioStreamPlayer]:
|
||||
streams.append(c)
|
||||
return streams
|
||||
|
||||
func set_volume(player : AudioStreamPlayer, to : float, fade_time = default_fade_time) -> Tween:
|
||||
func set_volume(player : AudioStreamPlayer, to : float, fade_time := 0.0) -> Tween:
|
||||
var fade_tween : Tween = get_tree().create_tween()
|
||||
|
||||
fade_tween.tween_property(player, "volume_db", to, fade_time)
|
||||
|
||||
return fade_tween
|
||||
|
||||
func start_player(player: AudioStreamPlayer, from_random_time = false, fade_time = DEFAULT_FADE_TIME):
|
||||
if player and not player.playing:
|
||||
player.play(
|
||||
0.0 if not from_random_time
|
||||
else randf_range(0.0, player.stream.get_length())
|
||||
)
|
||||
if fade_time > 0.0:
|
||||
player.volume_db = MIN_VOLUME
|
||||
await set_volume(player, get_volume_from_parent(player), fade_time).finished
|
||||
|
||||
func stop_player(player : AudioStreamPlayer, fade_time = DEFAULT_FADE_TIME):
|
||||
if player and player.playing:
|
||||
if fade_time > 0.0:
|
||||
await set_volume(player, MIN_VOLUME, fade_time).finished
|
||||
player.stop()
|
||||
player.volume_db = get_volume_from_parent(player)
|
||||
|
||||
func reset_volume(player : AudioStreamPlayer):
|
||||
player.volume_db = get_volume_from_parent(player)
|
||||
|
||||
@@ -96,36 +186,23 @@ func play_sfx(sfx_name : String):
|
||||
else:
|
||||
printerr("Sfx %s not found" % sfx_name)
|
||||
|
||||
func play_music(music_name : String = ""):
|
||||
var old_music = playing_music
|
||||
playing_music = null
|
||||
if old_music:
|
||||
await set_volume(old_music, MIN_VOLUME).finished
|
||||
if old_music and old_music != playing_music:
|
||||
old_music.stop()
|
||||
reset_volume(old_music)
|
||||
if music_name:
|
||||
var player := %Musics.find_child(music_name) as AudioStreamPlayer
|
||||
if player:
|
||||
playing_music = player
|
||||
player.play()
|
||||
set_volume(player, get_volume_from_parent(player))
|
||||
else:
|
||||
printerr("Music %s not found" % music_name)
|
||||
class AudioAction:
|
||||
pass
|
||||
|
||||
func play_ambiance(ambiance_name : String = ""):
|
||||
var old_ambiance = playing_ambiance
|
||||
playing_ambiance = null
|
||||
if old_ambiance:
|
||||
await set_volume(old_ambiance, MIN_VOLUME).finished
|
||||
if old_ambiance and old_ambiance != playing_ambiance:
|
||||
old_ambiance.stop()
|
||||
reset_volume(old_ambiance)
|
||||
if ambiance_name:
|
||||
var player := %Ambiance.find_child(ambiance_name) as AudioStreamPlayer
|
||||
if player:
|
||||
playing_ambiance = player
|
||||
player.play()
|
||||
set_volume(player, get_volume_from_parent(player))
|
||||
else:
|
||||
printerr("Ambiance %s not found" % ambiance_name)
|
||||
class AudioLaunch extends AudioAction:
|
||||
var player_name : String
|
||||
var from_random_time : bool
|
||||
var fade_time : float
|
||||
|
||||
func _init(
|
||||
_player_name : String,
|
||||
_from_random_time := false,
|
||||
_fade_time := DEFAULT_FADE_TIME,
|
||||
):
|
||||
player_name = _player_name
|
||||
from_random_time = _from_random_time
|
||||
fade_time = _fade_time
|
||||
|
||||
|
||||
class AudioStop extends AudioAction:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user