diff --git a/src/classes/communication.gd b/src/classes/communication.gd
new file mode 100644
index 0000000..819054e
--- /dev/null
+++ b/src/classes/communication.gd
@@ -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 .
+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 "/" + path
diff --git a/src/classes/types.gd b/src/classes/types.gd
index a14265c..172546b 100644
--- a/src/classes/types.gd
+++ b/src/classes/types.gd
@@ -17,4 +17,14 @@
extends Node
class_name PresencodeTypes
+enum PresencodeError {
+ OK,
+ INVALID_SLIDE
+}
enum AnimationStage { BEFORE, AFTER }
+
+func presencodeerror_string(error: PresencodeError) -> String:
+ match(error):
+ PresencodeError.OK: return "OK"
+ PresencodeError.INVALID_SLIDE: return "Invalid Slide"
+ _: return ""
diff --git a/src/presenloader.gd b/src/presenloader.gd
index 6da1ec7..406034e 100644
--- a/src/presenloader.gd
+++ b/src/presenloader.gd
@@ -29,15 +29,18 @@ var path: String = ""
var is_file: bool = true
var manifest: Dictionary = {}
var entrypoint: Script = null
+var entrypoint_node: PresencodeEntrypoint = null
# Access methods
var reader: ZIPReader = ZIPReader.new()
var diraccess: DirAccess = null
+# Communication
+var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
+
func _ready() -> void:
# Register cleanup hook
core.register_cleanup_hook(func() -> void: queue_free())
-
func load_presentation(load_path: String) -> String:
logger.info(core.misc.stringify_variables("Loading presentation located at %path%", { "path": load_path }))
@@ -231,13 +234,13 @@ func inject_entrypoint() -> void:
logger.verb("Injecting entrypoint")
# Instantiate new PresencodeEntrypoint
- var entrypoint_node: PresencodeEntrypoint = PresencodeEntrypoint.new()
+ entrypoint_node = PresencodeEntrypoint.new()
entrypoint_node.name = "Entrypoint"
entrypoint_node.set_script(entrypoint)
# Update variables
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
get_tree().root.add_child(entrypoint_node)