From 79a5b87a1c2919d0f3338d1c1beae14f831dfef6 Mon Sep 17 00:00:00 2001 From: Matteo Tietz Date: Sat, 20 Apr 2024 15:17:53 +0200 Subject: [PATCH] Add MusicSingleton and OnMusicChangedSlowTrigger --- 3d_platforma/Level.tscn | 6 +++++- project.godot | 14 ++++++++++++++ scripts/MusicSingleton.gd | 18 ++++++++++++++++++ scripts/OnMusicChangedSlowTrigger.gd | 11 +++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/MusicSingleton.gd create mode 100644 scripts/OnMusicChangedSlowTrigger.gd diff --git a/3d_platforma/Level.tscn b/3d_platforma/Level.tscn index 746665b..e708858 100644 --- a/3d_platforma/Level.tscn +++ b/3d_platforma/Level.tscn @@ -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/sqare_norm.png" type="Texture" id=4] [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="."] environment = SubResource( 24 ) + +[node name="MusicChangedSlowAction" type="Node" parent="."] +script = ExtResource( 1 ) diff --git a/project.godot b/project.godot index 1c96070..12072ed 100644 --- a/project.godot +++ b/project.godot @@ -8,12 +8,26 @@ config_version=4 +_global_script_classes=[ { +"base": "Node", +"class": "MusicChangedSlowAction", +"language": "GDScript", +"path": "res://scripts/OnMusicChangedSlowTrigger.gd" +} ] +_global_script_class_icons={ +"MusicChangedSlowAction": "" +} + [application] config/name="first_anniversary_godot_jam" run/main_scene="res://3d_platforma/Level.tscn" config/icon="res://icon.png" +[autoload] + +MusicSingleton="*res://scripts/MusicSingleton.gd" + [display] window/size/width=480 diff --git a/scripts/MusicSingleton.gd b/scripts/MusicSingleton.gd new file mode 100644 index 0000000..1afdb3f --- /dev/null +++ b/scripts/MusicSingleton.gd @@ -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() diff --git a/scripts/OnMusicChangedSlowTrigger.gd b/scripts/OnMusicChangedSlowTrigger.gd new file mode 100644 index 0000000..1d57758 --- /dev/null +++ b/scripts/OnMusicChangedSlowTrigger.gd @@ -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")