Moves stuff around, made a main menu and scene mgr

This commit is contained in:
Dan Baker 2025-07-03 14:08:39 +01:00
parent b2e3a3957b
commit 6c023a60a6
37 changed files with 888 additions and 214 deletions

View file

@ -0,0 +1,14 @@
[gd_scene load_steps=4 format=3 uid="uid://cn41yepyhvwsd"]
[ext_resource type="Script" uid="uid://bqtnrs6cjoyj6" path="res://Stages/SceneManager/scripts/scene_manager.gd" id="1_scgkw"]
[ext_resource type="PackedScene" uid="uid://bon4rtm4rv1rf" path="res://Stages/SceneManager/TransitionScene.tscn" id="2_fe7gw"]
[ext_resource type="PackedScene" uid="uid://dkucysn167kp6" path="res://Stages/MainMenu/MainMenu.tscn" id="3_obg8q"]
[node name="SceneManager" type="Node3D"]
script = ExtResource("1_scgkw")
[node name="CurrentScene" type="Node" parent="."]
[node name="MainMenu" parent="CurrentScene" instance=ExtResource("3_obg8q")]
[node name="TransitionScene" parent="." instance=ExtResource("2_fe7gw")]

View file

@ -0,0 +1,76 @@
[gd_scene load_steps=6 format=3 uid="uid://bon4rtm4rv1rf"]
[ext_resource type="Script" uid="uid://cem1lps8uxlya" path="res://Stages/SceneManager/scripts/transition_scene.gd" id="1_pt42a"]
[sub_resource type="Animation" id="Animation_skyqd"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(0, 0, 0, 1)]
}
[sub_resource type="Animation" id="Animation_ehfi2"]
resource_name = "fade_to_black"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
}
[sub_resource type="Animation" id="Animation_n8kpy"]
resource_name = "fade_to_normal"
length = 0.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_lyb8n"]
_data = {
&"RESET": SubResource("Animation_skyqd"),
&"fade_to_black": SubResource("Animation_ehfi2"),
&"fade_to_normal": SubResource("Animation_n8kpy")
}
[node name="TransitionScene" type="CanvasLayer"]
script = ExtResource("1_pt42a")
[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(0, 0, 0, 1)
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_lyb8n")
}
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]

View file

@ -0,0 +1,32 @@
extends Node3D
class_name SceneManager
const SCENES: Dictionary = {
"MAINMENU": "res://Stages/MainMenu/MainMenu.tscn",
"HIGHSCORES": "res://scenes/high_scores.tscn"
}
var loading_scene_res: Resource = null
func _ready() -> void:
## LOAD GAME DATA
#HighScoreMgr.load()
#HighScoreMgr.debug_output()
# HighScoreMgr.debug_save_high_score()
Log.pr("SceneManager is ready.")
SceneMgr.connect("change_scene", Callable(self, "_on_change_scene"))
$TransitionScene.connect("transitioned", Callable(self, "_on_transition_scene_transitioned"))
func _on_change_scene(scene_name: String) -> void:
Log.pr("Going to load a scene.", scene_name)
if SCENES.has(scene_name):
#GameState.reset()
loading_scene_res = load(SCENES[scene_name])
Log.pr("Loading scene: ", loading_scene_res)
$TransitionScene.transition()
else:
loading_scene_res = null
func _on_transition_scene_transitioned() -> void:
$CurrentScene.get_child(0).queue_free()
$CurrentScene.add_child(loading_scene_res.instantiate())

View file

@ -0,0 +1 @@
uid://bqtnrs6cjoyj6

View file

@ -0,0 +1,18 @@
extends CanvasLayer
signal transitioned
func _ready() -> void:
$AnimationPlayer.play("fade_to_normal")
func transition() -> void:
$AnimationPlayer.play("fade_to_black")
Log.pr("Fading to black")
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "fade_to_black":
Log.pr("Sending transitioned signal...")
emit_signal("transitioned")
$AnimationPlayer.play("fade_to_normal")
if anim_name == "fade_to_normal":
Log.pr("Faded to normal")

View file

@ -0,0 +1 @@
uid://cem1lps8uxlya