Skip to content

Import the game's save, and fix island loading races - #7

Merged
OGMods merged 1 commit into
mainfrom
game-export-import
Oct 11, 2026
Merged

OGMods merged 1 commit into
mainfrom
game-export-import

Conversation

@OGMods

@OGMods OGMods commented Oct 11, 2026

Copy link
Copy Markdown
Owner

What

The game's Export to Optimizer button writes an R2X1. code holding the player's whole save. Pasting it into Import code (renamed from "Import a layout") now loads it:

  • Every unlocked island's cleared obstacles and buildings, placed onto our maps.
  • The roster, Time Lab levels and anomaly.
  • Research in progress, with three choices: put building upgrades into the upgrade plan (default, in finishing order), count everything as done, or ignore it.
  • Islands still locked in the game are reset to their untouched maps. Custom islands are never touched.

Applying it takes two presses, because it replaces the player's boards. The dialog summarises the code first, and warns about any building it couldn't place or any anomaly this version doesn't know.

The format is specified in docs/game-export.md. Three real exports from the game are test fixtures.

How

  • packages/solver/src/encoding/gameExport.ts reads the code: raw deflate, base64url, a palette of the game's own ids, and BinaryWriter types. It ignores stray characters around a pasted code.
  • packages/solver/src/data/gameImport.ts maps it onto our data. Each shipped template now carries game: { areaId, originX, originY }, linking it to its region of the game's single world grid. A board is built from our template, with cleared obstacles cleared and buildings placed, so shipped maps still change only by player moves.
  • encoding/streams.ts holds the byte helpers both codecs share.

Fixes found along the way

  • Island 5's map was wrong. A tree sat one tile from where the game has it, and a real save has a cooler on the right spot. Golden layouts are unchanged; stored island 5 solves will show as stale.
  • Switching islands flashed the bare map. A load used to paint the template, then the saved layout over it, so repeated taps could leave either on screen. A load now decodes everything before it paints, and only the newest load lands. Tapping the island already open does nothing.
  • A pending save could undo Reset or an import. Saving an edit encodes in the background, and nothing cancelled it, so it could land after a Reset (or a game import) and bring the replaced board back. Both now cancel it.

Testing

  • npm test: 941 passed, including gameExport.test.ts (the real exports: alignment of every island, roster and Time Lab mapping, research in progress, refusals) and the app-side gameImport.test.ts and templateLoad.test.ts.
  • Each race test fails against the old code.
  • npm run check and npm run knip are clean.
  • I ran the import end to end in a headless browser with a real export: summary, two-press confirm, imported boards on screen, no console errors.

Open question for the game developer

One sample reports a research in progress with 0 seconds left. Either it had finished but wasn't collected, or the seconds aren't read from the running timer.

The game's Export to Optimizer button writes an R2X1 code holding the
player's whole save. Pasting it into Import code now loads it: every
unlocked island's cleared obstacles and buildings onto our maps, the
roster, Time Lab and anomaly, and research in progress either counted as
done or turned into the upgrade plan. Islands still locked in the game
are reset to their untouched maps. The format is in docs/game-export.md;
three real exports are test fixtures.

- encoding/gameExport.ts reads the code; data/gameImport.ts maps it onto
  our islands via IslandTemplate.game (area id and grid origin).
- Island 5's template had a tree one tile from where the game has it.
- Loading an island decodes before it paints and only the newest load
  lands, so the bare map no longer flashes and repeated taps settle on
  the saved board; tapping the open island does nothing.
- Reset and a game import cancel a save still encoding, which could
  otherwise land afterwards and bring the replaced board back.
@OGMods
OGMods merged commit 7894818 into main Oct 11, 2026
3 checks passed
@OGMods
OGMods deleted the game-export-import branch October 11, 2026 21:23
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