Developer docs · v2.4.2

Architecture

The game is plain browser JavaScript with no build step. It lives in game/: game/Substellar.dc.html is the only entry point; it loads support.js and the sub-*.js scripts, and everything else is fetched relative to it. The public website (homepage, changelog, 404) lives in site/, the docs in docs/, and npm run build combines all three into dist/ (see Website and build).

01Repository layout

Path What it is
game/ The game, served at /play/. Every file the entry point loads.
site/ The homepage, changelog page, 404 page and their scripts, styles and images. Served at /.
site/release-notes.json, site/releases.json Release notes and release dates: the single source for CHANGELOG.md, the changelog page and GitHub release text.
docs/ Player and contributor docs, rendered to /docs/. docs/release/<tag>/ records each deployment.
worker/ index.js: the Worker in front of the static site (Discord launches, Discord sign-in, co-op relay rooms). See DISCORD.md.
scripts/ check.mjs (fast checks), build-site.mjs (builds dist/), smoke.mjs (browser playtest).
tools/ balance-bot.js, balance-gate.js and changelog.cjs.

02Game files (game/)

File Role
Substellar.dc.html All UI (the template inside <x-dc>) and app logic (class Component in <script data-dc-script>). Screens: splash, menu, deploy, honors, battle, settings sheet.
sub-boot.js Runs before support.js: points the runtime at the React copies in vendor/ (through window.__resources) and copies Discord's script nonce onto every script the page adds.
support.js The component runtime that boots the entry point. It would load React, ReactDOM and Babel Standalone from unpkg; sub-boot.js redirects React to vendor/. Generated and vendored: don't edit it.
sub-net.js window.SubNet: Discord sign-in and Rich Presence, the co-op room connection and command forwarding. See DISCORD.md.
vendor/ React and ReactDOM UMD builds, the Rajdhani font and the bundled Discord SDK.
sub-data.js window.SUBD: 9 maps with masks, 29 defenses and structures (DEF) in four tabs (TABS: ground, air, control, support), 15 enemies (EN, including five boss classes rotated by bossOf), the late-wave HP multiplier waveK, waves (PROG/waveAt, Titan Rift ACTS/campAt), difficulties (DIFF), medals, ranks, cosmetics and ribbons (AW), abilities (ABIL), art and FX tables (ART, FX, MAP_UI).
sub-engine.js window.SubGame: 24 Hz simulation, pathing (BFS flow field), targeting, upgrades, snapshot and restore.
sub-render.js window.SubRender: canvas renderer for the map, towers, enemies, projectiles, FX and minimap. draw(ctx, g, alpha, ui) takes ui.vw/ui.vh (field size), ui.dpr, ui.cmp, ui.mmW and the camera. Projectiles and FX are culled to the view.
sub-audio.js window.SubAudio: synthesized SFX (SND), the ambient bed and map acoustics.
sub-music.js The soundtrack: two recorded tracks in assets/music/ (Ember Watch, Rift Signal) played through one <audio> element in the Web Audio graph, plus the last-life heartbeat and the analyser for the track art. Keeps the old entry points (menuBed, battleBed, sting, level).
sub-jukebox.js The music library with libPlay, libStop, libNow, libPos. The component's jbTick drives rotation.
sub-trackart.js Pixel art for the music player.
sub-icons.js SubIconURL: icon name to assets/sub/icons/*_mono.png mask.
sub-menubg.js Animated parallax menu backdrop (assets/sub/menu-album/<id>/).
tools/balance-bot.js Headless runner that loads sub-data.js and sub-engine.js in a Node VM and plays with a route-aware strategy.

Script tags in Substellar.dc.html carry ?v= cache busters (data n10, engine n9, render n6, audio n4, music n1, jukebox n1, trackart n1, icons n2, menubg n3 at v2.3.2). Bump the one for any script you edit.

03Events, effects and sounds

  • Every defense emits exactly one fire event per shot, named after its DEF id (this.ev(t.k) in fire()). SND in sub-audio.js has a voice for every id: rocket, howitzer, flame, tesla, laser, rail, nullifier, flak, goo, chain, gauss, sam, storm, oil, autocannon, mortar, flakburst, interceptor, cryo. Impacts emit imp_*, deaths die_light|die_heavy|die_air|die_boss, machines mhit and burn. Rate limits live in THR.
  • Other events: build, sell, boom, bomb, nuke, launch, time, wave, clear, leak, disabled, vet, unlock, boss, boss2, boss3, bosskill, victory, defeat, ui.
  • Visual FX kinds in g.fx are drawn by SubRender.fxDraw. There is one code path for every map and difficulty; only acoustics are map-specific.
  • sfx(type, pos) in the component pans and attenuates by camera position.

04Map acoustics

SubAudio.setRoom(mapId) swaps the impulse, wet level, low-pass and slap echo. MAP_ROOM: obsidian, cd_pass, cd_ash and titan use canyon; foundry and cd_foundry use metal; cd_coldtrap uses lunar; md_rim and md_habitat use hall; menus use menu. bgTick calls it when the screen changes.

05Layouts

Desktop: a fixed 1672 × 941 stage scaled to fit. The field is 1300 wide with the sidebar, or 1672 with it hidden (H).

Compact (phones): lay(vw, vh) sets this.cmp when the shortest side is under 600 CSS px or the URL has ?mobile=1. The stage is the real viewport at scale 1 and the canvas runs at devicePixelRatio (max 2). A top bar holds pause, wave, credits, lives and speed; a bottom bar holds Next Wave, four abilities and BUILD. The build drawer slides up in portrait and in from the right in landscape, and closes after a pick. A selected tower opens a card (upgrade, repair, sell, targeting). Pause, tech tree, report, results, ceremony and settings are full-screen sheets. Safe-area insets are respected and the camera is always active. Helpers: fw(), fh(), padT(), padB(), clampCam, centerOn.

Big maps (more than 20 columns) and every compact layout use the camera (pan, zoom, minimap).

06Input

  • Touch (pointer events on the canvas): with a build or ability armed, the first tap previews and a second tap on the same cell commits. Drag pans (or moves the preview when armed), pinch zooms, long-press selects a structure. buzz(ms) gives haptics when the haptics setting is on.
  • Gamepad: padTick(dt) runs every frame in battle. Outside battle padNav gives spatial focus over clickable elements (any element with an inline cursor:pointer); A clicks and B backs out.
  • Keyboard: rebindable in Settings → Controls; defaults are in KEYDEF.

07Co-op and Discord

Two players can share a co-op map (coop:true, split at column half, a gate per half in gates). The engine has np players with their own wallets (cr) and ability state (abs); pp is the player a call acts for, so credits, abT, abHad and abLv are getters for that player. The host's game runs the battle and sends syncOut() packets through the Worker's Room Durable Object; the partner's game runs as a follower and merges them with syncIn(). Details, Discord settings and tests: DISCORD.md.

08Persistence

  • localStorage['substellar.v2']: settings, best scores and the profile (XP, medals, ribbons, wins). Per-map difficulty memory is set.mapDiff[mapId].
  • localStorage['substellar.session']: the running battle snapshot, saved on wave events, every 15 seconds and on hide or unload; restored paused.
  • fixCos() resets rank-locked cosmetics on boot.
  • Never clear storage the game did not write.

09Rules and balance

  • Missile Turret: reload 33 ticks, rocket speed 4.
  • Upgrades MK I → II → III → IV → V cost 60%, 100%, 160%, 240% of base; MK IV needs wave 24 and MK V wave 48 (upGate). Each step gives ×1.25 damage, ×0.9 reload and +10% range (+5% for IV and V); see tDmg, tReload, tRange. Selling refunds 50% of the total spent.
  • Radar is local (radarAt, cached per tower as t.rf by auras()), Recycler salvF, Mining Rig mineIncome. Machines take damage through dmgTower (Shield Projector halves it and blocks fire).
  • New defenses target first (closest to the gate) by default. Modes: first, last, strong, weak, close, air.
  • Difficulties: easy 32, normal 64, hard 128, extreme 256 waves, and endless. Titan Rift is a 128-wave, eight-act campaign.
  • Waves launch on a countdown (DIFF.period ticks) unless the run is manual (new SubGame(diff, {manual: true}), from the manualWaves setting): then nothing launches until hurry(), which also works with enemies on the field. Manual scores are multiplied by TUNE.manualK (0.9). manual is saved in the session snapshot.
  • GAME_VERSION in Substellar.dc.html is shown on the main menu's "What's new" badge; npm run check keeps it equal to package.json.

10Conventions

  • Template images use <div role="img" style="background:url({{ x }}) center/contain no-repeat">, never <img src="{{ x }}">. A raw-template <img> with a hole makes the browser fetch the literal placeholder before mount. Static <img src="assets/..."> is fine.
  • Styles are inline in the template. The only stylesheet is the @keyframes and body reset block in <helmet>.
  • Map art must match the map's mask cell for cell (65 px cells).

11Website and build

The website has its own design system, taken from the game's HUD: Rajdhani lettering, amber corner ticks and angled buttons, telemetry read-outs, and one colour per build category (Ground amber, Air blue, Control violet, Support green). Map chapters use the game's paintings full-bleed; the guide uses blueprint plates and spec tables.

File Role
site/_partials.html Shared head links, top bar, footer and scripts. The build puts them into every page between <!-- site-header -->-style markers.
site/index.html, home.js Homepage: parallax hero (the menu's own art layers), map chapters (each pinned for two screens while it builds in stages s1–s5, themed with its own colours, layout and particles, showing the top-down map with its routes), the interactive blueprint flow field, arsenal, hostiles, battle anatomy, abilities (the game's FX sprite sheets), difficulty ladder, the player's record (read from substellar.v2 in their own browser, never sent anywhere) and the latest releases.
site/_guide.html, guide.js Field guide source. <!-- gen:… --> markers are filled by the build with plates and spec cards from the game data. guide.js draws the plates and runs the contents, search and previous/next links; the developer docs use it too.
site/site.js Shared: release data, game data (/data/game.json), the flow field (same BFS as the engine), navigation state, scroll reveals.
site/fx.js Ember particles behind every page. Still with reduced motion.
site/changelog.html, changelog.js Renders releases.json merged with release-notes.json (the structure and code come from xPartition).
site/assets/art/ Web-sized copies of game art, made by tools/site-art.cjs (needs Chrome). Sprites and FX are served from /play/assets/.
scripts/game-data.mjs Reads game/sub-data.js in a VM and returns the maps, machines, enemies, bosses, abilities, difficulties and ranks the site shows.

npm run build (scripts/build-site.mjs) writes dist/:

  • dist/ root: site/ without its _ sources (homepage at /, /changelog, 404.html, robots.txt, sitemap.xml, art and the Open Graph image), with the shared parts filled in.
  • dist/data/game.json: the game data.
  • dist/guide/: the field guide.
  • dist/play/: the game, byte-identical, plus index.html (the entry point with a page title and social tags).
  • dist/docs/: the Markdown docs in the guide's layout.
  • _headers (version and export digest headers), _redirects (old game URLs to /play/) and build-manifest.json (sha256 of every file).