Godot 4.5.1
This commit is contained in:
@@ -8,25 +8,25 @@ 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
|
||||
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
|
||||
var loadId = ResourceLoader.load_threaded_request(scenePath)
|
||||
watchingIds.append(loadId)
|
||||
loadStart.emit(scenePath, loadId)
|
||||
return loadId
|
||||
@@ -9,77 +9,77 @@ var playerDestinationNodeName:String
|
||||
var newMapLoaded:bool = false
|
||||
|
||||
func isMapChanging() -> bool:
|
||||
return newMapPath != ""
|
||||
return newMapPath != ""
|
||||
|
||||
func _enter_tree() -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
func _exit_tree() -> void:
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
|
||||
func _process(_delta:float) -> void:
|
||||
if(!isMapChanging()):
|
||||
return
|
||||
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 = ""
|
||||
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_IN_PROGRESS:
|
||||
print("Map loading in progress for: " + newMapPath)
|
||||
|
||||
elif status == ResourceLoader.THREAD_LOAD_LOADED:
|
||||
newMapLoaded = true
|
||||
newMapReady()
|
||||
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 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)
|
||||
# Begin fadeout
|
||||
hasFadedOut = false
|
||||
TRANSITION.fade(TransitionSingleton.FadeType.FADE_OUT)
|
||||
TRANSITION.fadeOutEnd.connect(onFadeOutEnd)
|
||||
|
||||
func onFadeOutEnd() -> void:
|
||||
# Fade out has occurred, are we still waiting for the map to load?
|
||||
TRANSITION.fadeOutEnd.disconnect(onFadeOutEnd)
|
||||
hasFadedOut = true
|
||||
# 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()
|
||||
# Make sure we aren't still waiting for the map to load.
|
||||
if !newMapLoaded:
|
||||
return
|
||||
newMapReady()
|
||||
|
||||
func newMapReady():
|
||||
if !hasFadedOut:
|
||||
return
|
||||
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 = ""
|
||||
# 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)
|
||||
# Emit event
|
||||
mapChanged.emit(mapResource, playerDestinationNodeName)
|
||||
|
||||
# Begin Fade In
|
||||
TRANSITION.fade(TransitionSingleton.FadeType.FADE_IN)
|
||||
TRANSITION.fadeInEnd.connect(onFadeInEnd)
|
||||
# Begin Fade In
|
||||
TRANSITION.fade(TransitionSingleton.FadeType.FADE_IN)
|
||||
TRANSITION.fadeInEnd.connect(onFadeInEnd)
|
||||
|
||||
func onFadeInEnd() -> void:
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
TRANSITION.fadeInEnd.disconnect(onFadeInEnd)
|
||||
|
||||
@@ -3,28 +3,28 @@ class_name PauseSingleton extends Node
|
||||
var cutscenePaused:bool = false
|
||||
|
||||
func cutscenePause() -> void:
|
||||
cutscenePaused = true
|
||||
cutscenePaused = true
|
||||
|
||||
func cutsceneResume() -> void:
|
||||
cutscenePaused = false
|
||||
cutscenePaused = false
|
||||
|
||||
func isMovementPaused() -> bool:
|
||||
if cutscenePaused:
|
||||
return true
|
||||
if cutscenePaused:
|
||||
return true
|
||||
|
||||
if !UI.TEXTBOX.isClosed:
|
||||
return true
|
||||
if !UI.TEXTBOX.isClosed:
|
||||
return true
|
||||
|
||||
if UI.PAUSE.isOpen():
|
||||
return true
|
||||
if UI.PAUSE.isOpen():
|
||||
return true
|
||||
|
||||
if OVERWORLD.isMapChanging():
|
||||
return true
|
||||
|
||||
return false
|
||||
if OVERWORLD.isMapChanging():
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func menuPause() -> void:
|
||||
if UI.PAUSE.isOpen():
|
||||
UI.PAUSE.close()
|
||||
else:
|
||||
UI.PAUSE.open()
|
||||
if UI.PAUSE.isOpen():
|
||||
UI.PAUSE.close()
|
||||
else:
|
||||
UI.PAUSE.open()
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
class_name SceneSingleton extends Node
|
||||
|
||||
enum SceneType {
|
||||
UNSET,
|
||||
INITIAL,
|
||||
OVERWORLD
|
||||
UNSET,
|
||||
INITIAL,
|
||||
OVERWORLD
|
||||
}
|
||||
|
||||
var currentScene:SceneType = SceneType.UNSET
|
||||
signal sceneChanged(newScene:SceneType)
|
||||
|
||||
func _enter_tree() -> void:
|
||||
currentScene = SceneType.UNSET
|
||||
currentScene = SceneType.UNSET
|
||||
|
||||
func setScene(newScene:SceneType) -> void:
|
||||
if currentScene == newScene:
|
||||
return
|
||||
currentScene = newScene
|
||||
sceneChanged.emit(currentScene)
|
||||
if currentScene == newScene:
|
||||
return
|
||||
currentScene = newScene
|
||||
sceneChanged.emit(currentScene)
|
||||
@@ -1,9 +1,9 @@
|
||||
class_name TransitionSingleton extends Control
|
||||
|
||||
enum FadeType {
|
||||
NONE,
|
||||
FADE_IN,
|
||||
FADE_OUT
|
||||
NONE,
|
||||
FADE_IN,
|
||||
FADE_OUT
|
||||
}
|
||||
|
||||
signal fadeOutStart
|
||||
@@ -18,64 +18,64 @@ var fadeTime:float = 0.0
|
||||
var inFade = false
|
||||
|
||||
func _enter_tree() -> void:
|
||||
$Overlay.visible = false
|
||||
$Overlay.visible = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if fadeType == FadeType.NONE:
|
||||
return
|
||||
if fadeType == FadeType.NONE:
|
||||
return
|
||||
|
||||
fadeTime += delta
|
||||
var t:float = fadeTime / fadeDuration
|
||||
fadeTime += delta
|
||||
var t:float = fadeTime / fadeDuration
|
||||
|
||||
# Get destination alpha type.
|
||||
var destAlpha:float = 0.0
|
||||
var srcAlpha:float
|
||||
if fadeType == FadeType.FADE_IN:
|
||||
srcAlpha = 1.0
|
||||
destAlpha = 0.0
|
||||
elif fadeType == FadeType.FADE_OUT:
|
||||
srcAlpha = 0.0
|
||||
destAlpha = 1.0
|
||||
# Get destination alpha type.
|
||||
var destAlpha:float = 0.0
|
||||
var srcAlpha:float
|
||||
if fadeType == FadeType.FADE_IN:
|
||||
srcAlpha = 1.0
|
||||
destAlpha = 0.0
|
||||
elif fadeType == FadeType.FADE_OUT:
|
||||
srcAlpha = 0.0
|
||||
destAlpha = 1.0
|
||||
|
||||
# End?
|
||||
if t >= 1.0:
|
||||
fadeUpdate.emit(1.0)
|
||||
var cFade = fadeType
|
||||
fadeType = FadeType.NONE
|
||||
$Overlay.color.a = destAlpha
|
||||
inFade = false
|
||||
# End?
|
||||
if t >= 1.0:
|
||||
fadeUpdate.emit(1.0)
|
||||
var cFade = fadeType
|
||||
fadeType = FadeType.NONE
|
||||
$Overlay.color.a = destAlpha
|
||||
inFade = false
|
||||
|
||||
if cFade == FadeType.FADE_OUT:
|
||||
fadeOutEnd.emit()
|
||||
elif cFade == FadeType.FADE_IN:
|
||||
fadeInEnd.emit()
|
||||
|
||||
return
|
||||
if cFade == FadeType.FADE_OUT:
|
||||
fadeOutEnd.emit()
|
||||
elif cFade == FadeType.FADE_IN:
|
||||
fadeInEnd.emit()
|
||||
|
||||
return
|
||||
|
||||
# TODO: Use curves
|
||||
$Overlay.color.a = srcAlpha + (destAlpha - srcAlpha) * t
|
||||
fadeUpdate.emit(t)
|
||||
pass
|
||||
# TODO: Use curves
|
||||
$Overlay.color.a = srcAlpha + (destAlpha - srcAlpha) * t
|
||||
fadeUpdate.emit(t)
|
||||
pass
|
||||
|
||||
func fade(
|
||||
fade:FadeType = FadeType.FADE_IN,
|
||||
duration:float = 0.4,
|
||||
color:Color = Color(0, 0, 0, 1),
|
||||
fade:FadeType = FadeType.FADE_IN,
|
||||
duration:float = 0.4,
|
||||
color:Color = Color(0, 0, 0, 1),
|
||||
):
|
||||
if inFade:
|
||||
push_error("Transition: Cannot start a new fade while another is in progress.")
|
||||
return
|
||||
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
|
||||
$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
|
||||
if fade == FadeType.FADE_IN:
|
||||
fadeInStart.emit()
|
||||
$Overlay.color.a = 0
|
||||
elif fade == FadeType.FADE_OUT:
|
||||
fadeOutStart.emit()
|
||||
$Overlay.color.a = 1
|
||||
Reference in New Issue
Block a user