Made map loading work
This commit is contained in:
		@@ -9,4 +9,4 @@ func start() -> void:
 | 
				
			|||||||
func done() -> void:
 | 
					func done() -> void:
 | 
				
			||||||
	if !cutscene:
 | 
						if !cutscene:
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	cutscene.nextItem()
 | 
						cutscene.nextItem()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
[gd_scene load_steps=13 format=3 uid="uid://b16ysbx7ah03u"]
 | 
					[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="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="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"]
 | 
					[ext_resource type="PackedScene" uid="uid://bng2mc7fu5aik" path="res://entities/NPC.tscn" id="4_nb1wl"]
 | 
				
			||||||
@@ -1,17 +1,18 @@
 | 
				
			|||||||
class_name OverworldScene extends Node
 | 
					class_name OverworldScene extends Node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@export var map:Node3D = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _enter_tree() -> void:
 | 
					func _enter_tree() -> void:
 | 
				
			||||||
	OVERWORLD.mapChanged.connect(onMapChanged)
 | 
						OVERWORLD.mapChanged.connect(onMapChanged)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _ready() -> void:
 | 
					func _ready() -> void:
 | 
				
			||||||
	onMapChanged(OVERWORLD.newMap, OVERWORLD.playerDestinationNodeName)
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _exit_tree() -> void:
 | 
					func _exit_tree() -> void:
 | 
				
			||||||
	OVERWORLD.mapChanged.disconnect(onMapChanged)
 | 
						OVERWORLD.mapChanged.disconnect(onMapChanged)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
 | 
					func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
 | 
				
			||||||
	print("New map time.")
 | 
						print("New map time.", newMap)
 | 
				
			||||||
	var map = $Map
 | 
					 | 
				
			||||||
	for childScene in map.get_children():
 | 
						for childScene in map.get_children():
 | 
				
			||||||
		map.remove_child(childScene)
 | 
							map.remove_child(childScene)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,12 +23,12 @@ func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
 | 
				
			|||||||
	map.add_child(newMapInstance)
 | 
						map.add_child(newMapInstance)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Find Player.
 | 
						# Find Player.
 | 
				
			||||||
	var player = newMapInstance.get_node("Player")
 | 
						if playerDestinationNodeName:
 | 
				
			||||||
	var destNode = newMapInstance.get_node(playerDestinationNodeName)
 | 
							var player = newMapInstance.get_node("Player")
 | 
				
			||||||
	if player && player is Player && destNode:
 | 
							var destNode = newMapInstance.get_node(playerDestinationNodeName)
 | 
				
			||||||
		player.global_position = destNode.global_position
 | 
							if player && player is Player && destNode:
 | 
				
			||||||
		player.global_rotation.y = destNode.global_rotation.y
 | 
								player.global_position = destNode.global_position
 | 
				
			||||||
	elif playerDestinationNodeName:
 | 
								player.global_rotation.y = destNode.global_rotation.y
 | 
				
			||||||
		push_error("Player, or destination node not found in new map.")
 | 
							elif playerDestinationNodeName:
 | 
				
			||||||
 | 
								push_error("Player, or destination node not found in new map.")
 | 
				
			||||||
	pass
 | 
							pass
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[ext_resource type="Script" uid="uid://dpvccegdmn7s6" path="res://meta/OverworldScene.gd" id="1_fa54r"]
 | 
					[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")
 | 
					script = ExtResource("1_fa54r")
 | 
				
			||||||
 | 
					map = NodePath("Map")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="Map" type="Node3D" parent="."]
 | 
					[node name="Map" type="Node3D" parent="."]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,4 +30,4 @@ func onSceneChange(newScene:SceneSingleton.SceneType) -> void:
 | 
				
			|||||||
			pass
 | 
								pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_:
 | 
							_:
 | 
				
			||||||
			pass
 | 
								pass
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,8 +10,6 @@ overworld = NodePath("OverworldScene")
 | 
				
			|||||||
initial = NodePath("InitialScene")
 | 
					initial = NodePath("InitialScene")
 | 
				
			||||||
metadata/_custom_type_script = "uid://ml70iui7qpo4"
 | 
					metadata/_custom_type_script = "uid://ml70iui7qpo4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")]
 | 
					 | 
				
			||||||
visible = false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[node name="OverworldScene" parent="." instance=ExtResource("2_o1wvd")]
 | 
					[node name="OverworldScene" parent="." instance=ExtResource("2_o1wvd")]
 | 
				
			||||||
visible = false
 | 
					
 | 
				
			||||||
 | 
					[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,3 @@
 | 
				
			|||||||
class_name GamePhysicsSingleton extends Node
 | 
					class_name GamePhysicsSingleton extends Node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const GRAVITY = Vector3.DOWN * 9.8
 | 
					const GRAVITY = Vector3.DOWN * 9.8
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,34 +1,85 @@
 | 
				
			|||||||
class_name OverworldSingleton extends Node
 | 
					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 playerDestinationNodeName:String
 | 
				
			||||||
 | 
					var newMapLoaded:bool = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _init() -> void:
 | 
					func isMapChanging() -> bool:
 | 
				
			||||||
 | 
						return newMapPath != ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _enter_tree() -> void:
 | 
				
			||||||
	pass
 | 
						pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _exit_tree() -> void:
 | 
					func _exit_tree() -> void:
 | 
				
			||||||
	TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
 | 
						TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
 | 
				
			||||||
	TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
 | 
						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.fade(TransitionSingleton.FadeType.FADE_OUT)
 | 
				
			||||||
	TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
 | 
						TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
 | 
				
			||||||
	newMap = map
 | 
					 | 
				
			||||||
	self.playerDestinationNodeName = playerDestinationNodeName
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func onFadeOutEnd() -> void:
 | 
					func onFadeOutEnd() -> void:
 | 
				
			||||||
 | 
						# Fade out has occurred, are we still waiting for the map to load?
 | 
				
			||||||
	TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
 | 
						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.fade(TransitionSingleton.FadeType.FADE_IN)
 | 
				
			||||||
	TRANSITION.fadeInEnd.connect(onFadeInEnd)
 | 
						TRANSITION.fadeInEnd.connect(onFadeInEnd)
 | 
				
			||||||
	mapChanged.emit(newMap, playerDestinationNodeName)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func onFadeInEnd() -> void:
 | 
					func onFadeInEnd() -> void:
 | 
				
			||||||
	TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
 | 
						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
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ class_name MainMenu extends Control
 | 
				
			|||||||
@export var btnNewGame:Button
 | 
					@export var btnNewGame:Button
 | 
				
			||||||
@export var btnSettings:Button
 | 
					@export var btnSettings:Button
 | 
				
			||||||
@export var settingsMenu:ClosableMenu
 | 
					@export var settingsMenu:ClosableMenu
 | 
				
			||||||
 | 
					@export_file("*.tscn") var newGameScene:String
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _ready() -> void:
 | 
					func _ready() -> void:
 | 
				
			||||||
	btnNewGame.pressed.connect(onNewGamePressed)
 | 
						btnNewGame.pressed.connect(onNewGamePressed)
 | 
				
			||||||
@@ -10,6 +11,7 @@ func _ready() -> void:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func onNewGamePressed() -> void:
 | 
					func onNewGamePressed() -> void:
 | 
				
			||||||
	SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
 | 
						SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
 | 
				
			||||||
 | 
						OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func onSettingsPressed() -> void:
 | 
					func onSettingsPressed() -> void:
 | 
				
			||||||
	print("Settings button pressed")
 | 
						print("Settings button pressed")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ script = ExtResource("1_vp3lc")
 | 
				
			|||||||
btnNewGame = NodePath("VBoxContainer/NewGame")
 | 
					btnNewGame = NodePath("VBoxContainer/NewGame")
 | 
				
			||||||
btnSettings = NodePath("VBoxContainer/Settings")
 | 
					btnSettings = NodePath("VBoxContainer/Settings")
 | 
				
			||||||
settingsMenu = NodePath("MainMenuSettings")
 | 
					settingsMenu = NodePath("MainMenuSettings")
 | 
				
			||||||
 | 
					newGameScene = "uid://b16ysbx7ah03u"
 | 
				
			||||||
metadata/_custom_type_script = "uid://btfeuku41py2b"
 | 
					metadata/_custom_type_script = "uid://btfeuku41py2b"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
 | 
					[node name="VBoxContainer" type="VBoxContainer" parent="."]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user