← @electriceeli

nonelectric-engine architecture (internal)

This guide is for people changing the engine. People using it should read the developer guide.

What this is and where it came from

The engine is four small pieces lifted out of eelipets, the pet game in the electriceeli.com repository. In eelipets each piece was tied to one game: its storage keys, its Preact islands, its pet. Here each is general, and anything about one particular game is left to the game.

Engine piece Taken from (electriceeli.com origin/main) What was kept What was left in eelipets
src/dialogue.js src/utils/data/digipet_clicker_rpg/story.ts and tale.ts, src/islands/digipet_clicker_rpg/story-modal.tsx Choices behind when conditions (flag, any, all). Flags set by choices. The open page saved so a reload lands on it. Checking saved data against the script on load. Chapters, endings and the tale cast. Need and stat checks (leans), dexterity games and {name} references. The game’s own conditions now go through check.
src/stage.js TravelFade in src/islands/digipet_clicker_rpg/scene-menu.tsx and .travel-fade in src/styles/eelipets.css Fade to dark, show the place’s name, swap the scene while it’s dark, fade back. Instant with reduced motion. The fixed 2.4 s keyframes, the farm and city art, the travel confirm dialog
src/clock.js gameInFront() in src/utils/stat-mechanics.ts, and the gated setIntervals in vitals.tsx and game-metadata.tsx Nothing moves unless the page is showing and focused. There’s no catching up on time away. Needs draining, encounter pacing and play-time counting, which are all users of the clock
src/save.js src/utils/data/digipet_clicker_rpg/save.ts Never crash on a hand-edited save. Parse field by field. A versioned shape. Run keys versus global keys, merging on import, gold as earned and spent totals, legacy key moves

eelipets hasn’t been moved onto the engine. Doing that is a separate change in electriceeli.com.

Shape

Engine modules used by a game

The four pieces never import each other. src/index.js only re-exports them. Keep it that way: it lets a game use one piece without the others. For example, a Preact game can use dialogue and save but draw its own transitions.

Rules that keep it working

  1. Everything worth saving is plain data owned by the game. Dialogue state is { at, flags }, clock time is a number, and the scene is a string. The engine never saves on its own behalf. Saving everything in one object is what lets a game resume mid-conversation without the engine knowing about saves.
  2. The dialogue is pure. view and choose take a state and return a new one. They read nothing else and change nothing. That’s why tests need no DOM, and why “what would the player see on load” is just view(resume(saved)).
  3. Flags are set when a node is entered, not when it’s drawn. begin and choose call enter, which adds the node’s set flags. Drawing the same line twice, for example after a reload, can’t apply them twice.
  4. Choice indexes are positions in the node, not on screen. view filters choices but keeps each one’s original index. A save or a test that says “choice 3” means the same choice whatever is hidden.
  5. Everything read from storage is untrusted. createSave.load swallows every error and returns null. dialogue.resume falls back to begin() if the saved node isn’t in the script anymore, which happens when a script is edited after players have saved. A game’s parse checks its own fields.
  6. Errors in the script are thrown at creation. createDialogue checks every to and next target, so a broken script fails at load, not three choices in.
  7. The clock only counts real play. Each tick measures real time since the last one and adds at most MAX_STEP_MS (1 s), and only while running() is true. Timers fire in deadline order, with ties going to the one set first. A callback may add or cancel timers.
  8. The stage swaps only while the screen is dark. The old scene’s cleanup runs, root is emptied, and the new scene draws while the veil is fully opaque. go calls are queued, so two quick clicks can’t draw two scenes over each other.

Saving and resuming mid-conversation

Saving a choice and restoring it after a reload

Choices made, and why

Testing

Known limits

Sprite toolkit

The sprite toolkit is an optional developer tool for pixel art. It lives in sprite/ and is described for users in sprites.md. It came from the eelipets sprite toolkit, using the portable snapshot of sprite-toolkit/shared/ that was handed over with the task. That folder isn’t on electriceeli.com’s origin/main, so the snapshot was the only source.

Here From sprite-toolkit/shared/ Changes
sprite/drawing.js drawing.ts Ported to JavaScript. Added rect, and a size check in canvas.
sprite/recipe.js generator.ts, validation.ts, outputs.ts, approval.ts Merged into one file, since each was a few lines. validateFrame throws on an unknown rule name. planOutputs also rejects absolute paths. The generator’s target was dropped: a sprite file lists its own rules.
sprite/browser.js browser.ts toCanvas is now exported, for the preview
sprite/png-node.js png-node.ts decode rejects files that aren’t PNGs
sprite/cli.js new; the idea is from scripts/sprite-toolkit-check.ts check and approve in one command

Where the line falls

Owner Responsible for
sprite/index.js (shared) pixel buffers, masks, seeded choices, validation, export planning, pixel comparison
sprite/cli.js (Node) loading a sprite file, planning and validating everything, then writing (approve) or comparing (check)
examples/parlour/sprites.html (development only) seed, settings, captions, rule results, and the approved PNG beside each state. It prints the approve command and never writes.
examples/parlour/art/mantel.js (the game) the art, palette, rules, state IDs and filenames
examples/parlour/game.js (the game) which PNG to show, worked out from the save
src/ (engine runtime) nothing: it never imports sprite/

test/sprite.test.js enforces the last row. It follows every static import from examples/parlour/game.js and fails if any reaches sprite/ or art/. I also checked it in Chrome’s network log: the game page loads only src/*.js, its own files, and images/mantel-*.png.

The mantel in the Quiet Parlour

Maintenance

Distribution

The engine is private and never published to a registry. Each version goes to a game as an npm pack archive, which the game commits under vendor/ and installs with npm ci. The workflow, and what an archive exposes, are in install.md. Anything added to files in package.json ends up in every game repo that commits an archive, so check npm pack --dry-run whenever files changes.