Add MusicSingleton and OnMusicChangedSlowTrigger

This commit is contained in:
Matteo Tietz 2024-04-20 15:17:53 +02:00
parent 5dceb81be3
commit 79a5b87a1c
4 changed files with 48 additions and 1 deletions

View File

@ -1,5 +1,6 @@
[gd_scene load_steps=34 format=2] [gd_scene load_steps=35 format=2]
[ext_resource path="res://scripts/OnMusicChangedSlowTrigger.gd" type="Script" id=1]
[ext_resource path="res://3d_platforma/golden_bay_512.hdr" type="Texture" id=2] [ext_resource path="res://3d_platforma/golden_bay_512.hdr" type="Texture" id=2]
[ext_resource path="res://3d_platforma/sqare_norm.png" type="Texture" id=4] [ext_resource path="res://3d_platforma/sqare_norm.png" type="Texture" id=4]
[ext_resource path="res://3d_platforma/texture_08.png" type="Texture" id=5] [ext_resource path="res://3d_platforma/texture_08.png" type="Texture" id=5]
@ -563,3 +564,6 @@ light_energy = 0.65
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 24 ) environment = SubResource( 24 )
[node name="MusicChangedSlowAction" type="Node" parent="."]
script = ExtResource( 1 )

View File

@ -8,12 +8,26 @@
config_version=4 config_version=4
_global_script_classes=[ {
"base": "Node",
"class": "MusicChangedSlowAction",
"language": "GDScript",
"path": "res://scripts/OnMusicChangedSlowTrigger.gd"
} ]
_global_script_class_icons={
"MusicChangedSlowAction": ""
}
[application] [application]
config/name="first_anniversary_godot_jam" config/name="first_anniversary_godot_jam"
run/main_scene="res://3d_platforma/Level.tscn" run/main_scene="res://3d_platforma/Level.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload]
MusicSingleton="*res://scripts/MusicSingleton.gd"
[display] [display]
window/size/width=480 window/size/width=480

18
scripts/MusicSingleton.gd Normal file
View File

@ -0,0 +1,18 @@
extends Node
func _ready() -> void:
print("Loaded Music singleton")
var change_slow_actions : Array = []
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()

View File

@ -0,0 +1,11 @@
class_name MusicChangedSlowAction extends Node
func _ready():
MusicSingleton.register_change_action(self)
MusicSingleton.change_music()
func _exit_tree():
MusicSingleton.unregister_change_action(self)
func execute() -> void:
print("Executed OnMusicChangedSlowAction")