five-on-it / apps/worker/src/generate
apps/worker/src/generate
A level from a level spec (TECHNICAL_SPECS §9.3): the spec checked against the catalogue's schema; a region's built in this process (generateRegion, no Blender); a city's solved here (@foi/catalogue's buildCity: its issues, else the plan Blender builds, handed to it as a file beside the spec); a town's or a city's written to a temporary folder and handed to the generator in headless Blender (assets/blender/levels/generate.py) with a time limit; the level's own kit and its recipe that Blender writes are then turned into level data in memory by the level pipeline (@foi/tools: the recipe's scene built, read back and exported, the way level:recipe and level:export would), in the canonical form of a level file. A spec the generator refuses (exit code 1, one generate: <path>: <message> line per problem) comes back as issues; anything else that goes wrong is a GenerateError. Every level is then audited and repaired (audit.ts: what may be dropped is dropped, the rest reported in the stats). The level's preview is rendered last (preview.ts, a second Blender run); a preview that fails leaves the level without one and says why in the stats, it never fails the generation.