Map changinbg
This commit is contained in:
@@ -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
|
@@ -6,5 +6,22 @@ func _enter_tree() -> void:
|
||||
func _exit_tree() -> void:
|
||||
OVERWORLD.mapChanged.disconnect(onMapChanged)
|
||||
|
||||
func onMapChanged() -> void:
|
||||
pass
|
||||
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
|
||||
|
@@ -1,7 +0,0 @@
|
||||
class_name Map extends Node
|
||||
|
||||
enum MapKey {
|
||||
TEST_MAP
|
||||
}
|
||||
|
||||
@export var mapKey:MapKey
|
@@ -1 +0,0 @@
|
||||
uid://3uibvxplc48
|
32
scripts/singletons/Load.gd
Normal file
32
scripts/singletons/Load.gd
Normal file
@@ -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
|
1
scripts/singletons/Load.gd.uid
Normal file
1
scripts/singletons/Load.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dfpml5awf5i35
|
@@ -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()
|
||||
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
|
||||
|
@@ -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()
|
||||
|
@@ -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
|
||||
$Overlay.color.a = 1
|
Reference in New Issue
Block a user