From 29ebb68215bb0d075785de8ead640f70794f2216 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 4 Jul 2025 15:02:41 -0500 Subject: [PATCH] Map changinbg --- project.godot | 3 +- scenes/SceneTwo.tscn | 50 +++++++++++++++++++++++++++++++ scenes/TestScene.tscn | 36 +++++++++++++++++----- scenes/maps/tundra/MapTundra.tscn | 10 +++++-- scenes/singletons/Load.tscn | 6 ++++ scripts/MapChangeInteract.gd | 15 +++++++--- scripts/OverworldScene.gd | 21 +++++++++++-- scripts/map/Map.gd | 7 ----- scripts/map/Map.gd.uid | 1 - scripts/singletons/Load.gd | 32 ++++++++++++++++++++ scripts/singletons/Load.gd.uid | 1 + scripts/singletons/Overworld.gd | 26 ++++++++++++---- scripts/singletons/Pause.gd | 5 ++-- scripts/singletons/Transition.gd | 18 ++++++----- 14 files changed, 192 insertions(+), 39 deletions(-) create mode 100644 scenes/SceneTwo.tscn create mode 100644 scenes/singletons/Load.tscn delete mode 100644 scripts/map/Map.gd delete mode 100644 scripts/map/Map.gd.uid create mode 100644 scripts/singletons/Load.gd create mode 100644 scripts/singletons/Load.gd.uid diff --git a/project.godot b/project.godot index d5e20c2..14bfc44 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Dawn Godot" -run/main_scene="uid://b16ysbx7ah03u" +run/main_scene="uid://ckkewlcugc8ro" config/features=PackedStringArray("4.4", "GL Compatibility") config/icon="res://icon.svg" @@ -23,6 +23,7 @@ TRANSITION="*res://scenes/singletons/Transition.tscn" UI="*res://scenes/singletons/UI.tscn" QUEST="*res://scenes/singletons/Quest.tscn" OVERWORLD="*res://scripts/singletons/Overworld.gd" +LOAD="*res://scenes/singletons/Load.tscn" [debug] diff --git a/scenes/SceneTwo.tscn b/scenes/SceneTwo.tscn new file mode 100644 index 0000000..31194df --- /dev/null +++ b/scenes/SceneTwo.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=7 format=3 uid="uid://bglgah2w61h7i"] + +[ext_resource type="PackedScene" uid="uid://d3rtd0ln7l2gr" path="res://scenes/maps/tundra/MapTundra.tscn" id="1_x2yj4"] +[ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://scenes/entities/Player.tscn" id="2_fv78m"] +[ext_resource type="PackedScene" uid="uid://bng2mc7fu5aik" path="res://scenes/entities/NPC.tscn" id="3_1v405"] +[ext_resource type="Script" uid="uid://csb0i132lcu0w" path="res://scripts/entities/MapCamera.gd" id="4_3et3s"] + +[sub_resource type="Curve3D" id="Curve3D_x2yj4"] +_data = { +"points": PackedVector3Array(-0.372482, -0.405171, 4.34187, 0.372482, 0.405171, -4.34187, 7.21406, 2.10688, 14.3008, 0, 0, 0, 0, 0, 0, 11.1143, 2.77149, 3.55938, -0.195236, 1.413, 11.5708, 0.195236, -1.413, -11.5708, 20.1087, 3.31252, -17.463), +"tilts": PackedFloat32Array(0, 0, 0) +} +point_count = 3 + +[sub_resource type="Curve3D" id="Curve3D_fv78m"] +_data = { +"points": PackedVector3Array(0, 0, 0, 0, 0, 0, 1.73319, 1.18547, 19.4148, -2.482, -1.23808, 5.14152, 2.482, 1.23808, -5.14152, 2.2062, 1.21935, 8.22687, -2.83202, -0.75344, 5.0391, 2.83202, 0.75344, -5.0391, 2.55912, 0.960021, -4.39348, 0, 0, 0, 0, 0, 0, 10.6352, 0.696404, -20.7808), +"tilts": PackedFloat32Array(0, 0, 0, 0) +} +point_count = 4 + +[node name="SceneTwo" type="Node3D"] + +[node name="MapTundra" parent="." instance=ExtResource("1_x2yj4")] + +[node name="Player" parent="." instance=ExtResource("2_fv78m")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.18123, 1.54702, 6.35532) + +[node name="NPC" parent="." instance=ExtResource("3_1v405")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.233215, 0.903163, 4.44944) + +[node name="Camera3D" type="Camera3D" parent="." node_paths=PackedStringArray("targetFollow", "pathFollow", "pathMap")] +transform = Transform3D(-0.21122, -0.118492, 0.97023, 0, 0.992625, 0.121227, -0.977439, 0.0256054, -0.209662, 10.7276, 2.7398, 4.2924) +fov = 57.5 +script = ExtResource("4_3et3s") +targetFollow = NodePath("../Player") +pathFollow = NodePath("../PathCamera/PathFollow3D") +pathMap = NodePath("../PathWorld") +metadata/_custom_type_script = "uid://csb0i132lcu0w" + +[node name="PathCamera" type="Path3D" parent="."] +curve = SubResource("Curve3D_x2yj4") + +[node name="PathFollow3D" type="PathFollow3D" parent="PathCamera"] +transform = Transform3D(0.88952, 0.00502652, -0.45662, -0.0260722, 0.998736, -0.0397962, 0.455898, 0.0473089, 0.888652, 10.7276, 2.7398, 4.2924) +progress = 10.6821 +loop = false + +[node name="PathWorld" type="Path3D" parent="."] +curve = SubResource("Curve3D_fv78m") diff --git a/scenes/TestScene.tscn b/scenes/TestScene.tscn index 4fbf2bb..14a6ca3 100644 --- a/scenes/TestScene.tscn +++ b/scenes/TestScene.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=12 format=3 uid="uid://b16ysbx7ah03u"] +[gd_scene load_steps=14 format=3 uid="uid://b16ysbx7ah03u"] [ext_resource type="PackedScene" uid="uid://d3rtd0ln7l2gr" path="res://scenes/maps/tundra/MapTundra.tscn" id="1_2gju5"] -[ext_resource type="Script" uid="uid://3uibvxplc48" path="res://scripts/map/Map.gd" id="1_xpysu"] [ext_resource type="PackedScene" uid="uid://2ch34sio36nv" path="res://scenes/entities/Player.tscn" id="2_rlkm5"] [ext_resource type="Script" uid="uid://csb0i132lcu0w" path="res://scripts/entities/MapCamera.gd" id="3_n77mx"] [ext_resource type="PackedScene" uid="uid://bng2mc7fu5aik" path="res://scenes/entities/NPC.tscn" id="4_nb1wl"] [ext_resource type="Script" uid="uid://chxpes3546yoj" path="res://scripts/cutscene/Cutscene.gd" id="5_m5dm6"] [ext_resource type="Script" uid="uid://8updtj1mctra" path="res://scripts/cutscene/item/CutsceneText.gd" id="6_fws1a"] [ext_resource type="PackedScene" uid="uid://cr6h3g15bf6ts" path="res://scenes/MapChangeInteract.tscn" id="8_epq12"] +[ext_resource type="PackedScene" uid="uid://bglgah2w61h7i" path="res://scenes/SceneTwo.tscn" id="9_u6bnu"] [sub_resource type="Curve3D" id="Curve3D_n77mx"] _data = { @@ -23,11 +23,16 @@ _data = { } point_count = 4 +[sub_resource type="BoxShape3D" id="BoxShape3D_u6bnu"] +size = Vector3(5.41431, 3.90259, 3.33496) + [sub_resource type="BoxShape3D" id="BoxShape3D_epq12"] -size = Vector3(2.02835, 3.23706, 2.64648) +size = Vector3(10.521, 3.90259, 3.33496) + +[sub_resource type="BoxShape3D" id="BoxShape3D_yhikq"] +size = Vector3(5.41431, 3.90259, 2.43964) [node name="TestScene" type="Node3D"] -script = ExtResource("1_xpysu") [node name="MapTundra" parent="." instance=ExtResource("1_2gju5")] @@ -40,7 +45,7 @@ interactType = 1 interactTexts = Array[String](["test"]) [node name="Camera3D" type="Camera3D" parent="." node_paths=PackedStringArray("targetFollow", "pathFollow", "pathMap")] -transform = Transform3D(-0.21122, -0.118491, 0.97023, 0, 0.992625, 0.121227, -0.977438, 0.0256055, -0.209663, 10.7276, 2.7398, 4.29238) +transform = Transform3D(-0.21122, -0.118492, 0.97023, 0, 0.992625, 0.121227, -0.977439, 0.0256054, -0.209662, 10.7276, 2.7398, 4.2924) fov = 57.5 script = ExtResource("3_n77mx") targetFollow = NodePath("../Player") @@ -52,7 +57,7 @@ metadata/_custom_type_script = "uid://csb0i132lcu0w" curve = SubResource("Curve3D_n77mx") [node name="PathFollow3D" type="PathFollow3D" parent="PathCamera"] -transform = Transform3D(0.88952, 0.0050268, -0.456619, -0.0260721, 0.998736, -0.0397954, 0.455898, 0.0473081, 0.888652, 10.7276, 2.7398, 4.29238) +transform = Transform3D(0.88952, 0.00502652, -0.45662, -0.0260722, 0.998736, -0.0397962, 0.455898, 0.0473089, 0.888652, 10.7276, 2.7398, 4.2924) progress = 10.6821 loop = false @@ -76,8 +81,25 @@ metadata/_custom_type_script = "uid://8updtj1mctra" [node name="MapChangeInteract" parent="." instance=ExtResource("8_epq12")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.63736, 0, 0.933406) +mapResource = ExtResource("9_u6bnu") [node name="ChildOutsideScene" type="CollisionShape3D" parent="MapChangeInteract"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.589279, 1.69859, 0.859571) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.96407, 1.69859, 0.859571) +shape = SubResource("BoxShape3D_u6bnu") +debug_color = Color(0.537255, 0.698039, 0, 1) + +[node name="MapChangeInteract2" parent="." instance=ExtResource("8_epq12")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.10542, 9.53674e-07, 24.2305) + +[node name="ChildOutsideScene2" type="CollisionShape3D" parent="MapChangeInteract2"] +transform = Transform3D(0.991814, 0.000859021, -0.127689, -0.00103728, 0.999999, -0.0013296, 0.127687, 0.00145116, 0.991813, 4.8648, 2.03135, 0.51722) shape = SubResource("BoxShape3D_epq12") debug_color = Color(0.537255, 0.698039, 0, 1) + +[node name="MapChangeInteract3" parent="." instance=ExtResource("8_epq12")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.63736, 0, 0.933406) + +[node name="ChildOutsideScene" type="CollisionShape3D" parent="MapChangeInteract3"] +transform = Transform3D(0.840207, 0, -0.542266, 0, 1, 0, 0.542266, 0, 0.840207, 2.76805, 1.69859, -15.1128) +shape = SubResource("BoxShape3D_yhikq") +debug_color = Color(0.537255, 0.698039, 0, 1) diff --git a/scenes/maps/tundra/MapTundra.tscn b/scenes/maps/tundra/MapTundra.tscn index 8edfc77..dd6610e 100644 --- a/scenes/maps/tundra/MapTundra.tscn +++ b/scenes/maps/tundra/MapTundra.tscn @@ -24,7 +24,7 @@ sky = SubResource("Sky_nb1wl") ambient_light_source = 3 [sub_resource type="BoxShape3D" id="BoxShape3D_qv7ds"] -size = Vector3(16.9149, 10.2326, 1) +size = Vector3(16.9149, 10.2326, 4.02686) [node name="MapTundra" type="Node3D"] @@ -52,6 +52,12 @@ environment = SubResource("Environment_5tafb") [node name="Fence" parent="." instance=ExtResource("3_qv7ds")] transform = Transform3D(0.200043, 0, 1.71894, 0, 1.73054, 0, -1.71894, 0, 0.200043, -5.16816, 0.497752, 9.45936) +[node name="Fence15" parent="." instance=ExtResource("3_qv7ds")] +transform = Transform3D(0.200043, 0, 1.71894, 0, 1.73054, 0, -1.71894, 0, 0.200043, -4.72367, 0.497752, -7.08098) + +[node name="Fence16" parent="." instance=ExtResource("3_qv7ds")] +transform = Transform3D(0.200043, 0, 1.71894, 0, 1.73054, 0, -1.71894, 0, 0.200043, -4.96908, 0.482898, -4.402) + [node name="Fence2" parent="." instance=ExtResource("3_qv7ds")] transform = Transform3D(-0.106491, 0, 1.72726, 0, 1.73054, 0, -1.72726, 0, -0.106491, -5.16587, 0.497752, 12.43) @@ -94,5 +100,5 @@ transform = Transform3D(0.164813, 0, 1.72267, 0, 1.73054, 0, -1.72267, 0, 0.1648 [node name="StaticBody3D" type="StaticBody3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.68842, 4.77113, 26.9999) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.68842, 4.77113, 25.4865) shape = SubResource("BoxShape3D_qv7ds") diff --git a/scenes/singletons/Load.tscn b/scenes/singletons/Load.tscn new file mode 100644 index 0000000..2d6e003 --- /dev/null +++ b/scenes/singletons/Load.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8shl8u156rfi"] + +[ext_resource type="Script" uid="uid://dfpml5awf5i35" path="res://scripts/singletons/Load.gd" id="1_a3iwn"] + +[node name="Load" type="Node"] +script = ExtResource("1_a3iwn") diff --git a/scripts/MapChangeInteract.gd b/scripts/MapChangeInteract.gd index 90f756e..4365566 100644 --- a/scripts/MapChangeInteract.gd +++ b/scripts/MapChangeInteract.gd @@ -1,11 +1,18 @@ class_name MapChangeInteract extends Node3D + +@export var mapResource:PackedScene +@export var destinationPointNodeName:String var interactableArea:InteractableArea var shapeChild:CollisionShape3D func _enter_tree() -> void: interactableArea = $InteractableArea + if !mapResource: + push_error("MapChangeInteract must have a mapResource set.") + return + # Needs to be exactly one child. if get_child_count() != 2: push_error("MapChangeInteract must have exactly one child InteractableArea node.") @@ -31,13 +38,13 @@ func _exit_tree() -> void: interactableArea.remove_child(shapeChild) add_child(shapeChild) -func onInteract(ent:Player) -> void: - print("MapChangeInteract: onInteract called") +func onInteract(_ent:Player) -> void: + OVERWORLD.mapChange(mapResource, destinationPointNodeName) -func onInteractable(ent:Player) -> void: +func onInteractable(_ent:Player) -> void: print("Able to leave map") pass -func onNotInteractable(ent:Player) -> void: +func onNotInteractable(_ent:Player) -> void: print("Not able to leave map") pass \ No newline at end of file diff --git a/scripts/OverworldScene.gd b/scripts/OverworldScene.gd index a94a729..06789e3 100644 --- a/scripts/OverworldScene.gd +++ b/scripts/OverworldScene.gd @@ -6,5 +6,22 @@ func _enter_tree() -> void: func _exit_tree() -> void: OVERWORLD.mapChanged.disconnect(onMapChanged) -func onMapChanged() -> void: - pass \ No newline at end of file +func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void: + print("New map time.") + var map = $Map + for childScene in map.get_children(): + map.remove_child(childScene) + + var newMapInstance = newMap.instantiate() + 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 diff --git a/scripts/map/Map.gd b/scripts/map/Map.gd deleted file mode 100644 index 3956afb..0000000 --- a/scripts/map/Map.gd +++ /dev/null @@ -1,7 +0,0 @@ -class_name Map extends Node - -enum MapKey { - TEST_MAP -} - -@export var mapKey:MapKey \ No newline at end of file diff --git a/scripts/map/Map.gd.uid b/scripts/map/Map.gd.uid deleted file mode 100644 index 7fc7eab..0000000 --- a/scripts/map/Map.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://3uibvxplc48 diff --git a/scripts/singletons/Load.gd b/scripts/singletons/Load.gd new file mode 100644 index 0000000..2ef5527 --- /dev/null +++ b/scripts/singletons/Load.gd @@ -0,0 +1,32 @@ +class_name LoadSingleton extends Node + +signal loadStart(scenePath:String, loadId:int) +signal loadEnd(scenePath:String, loadId:int, resource:Resource) +signal loadError(scenePath:String, loadId:int, error:String) +signal loadProgress(scenePath:String, loadId:int, progress:float) + +var watchingIds:Array[int] = [] + +func _process(delta: float) -> void: + var wIds = watchingIds.duplicate() + for watchId in wIds: + var status = ResourceLoader.load_threaded_get_status(watchId) + if status == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_LOADED: + watchingIds.erase(watchId) + var resource = ResourceLoader.load_threaded_get(watchId) + loadEnd.emit(watchId, resource) + elif status == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_FAILED: + watchingIds.erase(watchId) + loadError.emit(watchId, "Error loading resource.") + elif status == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_INVALID_RESOURCE: + watchingIds.erase(watchId) + loadError.emit(watchId, "Invalid Resource.") + elif status == ResourceLoader.ThreadLoadStatus.THREAD_LOAD_IN_PROGRESS: + loadProgress.emit(watchId, 0.0) + pass + +func load(scenePath:String) -> int: + var loadId = ResourceLoader.load_threaded_request(scenePath) + watchingIds.append(loadId) + loadStart.emit(scenePath, loadId) + return loadId \ No newline at end of file diff --git a/scripts/singletons/Load.gd.uid b/scripts/singletons/Load.gd.uid new file mode 100644 index 0000000..c4ed19d --- /dev/null +++ b/scripts/singletons/Load.gd.uid @@ -0,0 +1 @@ +uid://dfpml5awf5i35 diff --git a/scripts/singletons/Overworld.gd b/scripts/singletons/Overworld.gd index 76eb637..39fd5b0 100644 --- a/scripts/singletons/Overworld.gd +++ b/scripts/singletons/Overworld.gd @@ -1,19 +1,35 @@ class_name OverworldSingleton extends Node -signal mapChanged +signal mapChanged(newMap:PackedScene, playerDestinationNodeName:String) + +var newMap:PackedScene +var playerDestinationNodeName:String func _init() -> void: pass func _exit_tree() -> void: TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd) + TRANSITION.fadeInEnd.disconnect(onFadeInEnd) -func mapChange(map:Map.MapKey) -> void: +func mapChange(map:PackedScene, playerDestinationNodeName:String) -> void: TRANSITION.fade(TransitionSingleton.FadeType.FADE_OUT) TRANSITION.fadeOutEnd.connect(onFadeOutEnd) - print("OverworldSingleton: mapChange called with map:", map) + newMap = map + self.playerDestinationNodeName = playerDestinationNodeName func onFadeOutEnd() -> void: - TRANSITION.fadtOutEnd.disconnect(onFadeOutEnd) + TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd) TRANSITION.fade(TransitionSingleton.FadeType.FADE_IN) - mapChanged.emit() \ No newline at end of file + 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/scripts/singletons/Pause.gd b/scripts/singletons/Pause.gd index c1ee2db..9ea2340 100644 --- a/scripts/singletons/Pause.gd +++ b/scripts/singletons/Pause.gd @@ -8,7 +8,6 @@ func cutscenePause() -> void: func cutsceneResume() -> void: cutscenePaused = false - func isMovementPaused() -> bool: if cutscenePaused: return true @@ -18,10 +17,12 @@ func isMovementPaused() -> bool: if UI.PAUSE.isOpen(): return true + + if OVERWORLD.isMapChanging(): + return true return false - func menuPause() -> void: if UI.PAUSE.isOpen(): UI.PAUSE.close() diff --git a/scripts/singletons/Transition.gd b/scripts/singletons/Transition.gd index 2fbff1e..caa9fd5 100644 --- a/scripts/singletons/Transition.gd +++ b/scripts/singletons/Transition.gd @@ -15,6 +15,7 @@ signal fadeUpdate(t:float) var fadeType:FadeType = FadeType.NONE var fadeDuration:float = 0.4 var fadeTime:float = 0.0 +var inFade = false func _enter_tree() -> void: $Overlay.visible = false @@ -40,17 +41,15 @@ func _process(delta: float) -> void: if t >= 1.0: fadeUpdate.emit(1.0) var cFade = fadeType - print("Transition: Fade complete") fadeType = FadeType.NONE + $Overlay.color.a = destAlpha + inFade = false if cFade == FadeType.FADE_OUT: - $Overlay.visible = true fadeOutEnd.emit() elif cFade == FadeType.FADE_IN: - $Overlay.visible = false fadeInEnd.emit() - $Overlay.color.a = destAlpha return # TODO: Use curves @@ -63,17 +62,20 @@ func fade( duration:float = 0.4, color:Color = Color(0, 0, 0, 1), ): - $Overlay.visible = false + if inFade: + push_error("Transition: Cannot start a new fade while another is in progress.") + return + + $Overlay.visible = true $Overlay.color = color fadeDuration = duration fadeTime = 0 fadeType = fade + inFade = true if fade == FadeType.FADE_IN: fadeInStart.emit() $Overlay.color.a = 0 elif fade == FadeType.FADE_OUT: fadeOutStart.emit() - $Overlay.color.a = 1 - - $Overlay.visible = true \ No newline at end of file + $Overlay.color.a = 1 \ No newline at end of file