diff --git a/CONTRACT.md b/CONTRACT.md index 6922dac..618ac47 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -1,7 +1,11 @@ # CyberCity — module contract -Deliverable: **one self-contained `index.html`**, fullscreen, pure ambient, no game loop. -Sources live in `src/`; `node build.js` inlines them into `index.html`. Never edit `index.html` by hand. +Deliverable: **`index.html` plus `w/`** — the page with the engine and the city inline, and one +`w/.js` per secondary world loaded by synchronous `\n').join('')} `; fs.writeFileSync(OUT, HTML, 'utf8'); +/* w/ is rewritten whole: a chunk this build did not produce (a world renamed or folded back + * inline) would otherwise sit there being published and never loaded. */ +fs.mkdirSync(WDIR, { recursive: true }); +for (const f of fs.readdirSync(WDIR)) + if (f.endsWith('.js') && !chunks.some(c => c.rel === 'w/' + f)) fs.unlinkSync(path.join(WDIR, f)); +for (const c of chunks) fs.writeFileSync(path.join(ROOT, c.rel), c.text, 'utf8'); +const kb = n => n + ' bytes (' + (n / 1024).toFixed(1) + ' KB)'; const bytes = Buffer.byteLength(HTML, 'utf8'); +let over = false; for (const p of files) console.log(' + ' + path.relative(ROOT, p).split(path.sep).join('/')); -console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + ' KB) ' + - files.length + ' modules'); +console.log('index.html ' + kb(bytes) + ' ' + (files.length - chunks.reduce((n, c) => n + c.files.length, 0)) + + ' modules headroom ' + (CAP_PAGE - bytes)); +if (bytes > CAP_PAGE) { console.error('build: index.html is over the 600 KB budget'); over = true; } +for (const c of chunks) { + const n = Buffer.byteLength(c.text, 'utf8'); + console.log(c.rel.padEnd(11) + ' ' + kb(n) + ' ' + c.files.length + ' modules headroom ' + (CAP_CHUNK - n)); + if (n > CAP_CHUNK) { console.error('build: ' + c.rel + ' is over the 160 KB per-world budget'); over = true; } +} /* THE BUDGET WAS 200 KB AND IT IS NOW 300 KB. That is a raise, not a discovery, and it is being * written down rather than quietly deleted. src/ went from roughly 190 KB to roughly 530 KB in one * pass — twelve new ambient elements, a weather director every element reads, four input devices, @@ -545,8 +634,39 @@ console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + ' * tree and it is worth two thousand bytes. A world is thirty thousand. Splitting the payload costs * the "one self-contained file" property, which is the first line of CONTRACT.md and is a real * loss — but it is the only remaining answer that is not "ship less", and it should be taken - * deliberately, by someone who has decided that trade, rather than discovered at this line again. */ -if (bytes > 600 * 1024) { - console.error('build: index.html is over the 600 KB budget'); - process.exit(1); -} + * deliberately, by someone who has decided that trade, rather than discovered at this line again. + * + * ---- AND THE PASS AFTER THAT SPLIT IT. ONE 600 KB LINE -> 600 KB + 3 x 160 KB. ---- + * Seventh time at this line, and the first time the answer is the one the last three paragraphs + * asked for. It was DECIDED, by the owner, before a byte of it was written — which is the condition + * the paragraph directly above set — and this is the record of what was traded. + * + * WHY NOW: the high-definition pass (an underpainting behind the glyphs, a pixel-path printer, + * density-correct optics) was costed at 8.5-9 KB against 1,983 bytes of headroom. The banked + * duplication cut is 2.35 KB of it. No ordering of the three moves closes that, and the fourth + * option — the next world — was already known not to fit. So it split. + * + * WHAT WAS SPENT: the "one self-contained file" property. index.html is still the page, still + * opens with no server (file:// runs classic