Skip to content

Commit

Permalink
Fix tileset generation
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 7, 2024
1 parent a8225c0 commit 97a48f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ struct Gd3Map final
{
Gd3Metadata meta;
Gd3Resources resources;
ExtResourceId tileset_id;
Int2 tile_size;
Gd3Tileset tileset;
std::vector<Gd3Layer> layers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ auto Gd3DocumentConverter::visit(const IMapView& map) -> std::expected<void, std
m_map.sprite_frames.id = m_map.resources.next_sub_resource_id++;

m_map.tile_size = map.get_tile_size();
m_map.tileset_id = m_map.resources.next_ext_resource_id++;
m_map.meta = _convert_meta(map.get_meta());

return {};
Expand Down
20 changes: 10 additions & 10 deletions source/godot_tscn_format/lib/src/gd3_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ void _emit_tile_layer_animation_nodes(Gd3SceneWriter& writer,

void _emit_tile_layer(Gd3SceneWriter& writer,
const Gd3Layer& layer,
const ExtResourceId tileset_id,
const SubResourceId tileset_id,
const SubResourceId sprite_frames_id)
{
const auto& tile_layer = std::get<Gd3TileLayer>(layer.value);

writer.newline()
.node_header(layer.name, "TileMap", layer.parent)
.ext_resource_variable("tile_set", tileset_id)
.sub_resource_variable("tile_set", tileset_id)
.variable("visible", layer.visible)
.vector2_variable("cell_size", tile_layer.cell_size)
.color_variable("modulate", FColor {1, 1, 1, layer.opacity})
Expand Down Expand Up @@ -367,12 +367,12 @@ void _emit_object_layer(Gd3SceneWriter& writer, const Gd3Layer& layer)

void _emit_layer(Gd3SceneWriter& writer,
const Gd3Layer& layer,
ExtResourceId tileset_id,
SubResourceId tileset_id,
SubResourceId sprite_frames_id);

void _emit_group_layer(Gd3SceneWriter& writer,
const Gd3Layer& layer,
const ExtResourceId tileset_id,
const SubResourceId tileset_id,
const SubResourceId sprite_frames_id)
{
const auto& group_layer = std::get<Gd3GroupLayer>(layer.value);
Expand All @@ -391,7 +391,7 @@ void _emit_group_layer(Gd3SceneWriter& writer,

void _emit_layer(Gd3SceneWriter& writer,
const Gd3Layer& layer,
const ExtResourceId tileset_id,
const SubResourceId tileset_id,
const SubResourceId sprite_frames_id)
{
switch (layer.value.index()) {
Expand Down Expand Up @@ -467,15 +467,15 @@ auto _emit_map_file(const Gd3Map& map, const SaveFormatWriteOptions& options) ->
_emit_metadata(writer, map.meta);

for (const auto& layer : map.layers) {
_emit_layer(writer, layer, map.tileset_id, map.sprite_frames.id);
_emit_layer(writer, layer, map.tileset.id, map.sprite_frames.id);
}

return kOK;
}

[[nodiscard]]
auto _save_tileset_images(const Gd3Tileset& tileset,
const SaveFormatWriteOptions& options) -> Result<void>
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
Expand All @@ -501,8 +501,8 @@ auto _save_tileset_images(const Gd3Tileset& tileset,

} // 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>
{
return _save_tileset_images(map.tileset, options).and_then([&] {
return _emit_map_file(map, options);
Expand Down

0 comments on commit 97a48f4

Please sign in to comment.