diff --git a/cutscene/item/CutsceneItem.gd b/cutscene/item/CutsceneItem.gd index fe35748..80892a1 100644 --- a/cutscene/item/CutsceneItem.gd +++ b/cutscene/item/CutsceneItem.gd @@ -9,4 +9,4 @@ func start() -> void: func done() -> void: if !cutscene: return - cutscene.nextItem() \ No newline at end of file + cutscene.nextItem() diff --git a/maps/MapTundra.tscn b/maps/MapTundra/BaseMapTundra.tscn similarity index 100% rename from maps/MapTundra.tscn rename to maps/MapTundra/BaseMapTundra.tscn diff --git a/TestScene.tscn b/maps/MapTundra/TestMapTundra.tscn similarity index 98% rename from TestScene.tscn rename to maps/MapTundra/TestMapTundra.tscn index 1173cd7..b368e0d 100644 --- a/TestScene.tscn +++ b/maps/MapTundra/TestMapTundra.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=13 format=3 uid="uid://b16ysbx7ah03u"] -[ext_resource type="PackedScene" uid="uid://bicg5j33d72ld" path="res://maps/MapTundra.tscn" id="1_2gju5"] +[ext_resource type="PackedScene" uid="uid://bicg5j33d72ld" path="res://maps/MapTundra/BaseMapTundra.tscn" id="1_2gju5"] [ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://entities/Player.tscn" id="2_rlkm5"] [ext_resource type="Script" uid="uid://csb0i132lcu0w" path="res://entities/MapCamera.gd" id="3_n77mx"] [ext_resource type="PackedScene" uid="uid://bng2mc7fu5aik" path="res://entities/NPC.tscn" id="4_nb1wl"] diff --git a/meta/OverworldScene.gd b/meta/OverworldScene.gd index e5aabe1..a74ae8f 100644 --- a/meta/OverworldScene.gd +++ b/meta/OverworldScene.gd @@ -1,17 +1,18 @@ class_name OverworldScene extends Node +@export var map:Node3D = null + func _enter_tree() -> void: OVERWORLD.mapChanged.connect(onMapChanged) func _ready() -> void: - onMapChanged(OVERWORLD.newMap, OVERWORLD.playerDestinationNodeName) + pass func _exit_tree() -> void: OVERWORLD.mapChanged.disconnect(onMapChanged) func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void: - print("New map time.") - var map = $Map + print("New map time.", newMap) for childScene in map.get_children(): map.remove_child(childScene) @@ -22,12 +23,12 @@ func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void: map.add_child(newMapInstance) # Find Player. - 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 + 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 diff --git a/meta/OverworldScene.tscn b/meta/OverworldScene.tscn index 3785ac7..74309fe 100644 --- a/meta/OverworldScene.tscn +++ b/meta/OverworldScene.tscn @@ -2,7 +2,8 @@ [ext_resource type="Script" uid="uid://dpvccegdmn7s6" path="res://meta/OverworldScene.gd" id="1_fa54r"] -[node name="OverworldScene" type="Node3D"] +[node name="OverworldScene" type="Node3D" node_paths=PackedStringArray("map")] script = ExtResource("1_fa54r") +map = NodePath("Map") [node name="Map" type="Node3D" parent="."] diff --git a/meta/RootScene.gd b/meta/RootScene.gd index dfd2fe9..ebbf92e 100644 --- a/meta/RootScene.gd +++ b/meta/RootScene.gd @@ -30,4 +30,4 @@ func onSceneChange(newScene:SceneSingleton.SceneType) -> void: pass _: - pass \ No newline at end of file + pass diff --git a/meta/RootScene.tscn b/meta/RootScene.tscn index a7feb4b..ffb05a1 100644 --- a/meta/RootScene.tscn +++ b/meta/RootScene.tscn @@ -10,8 +10,6 @@ overworld = NodePath("OverworldScene") initial = NodePath("InitialScene") metadata/_custom_type_script = "uid://ml70iui7qpo4" -[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")] -visible = false - [node name="OverworldScene" parent="." instance=ExtResource("2_o1wvd")] -visible = false + +[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")] diff --git a/singletons/GamePhysics.gd b/singletons/GamePhysics.gd index 0ec3b8e..4cabc6a 100644 --- a/singletons/GamePhysics.gd +++ b/singletons/GamePhysics.gd @@ -1,3 +1,3 @@ class_name GamePhysicsSingleton extends Node -const GRAVITY = Vector3.DOWN * 9.8 \ No newline at end of file +const GRAVITY = Vector3.DOWN * 9.8 diff --git a/singletons/Overworld.gd b/singletons/Overworld.gd index f8c7a87..89f4e2d 100644 --- a/singletons/Overworld.gd +++ b/singletons/Overworld.gd @@ -1,34 +1,85 @@ class_name OverworldSingleton extends Node -signal mapChanged(newMap:PackedScene, playerDestinationNodeName:String) +signal mapChanged(map:PackedScene, playerDestinationNodeName:String) -var newMap:PackedScene + +var newMapPath:String +var hasFadedOut:bool = false var playerDestinationNodeName:String +var newMapLoaded:bool = false -func _init() -> void: +func isMapChanging() -> bool: + return newMapPath != "" + +func _enter_tree() -> void: pass func _exit_tree() -> void: TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd) TRANSITION.fadeInEnd.disconnect(onFadeInEnd) -func mapChange(map:PackedScene, playerDestinationNodeName:String) -> void: +func _process(delta:float) -> void: + if(!isMapChanging()): + return + + var status = ResourceLoader.load_threaded_get_status(newMapPath) + if status == ResourceLoader.THREAD_LOAD_FAILED: + push_error("Failed to load map: " + newMapPath) + newMapPath = "" + + elif status == ResourceLoader.THREAD_LOAD_INVALID_RESOURCE: + push_error("Failed to load map: " + newMapPath) + newMapPath = "" + + elif status == ResourceLoader.THREAD_LOAD_IN_PROGRESS: + print("Map loading in progress for: " + newMapPath) + + elif status == ResourceLoader.THREAD_LOAD_LOADED: + newMapLoaded = true + newMapReady() + + + +func mapChange(map:String, playerDestinationNodeName:String) -> void: + # Begin Loading new map + newMapPath = map + playerDestinationNodeName = playerDestinationNodeName + ResourceLoader.load_threaded_request(newMapPath) + + # Begin fadeout + hasFadedOut = false TRANSITION.fade(TransitionSingleton.FadeType.FADE_OUT) TRANSITION.fadeOutEnd.connect(onFadeOutEnd) - newMap = map - self.playerDestinationNodeName = playerDestinationNodeName func onFadeOutEnd() -> void: + # Fade out has occurred, are we still waiting for the map to load? TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd) + hasFadedOut = true + + # Make sure we aren't still waiting for the map to load. + if !newMapLoaded: + return + newMapReady() + +func newMapReady(): + if !hasFadedOut: + return + + # Instantiate the new map + var mapResource = ResourceLoader.load_threaded_get(newMapPath) + if mapResource == null: + push_error("Failed to load map resource: " + newMapPath) + return + + # Stop tracking new map name + newMapPath = "" + + # Emit event + mapChanged.emit(mapResource, playerDestinationNodeName) + + # Begin Fade In TRANSITION.fade(TransitionSingleton.FadeType.FADE_IN) TRANSITION.fadeInEnd.connect(onFadeInEnd) - mapChanged.emit(newMap, playerDestinationNodeName) - func onFadeInEnd() -> void: TRANSITION.fadeInEnd.disconnect(onFadeInEnd) - newMap = null - -func isMapChanging() -> bool: - # If the newMap is set, then we are in the process of changing maps. - return newMap != null diff --git a/ui/mainmenu/MainMenu.gd b/ui/mainmenu/MainMenu.gd index 745ff95..634d342 100644 --- a/ui/mainmenu/MainMenu.gd +++ b/ui/mainmenu/MainMenu.gd @@ -3,6 +3,7 @@ class_name MainMenu extends Control @export var btnNewGame:Button @export var btnSettings:Button @export var settingsMenu:ClosableMenu +@export_file("*.tscn") var newGameScene:String func _ready() -> void: btnNewGame.pressed.connect(onNewGamePressed) @@ -10,6 +11,7 @@ func _ready() -> void: func onNewGamePressed() -> void: SCENE.setScene(SceneSingleton.SceneType.OVERWORLD) + OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint") func onSettingsPressed() -> void: print("Settings button pressed") diff --git a/ui/mainmenu/MainMenu.tscn b/ui/mainmenu/MainMenu.tscn index d9a2bf3..c212dfd 100644 --- a/ui/mainmenu/MainMenu.tscn +++ b/ui/mainmenu/MainMenu.tscn @@ -15,6 +15,7 @@ script = ExtResource("1_vp3lc") btnNewGame = NodePath("VBoxContainer/NewGame") btnSettings = NodePath("VBoxContainer/Settings") settingsMenu = NodePath("MainMenuSettings") +newGameScene = "uid://b16ysbx7ah03u" metadata/_custom_type_script = "uid://btfeuku41py2b" [node name="VBoxContainer" type="VBoxContainer" parent="."]