61 lines
1.6 KiB
GDScript
61 lines
1.6 KiB
GDScript
tool
|
|
extends Node
|
|
|
|
enum themes{
|
|
NONE,
|
|
BASE,
|
|
THEME_1,
|
|
THEME_2,
|
|
THEME_3,
|
|
}
|
|
|
|
export (themes) var current_theme: int = themes.BASE setget set_theme
|
|
var last_theme: int = -1
|
|
export (bool) var autoplay:bool = true;
|
|
export (bool) var playing:bool = false setget set_playing
|
|
export (float) var transition_time:float = 5
|
|
var transition_state:float = 1
|
|
var max_volume = 0.5
|
|
|
|
func _ready():
|
|
for i in range(themes.size()):
|
|
if i > 0:
|
|
AudioServer.set_bus_volume_db(i, linear2db(0))
|
|
AudioServer.set_bus_mute(i, true)
|
|
if not current_theme == 0:
|
|
AudioServer.set_bus_volume_db(current_theme, linear2db(max_volume))
|
|
AudioServer.set_bus_mute(current_theme, false)
|
|
if autoplay and not playing:
|
|
set_playing(true)
|
|
|
|
func _process(delta):
|
|
if last_theme != -1:
|
|
transition_state += delta/transition_time
|
|
if transition_state > 1:
|
|
transition_state = 1
|
|
if not last_theme == 0: AudioServer.set_bus_mute(last_theme, true)
|
|
last_theme = -1
|
|
if not current_theme == 0: AudioServer.set_bus_volume_db(current_theme, linear2db(transition_state*max_volume))
|
|
if not last_theme == 0: AudioServer.set_bus_volume_db(last_theme, linear2db((1-transition_state)*max_volume))
|
|
|
|
|
|
func set_theme(new_theme):
|
|
if last_theme == -1:
|
|
last_theme = current_theme
|
|
current_theme = new_theme
|
|
AudioServer.set_bus_mute(new_theme, false)
|
|
transition_state = 0
|
|
|
|
func set_playing(play_input):
|
|
if is_inside_tree():
|
|
$Base.playing = play_input
|
|
$Theme1.playing = play_input
|
|
$Theme2.playing = play_input
|
|
$Theme3.playing = play_input
|
|
playing = play_input
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|