Tilemap cells are stored compactly in the project file: each layer keeps a tile list, an origin and one run-length encoded string per row; older projects with a cell map still load (#134)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
732f6518ae
commit
10b49fac46
6 files changed
+319
-4
No files matched your search
@@ -66,6 +66,7 @@ async function cellShows(t, x, y, quadrants) {
|
||||
|
||||
export async function tilemap(t) {
|
||||
const { check, json, evaluate, mutate, click, clickText, drag, press, shot, settle, undo, select } = t;
|
||||
const { saved, api, navigate, projectId } = t;
|
||||
|
||||
await press('Escape');
|
||||
await evaluate('__gm.state.select(null)');
|
||||
@@ -292,6 +293,33 @@ export async function tilemap(t) {
|
||||
const o = __gm.state.activeScene.objects.find((o) => o.id === ${JSON.stringify(MAP_OBJECT)});
|
||||
o.position = { x: 0, y: ${LANE}, z: 0 };`);
|
||||
|
||||
// 40k. The file holds the cells compactly (#134): per layer the tiles once and a string of runs
|
||||
// per row, no key per cell. A reload reads them back into exactly the same cells.
|
||||
const inMemory = await json(
|
||||
`__gm.state.project.assets.find((a) => a.id === ${JSON.stringify(made.id)}).layers.map((l) => l.cells)`,
|
||||
);
|
||||
await saved();
|
||||
const storedMap = (await api(`projects/${projectId}`)).project.assets.find((a) => a.id === made.id);
|
||||
const storedLayers = storedMap?.layers ?? [];
|
||||
check(
|
||||
'the saved map stores each layer as its tiles and a run string per row, not a key per cell',
|
||||
storedLayers.length === 2 &&
|
||||
storedLayers.every((l) => l.cells === undefined && Array.isArray(l.rows)) &&
|
||||
storedLayers[0].tiles.join() === 'at-grass' &&
|
||||
storedLayers[0].rows.every((r) => typeof r === 'string'),
|
||||
JSON.stringify(storedLayers.map(({ tiles, origin, rows }) => ({ tiles, origin, rows }))),
|
||||
);
|
||||
await navigate();
|
||||
const reloaded = await json(
|
||||
`__gm.state.project.assets.find((a) => a.id === ${JSON.stringify(made.id)}).layers.map((l) => l.cells)`,
|
||||
);
|
||||
const sorted = (layers) => JSON.stringify(layers.map((c) => Object.entries(c).sort()));
|
||||
check(
|
||||
'a reloaded project has exactly the cells it was saved with',
|
||||
sorted(reloaded) === sorted(inMemory) && Object.keys(inMemory[0]).length === 9,
|
||||
JSON.stringify({ reloaded, inMemory }),
|
||||
);
|
||||
|
||||
// Leave the editor as the rest of the suite expects to find it.
|
||||
await evaluate("__gm.state.setTilemapPaint({ tool: 'select' })");
|
||||
await evaluate('__gm.state.select(null)');
|
||||
|
||||
Reference in new issue
Block a user