diff --git a/source/godot_tscn_format/lib/src/gd3_exporter.cpp b/source/godot_tscn_format/lib/src/gd3_exporter.cpp index 21af9aa9de..05284146a7 100644 --- a/source/godot_tscn_format/lib/src/gd3_exporter.cpp +++ b/source/godot_tscn_format/lib/src/gd3_exporter.cpp @@ -482,6 +482,23 @@ auto _emit_tileset_file(const Gd3Tileset& tileset, _emit_resources(writer, tileset.resources); + writer.newline().resource_header(); + + std::size_t tileset_index = 0; + for (const auto& tile_atlas : tileset.atlases) { + _emit_tile_atlas(writer, tile_atlas, tileset_index); + ++tileset_index; + } + + writer.set_key_prefix(""); + + return kOK; +} + +[[nodiscard]] +auto _save_tileset_images(const Gd3Tileset& tileset, + const SaveFormatWriteOptions& options) -> Result +{ for (const auto& tile_atlas : tileset.atlases) { const auto dest = options.base_dir / tile_atlas.image_path.filename(); // FIXME @@ -489,33 +506,30 @@ auto _emit_tileset_file(const Gd3Tileset& tileset, "Copying texture '{}' to '{}'", tile_atlas.image_path.filename().string(), dest.string()); + + std::error_code copy_error {}; std::filesystem::copy(tile_atlas.image_path, dest, - std::filesystem::copy_options::overwrite_existing); - } + std::filesystem::copy_options::overwrite_existing, + copy_error); - writer.newline().resource_header(); - - std::size_t tileset_index = 0; - for (const auto& tile_atlas : tileset.atlases) { - _emit_tile_atlas(writer, tile_atlas, tileset_index); - ++tileset_index; + if (copy_error) { + return std::unexpected {copy_error}; + } } - writer.set_key_prefix(""); - return kOK; } } // namespace -auto save_godot3_scene(const Gd3Map& map, const SaveFormatWriteOptions& options) - -> Result +auto save_godot3_scene(const Gd3Map& map, + const SaveFormatWriteOptions& options) -> Result { // TODO put tileset in map as subresource - return _emit_tileset_file(map.tileset, options).and_then([&]() { - return _emit_map_file(map, options); - }); + return _save_tileset_images(map.tileset, options) + .and_then([&] { return _emit_tileset_file(map.tileset, options); }) + .and_then([&] { return _emit_map_file(map, options); }); } } // namespace tactile::godot