Map changinbg

This commit is contained in:
2025-07-04 15:02:41 -05:00
parent 7ae9d534ab
commit 29ebb68215
14 changed files with 192 additions and 39 deletions

View 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

View File

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

View File

@@ -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

View File

@@ -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()

View File

@@ -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