Added bg_sound manager and according ESC command.
Started transitions scene.
This commit is contained in:
42
addons/escoria-core/game/scenes/sound/bg_music.gd
Normal file
42
addons/escoria-core/game/scenes/sound/bg_music.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends Control
|
||||
class_name ESCBackgroundMusic
|
||||
|
||||
func get_class():
|
||||
return "ESCBackgroundMusic"
|
||||
|
||||
onready var stream = $AudioStreamPlayer
|
||||
var state = "default"
|
||||
export var global_id = "bg_music"
|
||||
|
||||
|
||||
func game_cleared():
|
||||
set_state("off", true)
|
||||
self.disconnect("tree_exited", escoria.esc_runner, "object_exit_scene")
|
||||
escoria.register_object(self)
|
||||
|
||||
|
||||
func set_state(p_state, p_force = false):
|
||||
# If already playing this stream, keep playing, unless p_force
|
||||
if p_state == state and not p_force and stream.is_playing():
|
||||
return
|
||||
|
||||
state = p_state
|
||||
|
||||
# If state is "off"/"default", turn off music
|
||||
if state == "off" or state == "default":
|
||||
stream.stream = null
|
||||
return
|
||||
|
||||
var resource = load(p_state)
|
||||
|
||||
stream.stream = resource
|
||||
|
||||
if stream.stream:
|
||||
resource.set_loop(true)
|
||||
if ProjectSettings.has_setting("escoria/sound/music_volume"):
|
||||
stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume")
|
||||
stream.play()
|
||||
|
||||
func _ready():
|
||||
escoria.register_object(self)
|
||||
|
||||
16
addons/escoria-core/game/scenes/sound/bg_music.tscn
Normal file
16
addons/escoria-core/game/scenes/sound/bg_music.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_music.gd" type="Script" id=1]
|
||||
|
||||
[node name="bg_music" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = -1680.0
|
||||
margin_bottom = -1050.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
41
addons/escoria-core/game/scenes/sound/bg_sound.gd
Normal file
41
addons/escoria-core/game/scenes/sound/bg_sound.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Control
|
||||
class_name ESCBackgroundSound
|
||||
|
||||
func get_class():
|
||||
return "ESCBackgroundSound"
|
||||
|
||||
onready var stream = $AudioStreamPlayer
|
||||
var state = "default"
|
||||
export var global_id = "bg_sound"
|
||||
|
||||
|
||||
func game_cleared():
|
||||
stream.stream = null
|
||||
escoria.register_object(self)
|
||||
|
||||
|
||||
func set_state(p_state, p_force = false):
|
||||
# If already playing this stream, keep playing, unless p_force
|
||||
if p_state == state and not p_force and stream.is_playing():
|
||||
return
|
||||
|
||||
state = p_state
|
||||
|
||||
# If state is "off"/"default", turn off music
|
||||
if state == "off" or state == "default":
|
||||
stream.stream = null
|
||||
return
|
||||
|
||||
var resource = load(p_state)
|
||||
|
||||
stream.stream = resource
|
||||
|
||||
if stream.stream:
|
||||
resource.set_loop(false)
|
||||
if ProjectSettings.has_setting("escoria/sound/sound_volume"):
|
||||
stream.volume_db = ProjectSettings.get_setting("escoria/sound/sound_volume")
|
||||
stream.play()
|
||||
|
||||
|
||||
func _ready():
|
||||
escoria.register_object(self)
|
||||
16
addons/escoria-core/game/scenes/sound/bg_sound.tscn
Normal file
16
addons/escoria-core/game/scenes/sound/bg_sound.tscn
Normal file
@@ -0,0 +1,16 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_sound.gd" type="Script" id=1]
|
||||
|
||||
[node name="bg_sound" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = -1680.0
|
||||
margin_bottom = -1050.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
Reference in New Issue
Block a user