Add PresencodeCommunication class
This commit is contained in:
parent
1371369213
commit
9a8c92a150
3 changed files with 81 additions and 3 deletions
65
src/classes/communication.gd
Normal file
65
src/classes/communication.gd
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# PRESENCODE SOURCE FILE
|
||||||
|
# Copyright (c) 2024 JeremyStarTM & Contributors
|
||||||
|
# Licensed under the GNU Affero General Public License v3
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
extends Node
|
||||||
|
class_name PresencodeCommunication
|
||||||
|
|
||||||
|
# CORE
|
||||||
|
var core: Core
|
||||||
|
@onready var logger: CoreLoggerInstance = core.logger.get_instance("src/classes/communication.gd")
|
||||||
|
|
||||||
|
# Presencode infrastructure
|
||||||
|
var presenloader: Node
|
||||||
|
|
||||||
|
# Presentation data
|
||||||
|
@onready var entrypoint: PresencodeEntrypoint = presenloader.entrypoint_node
|
||||||
|
@onready var manifest: Dictionary = presenloader.manifest
|
||||||
|
var current_slide: int = -1
|
||||||
|
|
||||||
|
func _init(core_new: Core, presenloader_new: Node) -> void:
|
||||||
|
core = core_new
|
||||||
|
presenloader = presenloader_new
|
||||||
|
|
||||||
|
func switch_slide(new_slide: int) -> PresencodeTypes.PresencodeError:
|
||||||
|
var old_slide: int = current_slide
|
||||||
|
|
||||||
|
if new_slide < 0:
|
||||||
|
logger.error(core.misc.stringify_variables("Invalid slide %slide%", { "slide": new_slide }))
|
||||||
|
return PresencodeTypes.PresencodeError.INVALID_SLIDE
|
||||||
|
if new_slide > manifest["slides"]:
|
||||||
|
logger.error(core.misc.stringify_variables("Invalid slide %slide%", { "slide": new_slide }))
|
||||||
|
return PresencodeTypes.PresencodeError.INVALID_SLIDE
|
||||||
|
|
||||||
|
logger.info(core.misc.stringify_variables("Switching from slide %old% to %new%", { "old": old_slide, "new": new_slide }))
|
||||||
|
|
||||||
|
# Play BEFORE animation
|
||||||
|
if manifest["animations"]:
|
||||||
|
logger.verb("Starting BEFORE animation")
|
||||||
|
await entrypoint.play_animation(PresencodeTypes.AnimationStage.BEFORE, old_slide, new_slide)
|
||||||
|
|
||||||
|
# Call switch_slide()
|
||||||
|
logger.verb("Switching slide")
|
||||||
|
await entrypoint.switch_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)
|
||||||
|
|
||||||
|
return PresencodeTypes.PresencodeError.OK
|
||||||
|
|
||||||
|
func get_source_path(path: String) -> String:
|
||||||
|
return "<presentation root>/" + path
|
|
@ -17,4 +17,14 @@
|
||||||
extends Node
|
extends Node
|
||||||
class_name PresencodeTypes
|
class_name PresencodeTypes
|
||||||
|
|
||||||
|
enum PresencodeError {
|
||||||
|
OK,
|
||||||
|
INVALID_SLIDE
|
||||||
|
}
|
||||||
enum AnimationStage { BEFORE, AFTER }
|
enum AnimationStage { BEFORE, AFTER }
|
||||||
|
|
||||||
|
func presencodeerror_string(error: PresencodeError) -> String:
|
||||||
|
match(error):
|
||||||
|
PresencodeError.OK: return "OK"
|
||||||
|
PresencodeError.INVALID_SLIDE: return "Invalid Slide"
|
||||||
|
_: return "<invalid enum value>"
|
||||||
|
|
|
@ -29,16 +29,19 @@ var path: String = ""
|
||||||
var is_file: bool = true
|
var is_file: bool = true
|
||||||
var manifest: Dictionary = {}
|
var manifest: Dictionary = {}
|
||||||
var entrypoint: Script = null
|
var entrypoint: Script = null
|
||||||
|
var entrypoint_node: PresencodeEntrypoint = null
|
||||||
|
|
||||||
# Access methods
|
# Access methods
|
||||||
var reader: ZIPReader = ZIPReader.new()
|
var reader: ZIPReader = ZIPReader.new()
|
||||||
var diraccess: DirAccess = null
|
var diraccess: DirAccess = null
|
||||||
|
|
||||||
|
# Communication
|
||||||
|
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
# Register cleanup hook
|
# Register cleanup hook
|
||||||
core.register_cleanup_hook(func() -> void: queue_free())
|
core.register_cleanup_hook(func() -> void: queue_free())
|
||||||
|
|
||||||
|
|
||||||
func load_presentation(load_path: String) -> String:
|
func load_presentation(load_path: String) -> String:
|
||||||
logger.info(core.misc.stringify_variables("Loading presentation located at %path%", { "path": load_path }))
|
logger.info(core.misc.stringify_variables("Loading presentation located at %path%", { "path": load_path }))
|
||||||
path = load_path
|
path = load_path
|
||||||
|
@ -231,13 +234,13 @@ func inject_entrypoint() -> void:
|
||||||
logger.verb("Injecting entrypoint")
|
logger.verb("Injecting entrypoint")
|
||||||
|
|
||||||
# Instantiate new PresencodeEntrypoint
|
# Instantiate new PresencodeEntrypoint
|
||||||
var entrypoint_node: PresencodeEntrypoint = PresencodeEntrypoint.new()
|
entrypoint_node = PresencodeEntrypoint.new()
|
||||||
entrypoint_node.name = "Entrypoint"
|
entrypoint_node.name = "Entrypoint"
|
||||||
entrypoint_node.set_script(entrypoint)
|
entrypoint_node.set_script(entrypoint)
|
||||||
|
|
||||||
# Update variables
|
# Update variables
|
||||||
entrypoint_node.core = core
|
entrypoint_node.core = core
|
||||||
entrypoint_node.logger = communication.get_source_path("src/" + manifest["entrypoint"])
|
entrypoint_node.logger = core.logger.get_instance(communication.get_source_path("src/" + manifest["entrypoint"]), entrypoint_node)
|
||||||
|
|
||||||
# Add to SceneTree
|
# Add to SceneTree
|
||||||
get_tree().root.add_child(entrypoint_node)
|
get_tree().root.add_child(entrypoint_node)
|
||||||
|
|
Loading…
Reference in a new issue