Compare commits
3 commits
b24d3935f8
...
dcb30cfac8
Author | SHA1 | Date | |
---|---|---|---|
dcb30cfac8 | |||
f90d854cea | |||
9b216c61ef |
5 changed files with 137 additions and 6 deletions
29
example/slides/slide_0.tscn
Normal file
29
example/slides/slide_0.tscn
Normal file
|
@ -0,0 +1,29 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://xmd7juxvox48"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bso65vpjqc4g4" path="res://addons/SUI/scenesrc/SuiText.tscn" id="1_6xtdi"]
|
||||
|
||||
[node name="Slide 0" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Text" parent="." instance=ExtResource("1_6xtdi")]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -340.0
|
||||
offset_top = -112.0
|
||||
offset_right = 340.0
|
||||
offset_bottom = 112.0
|
||||
text = "[b]Slide 0[/b]
|
||||
|
||||
|
||||
|
||||
|
||||
[right]Hello World![/right]"
|
29
example/slides/slide_1.tscn
Normal file
29
example/slides/slide_1.tscn
Normal file
|
@ -0,0 +1,29 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://kahpiyo87bjc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bso65vpjqc4g4" path="res://addons/SUI/scenesrc/SuiText.tscn" id="1_6wxt0"]
|
||||
|
||||
[node name="Slide 1" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Text" parent="." instance=ExtResource("1_6wxt0")]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -340.0
|
||||
offset_top = -112.0
|
||||
offset_right = 340.0
|
||||
offset_bottom = 112.0
|
||||
text = "[b]Slide 1[/b]
|
||||
|
||||
|
||||
|
||||
|
||||
[right]Hello Presencode![/right]"
|
|
@ -19,4 +19,4 @@ func switch_to_slide(new_slide: int) -> void:
|
|||
api.remove_all_slides()
|
||||
|
||||
# Add new slide
|
||||
sms.add_scene("slide", "slide_" + str(new_slide), CoreTypes.SceneType.MAIN)
|
||||
sms.add_scene("slide", resources["slide_" + str(new_slide)], CoreTypes.SceneType.MAIN)
|
||||
|
|
|
@ -19,21 +19,27 @@ class_name PresencodeCommunication
|
|||
|
||||
# CORE
|
||||
var core: Core
|
||||
@onready var logger: CoreLoggerInstance = core.logger.get_instance("src/classes/communication.gd")
|
||||
@onready var sms: CoreBaseModule = core.sms
|
||||
var logger: CoreLoggerInstance
|
||||
var sms: CoreBaseModule
|
||||
|
||||
# Presencode infrastructure
|
||||
var presenloader: Node
|
||||
|
||||
# Presentation data
|
||||
@onready var entrypoint: PresencodeEntrypoint = presenloader.entrypoint_node
|
||||
@onready var manifest: Dictionary = presenloader.manifest
|
||||
var entrypoint: PresencodeEntrypoint
|
||||
var manifest: Dictionary
|
||||
var current_slide: int = -1
|
||||
|
||||
# +++ initialization +++
|
||||
func _init(core_new: Core, presenloader_new: Node) -> void:
|
||||
core = core_new
|
||||
logger = core.logger.get_instance("src/classes/communication.gd", self)
|
||||
sms = core.sms
|
||||
|
||||
presenloader = presenloader_new
|
||||
|
||||
entrypoint = presenloader.entrypoint_node
|
||||
manifest = presenloader.manifest
|
||||
|
||||
# +++ slide management +++
|
||||
func switch_slide(new_slide: int) -> PresencodeTypes.PresencodeError:
|
||||
|
@ -70,6 +76,73 @@ func remove_all_slides() -> void:
|
|||
for scene in sms.get_scene_collection_list(CoreTypes.SceneType.MAIN):
|
||||
sms.remove_scene(scene.name)
|
||||
|
||||
# +++ resource loading +++
|
||||
func load_resources(list: Dictionary) -> Dictionary:
|
||||
logger.verb("Loading resources: " + str(list.keys()))
|
||||
|
||||
var output: Dictionary = {}
|
||||
|
||||
for resource in list:
|
||||
output.merge({ resource: await load_resource(list[resource]) })
|
||||
|
||||
return output
|
||||
|
||||
func load_resource(path: String):
|
||||
logger.diag("Loading resource located at " + path)
|
||||
|
||||
var load_path: String
|
||||
|
||||
if presenloader.is_file:
|
||||
# Check if file exists
|
||||
if !presenloader.reader.file_exists(path):
|
||||
await logger.crash(core.misc.stringify_variables("File path %path% could not be located inside presentation archive", { "path": path }))
|
||||
|
||||
# Write into temporary file
|
||||
presenloader.write_temporary_file(presenloader.reader.read_file(path))
|
||||
|
||||
# Update 'load_path'
|
||||
load_path = presenloader.temporary_file
|
||||
else:
|
||||
# Check if file exists
|
||||
if !FileAccess.file_exists(presenloader.path + "/" + path):
|
||||
await logger.crash(core.misc.stringify_variables("File path %path% could not be located inside presentation directory (full path is %path_full%)", { "path": path, "path_full": presenloader.path + "/" + path }))
|
||||
|
||||
# Update 'load_path'
|
||||
load_path = presenloader.path + "/" + path
|
||||
|
||||
# Load resource from temporary file
|
||||
var resource = _load_resource_format_loader(load_path, path)
|
||||
|
||||
# Check if loading failed
|
||||
if resource == null:
|
||||
await logger.crash("Resource could not be read")
|
||||
|
||||
# Return resource
|
||||
return resource
|
||||
|
||||
func _load_resource_format_loader(load_path: String, path: String):
|
||||
var resource = null
|
||||
|
||||
if path.ends_with(".tscn"):
|
||||
logger.diag("Using format loader for PackedScene")
|
||||
resource = ResourceLoader.load(load_path)
|
||||
|
||||
# Try to instantiate
|
||||
if resource.can_instantiate(): resource = resource.instantiate()
|
||||
else: resource = Control.new() # does not cause runtime errors
|
||||
elif path.ends_with(".ttf") or path.ends_with(".otf") or path.ends_with(".woff") or path.ends_with(".woff2"):
|
||||
logger.diag("Using format loader for FontFile")
|
||||
resource = FontFile.new()
|
||||
resource.load_dynamic_font(load_path)
|
||||
elif path.ends_with(".png") or path.ends_with(".jpg") or path.ends_with(".svg") or path.ends_with(".ktx") or path.ends_with(".tga") or path.ends_with(".webp"):
|
||||
logger.diag("Using format loader for Image")
|
||||
resource = Image.load_from_file(load_path)
|
||||
else:
|
||||
logger.diag("Using generic format loader")
|
||||
resource = ResourceLoader.load(load_path)
|
||||
|
||||
return resource
|
||||
|
||||
# +++ etc +++
|
||||
func get_source_path(path: String) -> String:
|
||||
return "<presentation root>/" + path
|
||||
|
|
|
@ -29,7 +29,7 @@ var manifest: Dictionary = {}
|
|||
|
||||
var entrypoint: Script = null
|
||||
var entrypoint_node: PresencodeEntrypoint = null
|
||||
var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
|
||||
@onready var communication: PresencodeCommunication = PresencodeCommunication.new(core, self)
|
||||
|
||||
var reader: ZIPReader = ZIPReader.new()
|
||||
var diraccess: DirAccess = null
|
||||
|
|
Loading…
Reference in a new issue