Add crashing prevention
This commit is contained in:
parent
527bd23363
commit
126ca9f412
2 changed files with 13 additions and 3 deletions
|
@ -28,7 +28,8 @@ var presenloader: Node
|
|||
# Presentation data
|
||||
var entrypoint: PresencodeEntrypoint
|
||||
var manifest: Dictionary
|
||||
var current_slide: int = -1
|
||||
var current_slide: int = 0
|
||||
var slide_switch_in_progress: bool = false
|
||||
|
||||
# +++ initialization +++
|
||||
func _init(core_new: Core, presenloader_new: Node) -> void:
|
||||
|
@ -56,13 +57,17 @@ func _process(_delta: float) -> void:
|
|||
|
||||
# +++ slide management +++
|
||||
func switch_slide(new_slide: int) -> PresencodeTypes.PresencodeError:
|
||||
if slide_switch_in_progress: return PresencodeTypes.PresencodeError.ALREADY_RUNNING
|
||||
slide_switch_in_progress = true
|
||||
var old_slide: int = current_slide
|
||||
|
||||
if new_slide < 0:
|
||||
logger.error(core.misc.stringify_variables("Invalid slide %slide%", { "slide": new_slide }))
|
||||
slide_switch_in_progress = false
|
||||
return PresencodeTypes.PresencodeError.INVALID_SLIDE
|
||||
if new_slide > manifest["slides"]:
|
||||
logger.error(core.misc.stringify_variables("Invalid slide %slide%", { "slide": new_slide }))
|
||||
slide_switch_in_progress = false
|
||||
return PresencodeTypes.PresencodeError.INVALID_SLIDE
|
||||
|
||||
logger.info(core.misc.stringify_variables("Switching from slide %old% to %new%", { "old": old_slide, "new": new_slide }))
|
||||
|
@ -74,13 +79,16 @@ func switch_slide(new_slide: int) -> PresencodeTypes.PresencodeError:
|
|||
|
||||
# Call switch_slide()
|
||||
logger.verb("Switching slide")
|
||||
await entrypoint.switch_slide(new_slide)
|
||||
await entrypoint.switch_to_slide(new_slide)
|
||||
|
||||
# Play AFTER animation
|
||||
if manifest["animations"]:
|
||||
logger.verb("Starting AFTER animation")
|
||||
await entrypoint.play_animation(PresencodeTypes.AnimationStage.AFTER, old_slide, new_slide)
|
||||
|
||||
current_slide = new_slide
|
||||
slide_switch_in_progress = false
|
||||
|
||||
return PresencodeTypes.PresencodeError.OK
|
||||
|
||||
func remove_all_slides() -> void:
|
||||
|
|
|
@ -19,7 +19,8 @@ class_name PresencodeTypes
|
|||
|
||||
enum PresencodeError {
|
||||
OK,
|
||||
INVALID_SLIDE
|
||||
INVALID_SLIDE,
|
||||
ALREADY_RUNNING,
|
||||
}
|
||||
enum AnimationStage { BEFORE, AFTER }
|
||||
|
||||
|
@ -27,4 +28,5 @@ func presencodeerror_string(error: PresencodeError) -> String:
|
|||
match(error):
|
||||
PresencodeError.OK: return "OK"
|
||||
PresencodeError.INVALID_SLIDE: return "Invalid Slide"
|
||||
PresencodeError.ALREADY_RUNNING: return "Already running"
|
||||
_: return "<invalid enum value>"
|
||||
|
|
Loading…
Reference in a new issue