five-on-it / apps/api/src/builds
apps/api/src/builds
Builds (TECHNICAL_SPECS §9.4): a draft's revision checked and, when it passes, stored as an artifact. A build resolves the game's level: a bundled level by name, or for a draft with a level spec the level the generator makes of it (generator.ts), whose named places join the game's own (the game's win over one of the same id). It then checks a generated level (checkLevel: its lint and the budgets), validates the game against the level, the vehicle classes and the common items and checks that its places can be reached from the spawn points (validateReach, on a navigation grid kept per level): the game's own and the generated ones its missions use. A generated level offers every place it has, the crater of a volcano and the top of a cliff among them; one no mission sends a player to is never a fault. It stores the level with the game under the artifact's hash; the build keeps the ids of the places the game has, for the missions its creator writes next, and what it was built with (currentManifest: the release, the formats, the generator), which the artifact carries too. A build that passes also stores its level's preview (a PNG): the one the generator rendered for a generated level, the committed one of a bundled level; a level without one, or a preview that cannot be stored, leaves the build without a picture and never fails it. Builds are jobs of the durable queue (queue.ts): a build's job, saved before the build is answered, keeps a snapshot of the game and the level spec as they were queued (a draft keeps no old revisions), so a build queued or running when the API stops is built after it comes back (a build is the same artifact however often it runs); the API runs a number of them at once (one by default, FOI_BUILD_CONCURRENCY), the build's state saved in the store as it goes.