From 836a45b200999f21b1ea3da3f3e0536cd114efad Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Sun, 17 Nov 2024 01:34:52 +0100 Subject: [PATCH] Use base directory for image tileset path --- .../tiled_tmj/lib/src/tmj_format_parser.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/plugins/tiled_tmj/lib/src/tmj_format_parser.cpp b/source/plugins/tiled_tmj/lib/src/tmj_format_parser.cpp index 7b666c28f..312ad3b7c 100644 --- a/source/plugins/tiled_tmj/lib/src/tmj_format_parser.cpp +++ b/source/plugins/tiled_tmj/lib/src/tmj_format_parser.cpp @@ -175,8 +175,9 @@ auto _read_tileset_tiles(const JSON& tileset_json, ir::Tileset& tileset) } [[nodiscard]] -auto _read_common_tileset_attributes(const JSON& tileset_json, ir::Tileset& tileset) - -> std::expected +auto _read_common_tileset_attributes(const JSON& tileset_json, + const SaveFormatReadOptions& options, + ir::Tileset& tileset) -> std::expected { return _read_metadata(tileset_json, tileset.meta) .and_then([&] { return read_attr_to(tileset_json, "name", tileset.meta.name); }) @@ -190,25 +191,27 @@ auto _read_common_tileset_attributes(const JSON& tileset_json, ir::Tileset& tile [&] { return read_attr_to(tileset_json, "imageheight", tileset.image_size[1]); }) .and_then([&] { return read_attr(tileset_json, "image"); }) .and_then([&](const std::string& image_path) { - tileset.image_path = image_path; + tileset.image_path = options.base_dir / image_path; return std::expected {}; }) .and_then([&] { return _read_tileset_tiles(tileset_json, tileset); }); } [[nodiscard]] -auto _read_embedded_tileset(const JSON& tileset_json) -> std::expected +auto _read_embedded_tileset(const JSON& tileset_json, const SaveFormatReadOptions& options) + -> std::expected { ir::Tileset tileset {}; tileset.is_embedded = true; - return _read_common_tileset_attributes(tileset_json, tileset).transform([&] { + return _read_common_tileset_attributes(tileset_json, options, tileset).transform([&] { return std::move(tileset); }); } [[nodiscard]] -auto _read_external_tileset(const std::filesystem::path& path) +auto _read_external_tileset(const std::filesystem::path& path, + const SaveFormatReadOptions& options) -> std::expected { ir::Tileset tileset {}; @@ -216,7 +219,7 @@ auto _read_external_tileset(const std::filesystem::path& path) return read_json_document(path) .and_then([&](const JSON& tileset_json) { - return _read_common_tileset_attributes(tileset_json, tileset); + return _read_common_tileset_attributes(tileset_json, options, tileset); }) .transform([&] { return std::move(tileset); }); } @@ -229,8 +232,8 @@ auto _read_tileset_ref(const JSON& tileset_ref_json, const SaveFormatReadOptions return read_attr_to(tileset_ref_json, "firstgid", tileset_ref.first_tile_id) .and_then([&] { const auto source = read_attr(tileset_ref_json, "source"); - return source.has_value() ? _read_external_tileset(options.base_dir / *source) - : _read_embedded_tileset(tileset_ref_json); + return source.has_value() ? _read_external_tileset(options.base_dir / *source, options) + : _read_embedded_tileset(tileset_ref_json, options); }) .transform([&](ir::Tileset&& tileset) { tileset_ref.tileset = std::move(tileset);