first_anniversary_godot_jam/scripts/MusicSingleton.gd

92 lines
2.4 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 ):
print("Set Music type")
musicType = type;
if type == 0:
gameSpeed = 0
var current_playback_position : float = 0.0
print("Set Music type normal")
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_normal
current_audio_player.play(current_playback_position)
if type == 1:
gameSpeed = 2
var current_playback_position : float = 0.0
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_fast
current_audio_player.play(current_playback_position)
if type == -1:
print("Set Music type slow")
gameSpeed = 0.5
var current_playback_position : float = 0.0
if current_audio_player:
current_playback_position = current_audio_player.get_playback_position()
current_audio_player.stop()
current_audio_player = audio_player_slow
current_audio_player.play(current_playback_position)
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