Skip to content

Commit

Permalink
Update Godot 4 exporter to use the new tile rotation/flipping system …
Browse files Browse the repository at this point in the history
…in Godot 4.2 (#3895)

Closes #3865
  • Loading branch information
Skrapion committed Feb 28, 2024
1 parent c691061 commit 77611b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Scripting: Restored compatibility for MapObject.polygon (#3845)
* JSON format: Fixed tile order when loading a tileset using the old format
* Godot export: Added support for exporting objects (by Rick Yorgason, #3615)
* Godot export: Use Godot 4.2 tile transformation flags (by Rick Yorgason, #3895)
* Godot export: Fixed positioning of tile collision shapes (by Ryan Petrie, #3862)
* tmxrasterizer: Added --hide-object and --show-object arguments (by Lars Luz, #3819)
* tmxrasterizer: Added --frames and --frame-duration arguments to export animated maps as multiple images (#3868)
Expand Down
8 changes: 5 additions & 3 deletions docs/manual/export-tscn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ Tilesets support the following property:

* bool ``exportAlternates`` (default: false)

The ``exportAlternates`` property is necessary when using flipped or rotated
tiles. This will create 7 alternate tiles for each tile, allowing all flipped
and rotation combinations.
**Deprecated:** The ``exportAlternates`` property is necessary when using
flipped or rotated tiles in Godot 4.0 and 4.1. This will create 7 alternate
tiles for each tile, allowing all flipped and rotation combinations. This
has been deprecated in Tiled 1.10.3 in favour of Godot 4.2's native rotation
and flipping support.

Tile Properties
~~~~~~~~~~~~~~~
Expand Down
14 changes: 8 additions & 6 deletions src/plugins/tscn/tscnplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ static AssetInfo collectAssets(const Map *map)
}

enum FlippedState {
// exportAlternate Deprecation Note: Change to 1<<12, 1<<13, 1<<14 when exportAlternates is removed
FlippedH = 1,
FlippedV = 2,
Transposed = 4
Expand Down Expand Up @@ -676,8 +677,10 @@ static void writeTileset(const Map *map, QFileDevice *device, bool isExternal, A
device->write(formatByteString("texture_region_size = Vector2i(%1, %2)\n",
tileset.tileWidth(), tileset.tileHeight()));

// exportAlternate Deprecation Note: Remove this block
bool hasAlternates = tileset.resolvedProperty("exportAlternates").toBool();

if (hasAlternates)
Tiled::WARNING(TscnPlugin::tr("exportAlternates is deprecated. Godot 4.2 supports native tile rotation. Tileset: %1").arg(tileset.name()));
unsigned maxAlternate = hasAlternates ? FlippedH | FlippedV | Transposed : 0;

// Tile info
Expand Down Expand Up @@ -731,6 +734,7 @@ static void writeTileset(const Map *map, QFileDevice *device, bool isExternal, A
}

// If we're using alternate tiles, give a hint for the next alt ID
// exportAlternate Deprecation Note: Remove the entire if and for blocks following
if (hasAlternates) {
device->write(formatByteString("%1:%2/next_alternative_id = 8\n",
x, y));
Expand Down Expand Up @@ -936,7 +940,7 @@ bool TscnPlugin::write(const Map *map, const QString &fileName, Options options)
// Where:
// DestLocation = (DestX >= 0 ? DestY : DestY + 1) * 65536 + DestX
// SrcX = SrcX * 65536 + TileSetId
// SrcY = SrcY + 65536 * AlternateId
// SrcY = SrcY + 65536 * (AlternateId | FLIP_H | FLIP_V | TRANSPOSE)
int layerIndex = 0;
for (const auto layer : std::as_const(assetInfo.layers)) {
device->write(formatByteString("layer_%1/name = \"%2\"\n",
Expand Down Expand Up @@ -986,11 +990,9 @@ bool TscnPlugin::write(const Map *map, const QString &fileName, Options options)
alt |= FlippedV;
if (cell.flippedAntiDiagonally())
alt |= Transposed;
// exportAlternate Deprecation Note: Remove this if block
if (alt && !cell.tileset()->resolvedProperty("exportAlternates").toBool()) {
Tiled::ERROR(TscnPlugin::tr("Map uses flipped/rotated tiles. The tileset must have "
"the custom exportAlternates property enabled to export this map."),
Tiled::JumpToTile { map, QPoint(x, y), layer });
alt = 0;
alt <<= 12;
}

int destLocation = (x >= 0 ? y : y + 1) * 65536 + x;
Expand Down

0 comments on commit 77611b6

Please sign in to comment.