Refactoring

This commit is contained in:
2026-01-07 22:09:56 -06:00
parent fff088a0a7
commit b7716201d8
62 changed files with 110 additions and 78 deletions

7
scene/InitialScene.tscn Normal file
View File

@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://bs41nqi3ocih3"]
[ext_resource type="PackedScene" uid="uid://d2u7xxqmy8mws" path="res://ui/mainmenu/MainMenu.tscn" id="1_hu3pf"]
[node name="InitialScene" type="Node3D"]
[node name="MainMenu" parent="." instance=ExtResource("1_hu3pf")]

34
scene/OverworldScene.gd Normal file
View File

@@ -0,0 +1,34 @@
class_name OverworldScene extends Node
@export var map:Node3D = null
func _enter_tree() -> void:
OVERWORLD.mapChanged.connect(onMapChanged)
func _ready() -> void:
pass
func _exit_tree() -> void:
OVERWORLD.mapChanged.disconnect(onMapChanged)
func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
print("New map time.", newMap)
for childScene in map.get_children():
map.remove_child(childScene)
if !newMap:
return
var newMapInstance = newMap.instantiate()
map.add_child(newMapInstance)
# Find Player.
# if playerDestinationNodeName:
# var player = newMapInstance.get_node("Player")
# var destNode = newMapInstance.get_node(playerDestinationNodeName)
# if player && player is Player && destNode:
# player.global_position = destNode.global_position
# player.global_rotation.y = destNode.global_rotation.y
# elif playerDestinationNodeName:
# push_error("Player, or destination node not found in new map.")
# pass

View File

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

View File

@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://c0k1t3tyiaojl"]
[ext_resource type="Script" uid="uid://dpvccegdmn7s6" path="res://scene/OverworldScene.gd" id="1_fa54r"]
[node name="OverworldScene" type="Node3D" node_paths=PackedStringArray("map")]
script = ExtResource("1_fa54r")
map = NodePath("Map")
[node name="Map" type="Node3D" parent="."]

34
scene/RootScene.gd Normal file
View File

@@ -0,0 +1,34 @@
class_name RootScene extends Node3D
@export var overworld:Node3D = null
@export var initial:Node3D = null
func _enter_tree() -> void:
SCENE.sceneChanged.connect(onSceneChange)
SCENE.setScene(SceneSingleton.SceneType.INITIAL)
func _exit_tree() -> void:
push_error("RootScene should not be removed from the scene tree. This is a bug.")
func onSceneChange(newScene:SceneSingleton.SceneType) -> void:
print("overworld", overworld)
remove_child(overworld)
remove_child(initial)
overworld.visible = false
initial.visible = false
match newScene:
SceneSingleton.SceneType.INITIAL:
add_child(initial)
initial.visible = true
SceneSingleton.SceneType.OVERWORLD:
add_child(overworld)
overworld.visible = true
SceneSingleton.SceneType.UNSET:
pass
_:
pass

1
scene/RootScene.gd.uid Normal file
View File

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

15
scene/RootScene.tscn Normal file
View File

@@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=3 uid="uid://ckkewlcugc8ro"]
[ext_resource type="Script" uid="uid://ml70iui7qpo4" path="res://scene/RootScene.gd" id="1_nky1x"]
[ext_resource type="PackedScene" uid="uid://bs41nqi3ocih3" path="res://scene/InitialScene.tscn" id="2_hkmoa"]
[ext_resource type="PackedScene" uid="uid://c0k1t3tyiaojl" path="res://scene/OverworldScene.tscn" id="2_o1wvd"]
[node name="RootScene" type="Node3D" node_paths=PackedStringArray("overworld", "initial")]
script = ExtResource("1_nky1x")
overworld = NodePath("OverworldScene")
initial = NodePath("InitialScene")
metadata/_custom_type_script = "uid://ml70iui7qpo4"
[node name="OverworldScene" parent="." instance=ExtResource("2_o1wvd")]
[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")]

19
scene/Scene.gd Normal file
View File

@@ -0,0 +1,19 @@
class_name SceneSingleton extends Node
enum SceneType {
UNSET,
INITIAL,
OVERWORLD
}
var currentScene:SceneType = SceneType.UNSET
signal sceneChanged(newScene:SceneType)
func _enter_tree() -> void:
currentScene = SceneType.UNSET
func setScene(newScene:SceneType) -> void:
if currentScene == newScene:
return
currentScene = newScene
sceneChanged.emit(currentScene)

1
scene/Scene.gd.uid Normal file
View File

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