first_anniversary_godot_jam/scripts/MusicSingleton.gd

67 lines
1.8 KiB
GDScript

extends Node
func _ready() -> void:
print("Loaded Music singleton")
var change_slow_actions : Array = []
var gameSpeed : float = 1;
var musicType: int = 0;
var audio_player_slow : AudioStreamPlayer3D
var audio_player_normal : AudioStreamPlayer3D
var audio_player_fast : AudioStreamPlayer3D
var current_audio_player : AudioStreamPlayer3D
func setSlowMusic():
setMusicType( -1 )
func setFastMusic():
setMusicType( 1 )
func setNormalMusic():
setMusicType( 0 )
func setMusicType( type:int ):
musicType = type;
if type == 0:
gameSpeed = 0
# current_playback_position : float = 0.0
# if current_audio_player:
# current_audio_player.stop()
# current_playback_position = current_audio_player.get_playback_position()
# current_playback_position = current_audio_player.get_playback_position()
# current_playback_position = current_audio_player.get_playback_position()
if type == 1:
gameSpeed = 2
if type == -1:
gameSpeed = 0.5
func register_change_action(change_action : Node) -> void:
print("Registered change action")
change_slow_actions.append(change_action)
func unregister_change_action(change_action : Node) -> void:
print("Unregistered change action")
change_slow_actions.erase(change_action)
func change_music() -> void:
for change_action in change_slow_actions:
change_action.execute()
func register_audio_player_slow(audio_player : AudioStreamPlayer3D) -> void:
print("Registered audio stream player fast")
audio_player_slow = audio_player
func register_audio_player_normal(audio_player : AudioStreamPlayer3D) -> void:
print("Registered audio stream player normal")
audio_player_normal = audio_player
func register_audio_player_fast(audio_player : AudioStreamPlayer3D) -> void:
print("Registered audio stream player fast")
audio_player_fast = audio_player