diff --git a/assets/images/Icon.png.import b/assets/images/Icon.png.import deleted file mode 100644 index 1704d06..0000000 --- a/assets/images/Icon.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://bqf0yuaaxgrdr" -path="res://.godot/imported/Icon.png-93ca016a3d581ee8be85859272221470.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/images/Icon.png" -dest_files=["res://.godot/imported/Icon.png-93ca016a3d581ee8be85859272221470.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/assets/images/IconRound.png.import b/assets/images/IconRound.png.import deleted file mode 100644 index 889894d..0000000 --- a/assets/images/IconRound.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://btrjvej7kesqp" -path="res://.godot/imported/IconRound.png-1afd952ea59d10fc5e3b0a78c073f524.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://docs/static/assets/images/IconRound.png" -dest_files=["res://.godot/imported/IconRound.png-1afd952ea59d10fc5e3b0a78c073f524.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/assets/images/IconText.png.import b/assets/images/IconText.png.import deleted file mode 100644 index 5685018..0000000 --- a/assets/images/IconText.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://cvhgvybvn011m" -path="res://.godot/imported/IconText.png-ba84e8aaca79c24529b5915da9118cd4.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/images/IconText.png" -dest_files=["res://.godot/imported/IconText.png-ba84e8aaca79c24529b5915da9118cd4.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/assets/images/web/IconRound_192x192.png.import b/assets/images/web/IconRound_192x192.png.import deleted file mode 100644 index ad084cd..0000000 --- a/assets/images/web/IconRound_192x192.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dt4kldhfyob1h" -path="res://.godot/imported/IconRound_192x192.png-35fb3db21886e26e465df99404de1b9b.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/images/web/IconRound_192x192.png" -dest_files=["res://.godot/imported/IconRound_192x192.png-35fb3db21886e26e465df99404de1b9b.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/assets/images/web/IconRound_512x512.png.import b/assets/images/web/IconRound_512x512.png.import deleted file mode 100644 index 37d6d2f..0000000 --- a/assets/images/web/IconRound_512x512.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dgeydjomrd7nt" -path="res://.godot/imported/IconRound_512x512.png-5a9260cdeed5622a5196eddf4da6277a.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://assets/images/web/IconRound_512x512.png" -dest_files=["res://.godot/imported/IconRound_512x512.png-5a9260cdeed5622a5196eddf4da6277a.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/docs/docs/reference/api/preader.md b/docs/docs/reference/api/preader.md index 7c00437..9d2c330 100644 --- a/docs/docs/reference/api/preader.md +++ b/docs/docs/reference/api/preader.md @@ -14,6 +14,23 @@ Reads Presencode presentation archives and directories. - type `string` - mandatory `yes` - description `The path to a file` +### `read_resource` +- return type `Resource` +- description `Reads a resource from the presentation archive/directory. Returns an empty Resource if the file could not be read.` +- arguments + - `path` + - type `string` + - mandatory `yes` + - description `The path to a resource` +### `read_resource_unsafe` +- return type `Resource` +- description `Reads a resource from the presentation archive/directory. Returns an empty Resource if the file could not be read.` +- warning `Loads resources directly, which can lead to missing resources when the presentation is loaded from an archive.` +- arguments + - `path` + - type `string` + - mandatory `yes` + - description `The path to a resource` ### `get_topic` - return type `String` - description `Get the presentation topic` diff --git a/example/images/foxxo.jpg.import b/example/images/foxxo.jpg.import deleted file mode 100644 index b24e545..0000000 --- a/example/images/foxxo.jpg.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dp6kkiretv01v" -path="res://.godot/imported/foxxo.jpg-ef4c7ba004a3455efe7e3e1605964ac9.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://example/images/foxxo.jpg" -dest_files=["res://.godot/imported/foxxo.jpg-ef4c7ba004a3455efe7e3e1605964ac9.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/example/images/mario.gif.import b/example/images/mario.gif.import deleted file mode 100644 index e4c6f13..0000000 --- a/example/images/mario.gif.import +++ /dev/null @@ -1,15 +0,0 @@ -[remap] - -importer="import_gif_to_sprite_frames" -type="SpriteFrames" -uid="uid://bghv86mpnhh6" -path="res://.godot/imported/mario.gif-f119460dcfd983f3b74edf3b7b56592c.tres" - -[deps] - -source_file="res://example/images/mario.gif" -dest_files=["res://.godot/imported/mario.gif-f119460dcfd983f3b74edf3b7b56592c.tres"] - -[params] - -frames_per_second=30 diff --git a/example/images/meme.jpg.import b/example/images/meme.jpg.import deleted file mode 100644 index 35daa62..0000000 --- a/example/images/meme.jpg.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://jwvaqrhaf1t" -path="res://.godot/imported/meme.jpg-9a7233508d56192f29bdb233352ed64b.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://example/images/meme.jpg" -dest_files=["res://.godot/imported/meme.jpg-9a7233508d56192f29bdb233352ed64b.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/src/preader.gd b/src/preader.gd index 3a1ebff..d09de60 100644 --- a/src/preader.gd +++ b/src/preader.gd @@ -104,6 +104,43 @@ func read_file(path: String) -> PackedByteArray: # Read a resource from the presentation archive/directory func read_resource(path: String) -> Resource: + if !is_open: + logger.warn("No presentation is currently opened") + return null + if directorypath == "": + var resource_bytes: PackedByteArray = read_file(path) + if resource_bytes.size() == 0: + logger.warn("Resource could not be read") + return null + var split_path: Array = path.split("/") + var file = FileAccess.open(misc.get_temporary_dir() + "/" + str(split_path[split_path.size()-1]), FileAccess.WRITE) + if file == null: + logger.warn("Resource could not be read, FileAccess[1] failed: " + str(FileAccess.get_open_error())) + return null + file.store_buffer(resource_bytes) + file.close() + var resource: Resource = null + if path.ends_with(".ttf") or path.ends_with(".otf") or path.ends_with(".woff") or path.ends_with(".woff2"): + resource = FontFile.new() + resource.load_dynamic_font(misc.get_temporary_dir() + "/" + str(split_path[split_path.size()-1])) + else: + resource = ResourceLoader.load(misc.get_temporary_dir() + "/" + str(split_path[split_path.size()-1])) + if resource == null: + logger.warn("Resource could not be read, resource is null") + return null + return resource + else: + if !FileAccess.file_exists(directorypath + "/" + path): + logger.error("Requested resource is missing in presentation directory") + return null + var resource: Resource = ResourceLoader.load(directorypath + "/" + path) + if resource == null: + logger.warn("Resource could not be read, resource is null") + return null + return resource + +# Read a resource from the presentation archive/directory (unsafe) +func read_resource_unsafe(path: String) -> Resource: if !is_open: logger.warn("No presentation is currently opened") return null