Skip to content

Commit

Permalink
Don't throw if tileset images can't be copied
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 7, 2024
1 parent 10291d5 commit bfa1323
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions source/godot_tscn_format/lib/src/gd3_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,40 +482,54 @@ 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<void>
{
for (const auto& tile_atlas : tileset.atlases) {
const auto dest = options.base_dir / tile_atlas.image_path.filename(); // FIXME

log(LogLevel::kDebug,
"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<void>
auto save_godot3_scene(const Gd3Map& map,
const SaveFormatWriteOptions& options) -> Result<void>
{
// 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

0 comments on commit bfa1323

Please sign in to comment.