Compare commits

..

2 commits

4 changed files with 63 additions and 8 deletions

View file

@ -0,0 +1 @@
extends PresencodeEntrypoint

25
src/classes/entrypoint.gd Normal file
View file

@ -0,0 +1,25 @@
# 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 PresencodeEntrypoint
var core: Core
var logger: CoreLoggerInstance
# Required methods
func load_resources() -> void: core.logger.crash("PresencodeEntrypoint", "Method load_resources was not overriden")
func switch_to_slide(_slide: int) -> void: core.logger.crash("PresencodeEntrypoint", "Method switch_to_slide was not overriden")

View file

@ -81,10 +81,15 @@ func load_presentation(load_path: String) -> String:
var output_array: Array[String] = check_manifest()
if output_array != []: return core.misc.format_stringarray(output_array, "- ", "", "\n", "\n")
# Load and inject entrypoint
# Validate entrypoint
output = validate_entrypoint()
if output != "": return output
# Load entrypoint
output = load_entrypoint()
if output != "": return output
# Inject entrypoint
inject_entrypoint()
return ""
@ -174,13 +179,37 @@ func check_manifest() -> Array[String]:
return schema.evaluate()
func load_entrypoint() -> String:
logger.verb("Loading entrypoint")
func validate_entrypoint() -> String:
logger.verb("Validating entrypoint")
var content: String = ""
# Get entrypoint content
if is_file:
if !reader.file_exists("src/" + manifest["entrypoint"]):
return "Specified entrypoint file could not be located at src/" + manifest["entrypoint"]
content = reader.read_file("src/" + manifest["entrypoint"]).get_string_from_utf8()
else:
if !FileAccess.file_exists(path + "/src/" + manifest["entrypoint"]):
return "Specified entrypoint file could not be located at src/" + manifest["entrypoint"]
var file: FileAccess = FileAccess.open(path + "/src/" + manifest["entrypoint"], FileAccess.READ)
if file == null:
return core.misc.stringify_variables("Can't read entrypoint: %error_string% (%error%)", { "error": FileAccess.get_open_error(), "error_string": error_string(FileAccess.get_open_error()) })
content = file.get_as_text()
file.close()
# Validate entrypoint is extending PresencodeEntrypoint
if !content.contains("\nextends PresencodeEntrypoint\n") and !content.begins_with("extends PresencodeEntrypoint\n"):
return "The entrypoint script does not extend 'PresencodeEntrypoint'"
return ""
func load_entrypoint() -> String:
logger.verb("Loading entrypoint")
if is_file:
# Workaround (we can't load resources from buffer. why? idk)
# -> Remove temporary file (if exists)
if FileAccess.file_exists("user://entrypoint.gd"):
@ -194,9 +223,6 @@ func load_entrypoint() -> String:
# -> Load temporary file
entrypoint = ResourceLoader.load("user://entrypoint.gd")
else:
if !FileAccess.file_exists(path + "/src/" + manifest["entrypoint"]):
return "Specified entrypoint file could not be located at src/" + manifest["entrypoint"]
# Load entrypoint
entrypoint = ResourceLoader.load(path + "/src/" + manifest["entrypoint"])
@ -205,8 +231,8 @@ func load_entrypoint() -> String:
func inject_entrypoint() -> void:
logger.verb("Injecting entrypoint")
# Instantiate new Node
var entrypoint_node: Node = Node.new()
# Instantiate new PresencodeEntrypoint
var entrypoint_node: PresencodeEntrypoint = PresencodeEntrypoint.new()
# Give the new node a name and the entrypoint script
entrypoint_node.name = "Entrypoint"
entrypoint_node.set_script(entrypoint)

View file

@ -74,6 +74,9 @@ func _ready() -> void:
logger.info("User Interface is ready")
load_high_quality_wallpaper()
func load_high_quality_wallpaper() -> void:
# Load higher quality wallpaper in a thread.
# This has been done to decrease loading
# times and make the UX/DX much better.