Skip to content

Tiles can be mirrored and turned: X, Y, Z in the map editor (runtime 20261130.5) - #107

Open
Xehanort88 wants to merge 3 commits into
Psychronic-Games:mainfrom
Xehanort88:pr/tile-flips
Open

Xehanort88 wants to merge 3 commits into
Psychronic-Games:mainfrom
Xehanort88:pr/tile-flips

Conversation

@Xehanort88

Copy link
Copy Markdown
Contributor

Stacked on #106 (map editor keyboard shortcuts), whose single commit is on this branch too. This pull request adds two commits of its own. After #106 merges, only those two will show.

The problem

There is no way to draw a tile mirrored or turned. A wall corner, a cliff edge or an arrow that is needed facing four ways has to be drawn four times in the tileset, which fills up the B–E sheets with near-duplicates. Tiled and most modern tile editors let you mirror or turn a tile as you place it.

What changed

A map cell can now show its tile mirrored or turned a quarter, so one drawing can be used in all eight orientations.

Storage

  • Each orientation is stored as three bits, the same three Tiled uses: 1 mirrors left to right, 2 mirrors top to bottom, 4 swaps rows and columns (applied first).
  • They are kept in a new optional map field, rrTileFlips, keyed by "x,y,z" (z = layer). Only cells that are actually turned get an entry.
  • Tile ids are left alone, so plugins, older editors and older runtimes read a map exactly as before; they just draw the tile unturned.
  • Only ordinary tiles (B–E and A5, ids below 2048) can be turned. An autotile's piece is chosen from its neighbours, so turning it would not mean anything.

Editor (flat view)

  • Keys: X and Y mirror the tile you are about to paint; Z turns it a quarter clockwise, Shift+Z counter-clockwise.
    • A single palette tile turns in place.
    • A block of palette tiles is also laid out turned by the pencil.
    • A copied area turns as one picture, shadows and regions included.
  • Keeping orientations right: after every paint step, MapEditor.reconcileFlips compares the stroke's before and after.
    • A tile the brush painted takes the brush's orientation.
    • A tile pushed to another layer keeps its own.
    • A replaced or erased tile loses it.
  • Carried through: undo, redo, resize and save all keep the orientations.
  • Drawn turned: both tile renderers, the hover preview, the stamp preview, Save Map As Image and the passage overlay.
  • Shared maths: editor/src/utils/TileTransforms.js (RRTileTransforms) holds the orientation maths.

Runtime, 2D (revision 20261130.4, then 20261130.5)

  • Drawing:
    • Tilemap.setTileFlips hands the table to the tilemap.
    • All three tile paths draw turned tiles: the chunked mesh (the default), the layer mesh and the sprite fallback.
    • The chunked mesh carries the orientation above the water bits in rect slot 7.
  • Passage: a turned tile's four directional passage bits turn with its picture.

Second commit: keeping it working when plugins wrap these methods

I tested this in a real game with 133 plugins and found that VisuMZ_0_CoreEngine breaks a straightforward version in two ways:

  • Its Tilemap._addSpotTile wrapper passes on only three arguments, so an orientation passed as a fourth argument never arrived.
  • It replaces Game_Map.checkPassage without calling the original.

So the second commit puts things back to stock and works around both:

  • _addSpotTile, _addTile and checkPassage are the stock methods again.
  • _addSpot sets this._rrSpotFlip before each tile, and _addNormalTile reads it.
  • Game_Map.installTurnedTileShim() wraps whichever checkPassage is live once all plugins have loaded. It runs from Scene_Boot.start and from the two boot paths that skip it.
    • On a cell with a turned tile, it gives that check tileset flags whose passage bits are turned.
    • Everywhere else, the check runs unchanged.

Verification

  • Tests:
    • editor/tests/tile-flips.test.cjs covers the orientation maths, layout, stamps and the reconcile rules, plus undo, resize and save.
    • It also checks the runtime: all three tile paths, passage, and that the runtime's copy of the tables matches the editor's.
    • It includes a stand-in for a plugin that forwards three arguments and replaces checkPassage.
    • tilemap-chunk-paint.test.cjs passes unchanged.
    • On this branch, the touched and related test files give 227 tests, none failing.
  • Editor: driven over CDP. Mirrored and turned tiles were compared pixel for pixel against the expected picture, in both editor renderers.
  • Real game (133 plugins, CoreEngine among them):
    • Every _addSpotTile call went through CoreEngine's three-argument wrapper.
    • The turned tiles reached the tile layers with their orientations.
    • Passage turned with the tile: a wall that blocks on the left blocks on the right once mirrored.

Limits

  • 3D: the 3D view and 3D maps still draw these tiles unturned.
  • Patterns: the rectangle, circle and fill tools turn each tile of a multi-tile pattern in place; they do not rearrange the pattern itself.
  • Speed: CoreEngine's wrapper already makes games fall back from chunked painting ($reactorTilemapStats.chunkFallback); this is not new here. I measured it with ReactorProfiler while scrolling a 100×55 map. Average frame work was 0.51 ms with full repaints, 0.50 ms with chunked painting allowed, and 0.48 ms with full repaints again. The difference is noise, so this pull request leaves that alone.

🤖 Generated with Claude Code

Xehanort88 and others added 3 commits November 30, 2026 18:58
On the flat map, with no dialog up and no text field in use:

- B, R, C, F pick the pencil, rectangle, circle and fill; E and S toggle
  the eraser and the shadow pen. Each button's tooltip ends with its key.
- Ctrl with +, - and 0 zooms in, out and to 100%; Ctrl+/ fits the map in
  the panel. Zoom is about the middle of the panel and uses the wheel's
  own steps and limits.
- The arrow keys scroll by one tile (Event mode keeps them for its cursor).
- Space held over the map turns a left drag into a pan, beside the middle
  button and Shift+drag. The painter stands down for that drag.

The key table is utils/MapShortcuts.js. The 3D view keeps its fly keys,
and the sidebar lists and open dropdowns keep their letters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…20261130.4)

A map cell can show its tile mirrored or turned a quarter, so one drawing
in a sheet serves for its eight orientations.

The orientation is three bits per tile, the three Tiled uses (1 mirrored
left to right, 2 top to bottom, 4 transposed), kept beside the tile ids in
a new map field: rrTileFlips maps "x,y,z" to the bits of layer z of that
cell, and only turned cells have an entry. Tile ids are untouched, so
plugins and older editors read the map as before. Only ordinary tiles turn
(B to G and A5); an autotile's piece is chosen by its neighbours.

Editor (flat view):
- X and Y mirror what is in hand, Z turns it a quarter clockwise, Shift+Z
  back. A palette tile turns in place; a block of palette tiles is also
  laid out turned by the pencil; a copied area turns as one picture, its
  shadows and regions with it.
- The table is settled after every paint step from the stroke's own
  before and after (MapEditor.reconcileFlips): the brush's tile takes the
  brush's orientation, a tile pushed to another layer keeps its own, a
  replaced or erased one loses it. Undo, redo, resize and save carry it.
- Both tile renderers, the hover preview, the stamp preview, Save Map As
  Image and the passage overlay draw turned tiles.

Runtime (2D): Tilemap.setTileFlips; the chunked mesh, the layer mesh and
the sprite fallback draw turned tiles; Game_Map.checkPassage turns a
tile's directional passage with its picture.

Not in this change: the 3D view and 3D maps draw these tiles unturned, and
the rectangle, circle and fill tools turn each tile of a multi-tile
pattern in place without rearranging the pattern.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…time 20261130.5)

VisuMZ_0_CoreEngine, enabled in most VisuStella games, broke both halves of
turned tiles in a real game:

- its Tilemap._addSpotTile wrapper passes on three arguments, so the
  orientation, passed as a fourth, never reached _addNormalTile: turned
  tiles on layers 1 and 2 (and 3 and 4 off overpasses) drew unturned;
- it replaces Game_Map.checkPassage without calling the original, so a
  turned wall blocked on its unturned side.

The orientation now rides on the tilemap instead: _addSpot sets
_rrSpotFlip before each tile and clears it after the cell, _addNormalTile
reads it, and _addSpotTile and _addTile are the stock methods again.
Passage is a shim installed in Scene_Boot.start (and the two boot paths
that skip it), over whichever checkPassage is live by then: on a cell with
a turned tile it hands that check tileset flags in which the tile's four
passage bits are turned; elsewhere the check runs as it was. The stock
checkPassage is back to what it was before turned tiles.

Checked in the user's game (133 plugins, CoreEngine among them): every
_addSpotTile call went through CoreEngine's three-argument wrapper and the
three turned tiles reached the layers with their orientations; passage
answered by CoreEngine's check turned with the tile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant