firstbyte 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -2
- package/bin/firstbyte.js +32 -0
- package/blocks/achievements/Achievements/Achievements.js +102 -0
- package/blocks/catalog/Kinds/Kinds.js +18 -0
- package/blocks/catalog/Listing/Listing.js +178 -0
- package/blocks/catalog/Needs/Needs.js +68 -0
- package/blocks/check/Checker/Checker.js +63 -0
- package/blocks/check/FileChecks/FileChecks.js +228 -0
- package/blocks/check/PlayChecks/PlayChecks.js +289 -0
- package/blocks/check/PlayChecks/harness.html +21 -0
- package/blocks/check/PlayChecks/png.js +70 -0
- package/blocks/check/PlayChecks/serve.js +50 -0
- package/blocks/check/ReportText/ReportText.js +57 -0
- package/blocks/dev/Levels/Levels.js +47 -0
- package/blocks/load/Build/Build.js +45 -0
- package/blocks/load/Served/Served.js +27 -0
- package/blocks/load/Zip/Zip.js +141 -0
- package/blocks/metrics/Rollup/Rollup.js +79 -0
- package/blocks/rules/Brief/Brief.js +168 -0
- package/blocks/rules/Rulebook/Rulebook.js +214 -0
- package/blocks/rules/Starter/Starter.js +22 -0
- package/blocks/rules/Starter/game/README.txt +11 -0
- package/blocks/rules/Starter/game/achievements.json +6 -0
- package/blocks/rules/Starter/game/cover.jpg +0 -0
- package/blocks/rules/Starter/game/game.js +147 -0
- package/blocks/rules/Starter/game/game.json +9 -0
- package/blocks/rules/Starter/game/index.html +14 -0
- package/blocks/rules/Starter/game/style.css +3 -0
- package/blocks/sdk/Host/Host.js +123 -0
- package/blocks/sdk/Sdk/Sdk.js +157 -0
- package/index.js +7 -0
- package/package.json +52 -4
- package/site/data/demo-sessions.json +1 -0
- package/site/data/games.json +9 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* Serves a build from memory on 127.0.0.1 for the checker: the game on its own port, the harness page on another. */
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { served } from '../../load/Served/Served.js';
|
|
5
|
+
|
|
6
|
+
const here = (p) => new URL(p, import.meta.url);
|
|
7
|
+
const HARNESS = readFileSync(here('./harness.html'));
|
|
8
|
+
const HOST = readFileSync(here('../../sdk/Host/Host.js'));
|
|
9
|
+
export const SDK = readFileSync(here('../../sdk/Sdk/Sdk.js'));
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Two servers: the harness page (and sdk/Host) on one port, the game on another, so the game is on its own
|
|
13
|
+
* origin as it is on the real site and can't reach into the page that records its results. A path that
|
|
14
|
+
* can't be decoded is a 400, never a crash.
|
|
15
|
+
*/
|
|
16
|
+
export async function serve(files, root) {
|
|
17
|
+
/* Each file goes out as the live site sends it (load/Served): its type, and for a file the engine
|
|
18
|
+
already compressed (.br, .gz) its encoding, so the browser unpacks it as it will on the site. */
|
|
19
|
+
const send = (res, body, name) => {
|
|
20
|
+
const as = served(name);
|
|
21
|
+
res.writeHead(200, { 'content-type': as.type, 'cache-control': 'no-store', ...(as.encoding ? { 'content-encoding': as.encoding } : {}) });
|
|
22
|
+
res.end(body);
|
|
23
|
+
};
|
|
24
|
+
const notFound = (res, status = 404) => { res.writeHead(status, { 'content-type': 'text/plain' }); res.end(status === 400 ? 'Bad path' : 'Not in the build'); };
|
|
25
|
+
const pathOf = (req) => { try { return decodeURIComponent(new URL(req.url, 'http://x').pathname); } catch { return null; } };
|
|
26
|
+
const listen = (server) => new Promise((done) => server.listen(0, '127.0.0.1', () => done(server.address().port)));
|
|
27
|
+
|
|
28
|
+
const game = createServer((req, res) => {
|
|
29
|
+
const path = pathOf(req);
|
|
30
|
+
if (path === null) return notFound(res, 400);
|
|
31
|
+
if (path.startsWith('/game/')) {
|
|
32
|
+
let name = root + path.slice(6);
|
|
33
|
+
if (name.endsWith('/') || name === root) name += 'index.html';
|
|
34
|
+
const body = files.get(name);
|
|
35
|
+
if (body) return send(res, body, name);
|
|
36
|
+
}
|
|
37
|
+
return notFound(res);
|
|
38
|
+
});
|
|
39
|
+
const gamePort = await listen(game);
|
|
40
|
+
const harness = HARNESS.toString('utf8').replace('src="/game/index.html"', `src="http://127.0.0.1:${gamePort}/game/index.html"`);
|
|
41
|
+
const page = createServer((req, res) => {
|
|
42
|
+
const path = pathOf(req);
|
|
43
|
+
if (path === '/__fb/harness.html') return send(res, harness, 'harness.html');
|
|
44
|
+
if (path === '/__fb/host.js') return send(res, HOST, 'host.js');
|
|
45
|
+
return notFound(res, path === null ? 400 : 404);
|
|
46
|
+
});
|
|
47
|
+
const port = await listen(page);
|
|
48
|
+
const close = (server) => new Promise((r) => { server.closeAllConnections?.(); server.close(r); });
|
|
49
|
+
return { port, gamePort, close: () => Promise.all([close(page), close(game)]) };
|
|
50
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* The report as plain text for a person. --json prints the report object itself for an AI. */
|
|
2
|
+
|
|
3
|
+
const LABEL = { pass: 'PASS', fail: 'FAIL', warn: 'LOOK', skip: 'SKIP', note: 'NOTE', person: ' · ' };
|
|
4
|
+
const GROUPS = [
|
|
5
|
+
['files', 'Ready to send: the files'],
|
|
6
|
+
['play', 'Ready to send: playing it (headless browser)'],
|
|
7
|
+
['person', 'Quality review: our team plays it after you send it'],
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export function formatReport(rep, { color = false } = {}) {
|
|
11
|
+
const paint = (code, s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
12
|
+
const tint = { pass: 32, fail: 31, warn: 33, skip: 90, note: 36, person: 90 };
|
|
13
|
+
const lines = [`First Byte check: ${rep.name}`, ''];
|
|
14
|
+
if (rep.error) {
|
|
15
|
+
lines.push(`${paint(31, 'FAIL')} ${rep.error}`, '');
|
|
16
|
+
return lines.join('\n');
|
|
17
|
+
}
|
|
18
|
+
for (const [check, title] of GROUPS) {
|
|
19
|
+
lines.push(title);
|
|
20
|
+
const group = rep.results.filter((x) => x.check === check);
|
|
21
|
+
const why = group.length && group.every((r) => r.status === 'skip' && r.detail.join() === group[0].detail.join()) ? group[0].detail : null;
|
|
22
|
+
if (why) {
|
|
23
|
+
lines.push(` ${paint(tint.skip, 'SKIP')} ${group.map((r) => r.id).join(' ')}`);
|
|
24
|
+
for (const d of why) lines.push(` ${d}`);
|
|
25
|
+
lines.push('');
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for (const r of group) {
|
|
29
|
+
lines.push(` ${paint(tint[r.status], LABEL[r.status])} ${r.id} ${r.title}`);
|
|
30
|
+
for (const d of r.detail) lines.push(` ${d}`);
|
|
31
|
+
if (r.fix) lines.push(` ${paint(1, 'Fix:')} ${r.fix}`);
|
|
32
|
+
}
|
|
33
|
+
lines.push('');
|
|
34
|
+
}
|
|
35
|
+
lines.push(summary(rep, paint));
|
|
36
|
+
return lines.join('\n') + '\n';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* One line that never says more than the checks proved. */
|
|
40
|
+
export function summary(rep, paint = (c, s) => s) {
|
|
41
|
+
const fails = rep.counts.fail || 0;
|
|
42
|
+
const looks = rep.counts.warn || 0;
|
|
43
|
+
const skips = rep.counts.skip || 0;
|
|
44
|
+
const look = looks ? `, ${looks} to look at` : '';
|
|
45
|
+
if (fails) {
|
|
46
|
+
/* Some failures probably come from others (check/Checker `after`): say where to start. */
|
|
47
|
+
const failed = rep.results.filter((r) => r.status === 'fail');
|
|
48
|
+
const later = failed.filter((r) => r.after).length;
|
|
49
|
+
if (!later) return paint(31, `${fails} to fix${look}.`) + ' Fix them and run the check again.';
|
|
50
|
+
const first = failed.filter((r) => !r.after).map((r) => r.id);
|
|
51
|
+
const start = first.length > 1 ? `${first.slice(0, -1).join(', ')} and ${first.at(-1)}` : first[0];
|
|
52
|
+
return paint(31, `${fails} to fix${look}.`) + ` Start with ${start}: the other ${later} will probably clear up after. Then run the check again.`;
|
|
53
|
+
}
|
|
54
|
+
if (skips) return paint(33, `Nothing to fix so far${look}, but ${skips} check${skips === 1 ? ' was' : 's were'} skipped.`) + ' Run them before you send the game.';
|
|
55
|
+
if (looks) return paint(33, `Nothing to fix, ${looks} to look at.`) + ' A person plays it next.';
|
|
56
|
+
return paint(32, 'Passed every check.') + ' A person plays it next.';
|
|
57
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* A developer's level from what they have done. Plain ESM with no Node imports. */
|
|
2
|
+
|
|
3
|
+
export const OWN_SHARE = 100;
|
|
4
|
+
|
|
5
|
+
export const LEVELS = [
|
|
6
|
+
{ level: 0, name: 'Not picked yet', share: 0, perks: [] },
|
|
7
|
+
{ level: 1, name: 'First Byte', share: 70, perks: ['Your First Byte badge', 'Keep 70% of ad money from our players', 'Keep 100% from players you bring'] },
|
|
8
|
+
{ level: 2, name: 'Regular', share: 75, perks: ['Your Regular badge', 'Keep 75% of ad money from our players', 'Your uploads move up the review queue'] },
|
|
9
|
+
{ level: 3, name: 'Trusted', share: 80, perks: ['Your Trusted badge', 'Keep 80% of ad money from our players', 'Review feedback within 48 hours'] },
|
|
10
|
+
{ level: 4, name: 'Studio', share: 85, perks: ['Your Studio badge', 'Keep 85% of ad money from our players', 'First in line for the Monday front row'] },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/* What each level needs on top of the one below it. */
|
|
14
|
+
const NEEDS = [
|
|
15
|
+
() => [],
|
|
16
|
+
(r) => [{ label: 'Games picked', have: r.picked, need: 1 }],
|
|
17
|
+
(r) => (r.weeksLive >= 8 && r.picked < 3
|
|
18
|
+
? [{ label: 'Weeks one game has been live', have: r.weeksLive, need: 8 }]
|
|
19
|
+
: [{ label: 'Games picked', have: r.picked, need: 3 }]),
|
|
20
|
+
(r) => [{ label: 'Games picked', have: r.picked, need: 5 }, { label: 'Must-fix items in your last 3 reviews', have: r.recentMustFix, need: 0, atMost: true }],
|
|
21
|
+
(r) => [
|
|
22
|
+
{ label: 'Games picked', have: r.picked, need: 10 },
|
|
23
|
+
{ label: 'Players in the last 4 weeks', have: r.players, need: 100 },
|
|
24
|
+
{ label: '% of players past the first minute', have: Math.round(r.pastFirstMinute * 100), need: 50 },
|
|
25
|
+
{ label: '% of players back another day', have: Math.round(r.returning * 100), need: 20 },
|
|
26
|
+
],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const clean = (r = {}) => ({
|
|
30
|
+
picked: r.picked || 0, weeksLive: r.weeksLive || 0, recentMustFix: r.recentMustFix || 0,
|
|
31
|
+
players: r.players || 0, pastFirstMinute: r.pastFirstMinute || 0, returning: r.returning || 0,
|
|
32
|
+
});
|
|
33
|
+
const needs = (n, r) => NEEDS[n](r).map(({ atMost, ...x }) => ({ ...x, done: atMost ? x.have <= x.need : x.have >= x.need }));
|
|
34
|
+
|
|
35
|
+
export function levelOf(record, { reached = 0, cap = null } = {}) {
|
|
36
|
+
const r = clean(record);
|
|
37
|
+
let earned = 0;
|
|
38
|
+
while (earned < 4 && needs(earned + 1, r).every((x) => x.done)) earned++;
|
|
39
|
+
const best = Math.max(earned, reached || 0);
|
|
40
|
+
const level = cap == null ? best : Math.min(best, cap);
|
|
41
|
+
const L = LEVELS[level];
|
|
42
|
+
const n = level < 4 ? LEVELS[level + 1] : null;
|
|
43
|
+
return {
|
|
44
|
+
level, earned, name: L.name, share: L.share, ownShare: OWN_SHARE, perks: L.perks, capped: cap != null && best > cap,
|
|
45
|
+
next: n ? { level: n.level, name: n.name, needs: needs(n.level, r) } : null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* Loads a game build from a zip or a folder into one shape: a Map of path to Buffer. */
|
|
2
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { join, relative, sep } from 'node:path';
|
|
4
|
+
import { readZip } from '../Zip/Zip.js';
|
|
5
|
+
|
|
6
|
+
const SKIP = new Set(['.git', '.DS_Store', 'Thumbs.db', '__MACOSX', 'node_modules']);
|
|
7
|
+
|
|
8
|
+
export function loadGame(path) {
|
|
9
|
+
const st = statSync(path);
|
|
10
|
+
if (st.isDirectory()) return { kind: 'folder', path, files: readFolder(path) };
|
|
11
|
+
return { ...fromZip(readFileSync(path)), path };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function fromZip(buf) {
|
|
15
|
+
const files = readZip(buf);
|
|
16
|
+
for (const name of [...files.keys()]) if (name.startsWith('__MACOSX/')) files.delete(name);
|
|
17
|
+
return { kind: 'zip', path: null, files };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readFolder(root) {
|
|
21
|
+
const files = new Map();
|
|
22
|
+
const walk = (dir) => {
|
|
23
|
+
for (const name of readdirSync(dir)) {
|
|
24
|
+
if (SKIP.has(name)) continue;
|
|
25
|
+
const full = join(dir, name);
|
|
26
|
+
if (statSync(full).isDirectory()) walk(full);
|
|
27
|
+
else files.set(relative(root, full).split(sep).join('/'), readFileSync(full));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
walk(root);
|
|
31
|
+
for (const name of [...files.keys()]) if (name.startsWith('__MACOSX/')) files.delete(name);
|
|
32
|
+
return files;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Where index.html really is: '' when at the top, 'folder/' when the whole build sits in one folder. */
|
|
36
|
+
export function findRoot(files) {
|
|
37
|
+
const names = [...files.keys()].filter((n) => !n.startsWith('__MACOSX/'));
|
|
38
|
+
if (files.has('index.html')) return '';
|
|
39
|
+
const tops = new Set(names.map((n) => n.split('/')[0]));
|
|
40
|
+
if (tops.size === 1) {
|
|
41
|
+
const [top] = tops;
|
|
42
|
+
if (files.has(`${top}/index.html`)) return `${top}/`;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How one file of a build is sent to a browser: its type, and its encoding when the file is already
|
|
3
|
+
* compressed (game.wasm.br, game.data.gz, as Unity and other engines write them).
|
|
4
|
+
*
|
|
5
|
+
* The live site (server/GameHost) and the checker (check/PlayChecks serve.js) both ask here, so a
|
|
6
|
+
* build that plays in one plays in the other. Add a new file type in this table and nowhere else.
|
|
7
|
+
*/
|
|
8
|
+
export const TYPES = {
|
|
9
|
+
html: 'text/html; charset=utf-8', htm: 'text/html; charset=utf-8', js: 'text/javascript', mjs: 'text/javascript', css: 'text/css',
|
|
10
|
+
json: 'application/json', wasm: 'application/wasm', data: 'application/octet-stream', bin: 'application/octet-stream',
|
|
11
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif', svg: 'image/svg+xml', ico: 'image/x-icon',
|
|
12
|
+
mp3: 'audio/mpeg', ogg: 'audio/ogg', wav: 'audio/wav', m4a: 'audio/mp4', mp4: 'video/mp4', webm: 'video/webm',
|
|
13
|
+
woff: 'font/woff', woff2: 'font/woff2', ttf: 'font/ttf', otf: 'font/otf', txt: 'text/plain; charset=utf-8', xml: 'application/xml',
|
|
14
|
+
glb: 'model/gltf-binary', gltf: 'model/gltf+json', atlas: 'text/plain; charset=utf-8',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/* A last extension that means "these bytes are already compressed": the browser unpacks them. */
|
|
18
|
+
export const ENCODINGS = { br: 'br', gz: 'gzip' };
|
|
19
|
+
|
|
20
|
+
const ext = (name) => (name.includes('.') ? name.split('.').pop().toLowerCase() : '');
|
|
21
|
+
const typeOf = (name) => TYPES[ext(name)] || 'application/octet-stream';
|
|
22
|
+
|
|
23
|
+
export function served(name) {
|
|
24
|
+
const last = ext(name);
|
|
25
|
+
if (ENCODINGS[last]) return { type: typeOf(name.slice(0, -last.length - 1)), encoding: ENCODINGS[last] };
|
|
26
|
+
return { type: typeOf(name), encoding: null };
|
|
27
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* A small zip reader: stored and deflated entries, no zip64. Enough for a game build. And a writer, for the zips we hand out. */
|
|
2
|
+
import { inflateRawSync, deflateRawSync, crc32 } from 'node:zlib';
|
|
3
|
+
|
|
4
|
+
const EOCD = 0x06054b50;
|
|
5
|
+
const CENTRAL = 0x02014b50;
|
|
6
|
+
const LOCAL = 0x04034b50;
|
|
7
|
+
|
|
8
|
+
export class ZipError extends Error {}
|
|
9
|
+
|
|
10
|
+
/* The central directory, without unpacking anything. */
|
|
11
|
+
function entries(buf) {
|
|
12
|
+
const end = findEnd(buf);
|
|
13
|
+
const count = buf.readUInt16LE(end + 10);
|
|
14
|
+
const dirOffset = buf.readUInt32LE(end + 16);
|
|
15
|
+
if (count === 0xffff || dirOffset === 0xffffffff) {
|
|
16
|
+
throw new ZipError('This zip uses zip64, which the checker does not read. Zip it again with a normal zip tool.');
|
|
17
|
+
}
|
|
18
|
+
const out = [];
|
|
19
|
+
let p = dirOffset;
|
|
20
|
+
for (let i = 0; i < count; i++) {
|
|
21
|
+
if (p + 46 > buf.length || buf.readUInt32LE(p) !== CENTRAL) throw new ZipError('The zip is damaged: its file list is broken.');
|
|
22
|
+
const flags = buf.readUInt16LE(p + 8);
|
|
23
|
+
const nameLen = buf.readUInt16LE(p + 28);
|
|
24
|
+
const extraLen = buf.readUInt16LE(p + 30);
|
|
25
|
+
const commentLen = buf.readUInt16LE(p + 32);
|
|
26
|
+
const name = buf.toString(flags & 0x800 ? 'utf8' : 'latin1', p + 46, p + 46 + nameLen);
|
|
27
|
+
out.push({
|
|
28
|
+
name,
|
|
29
|
+
flags,
|
|
30
|
+
method: buf.readUInt16LE(p + 10),
|
|
31
|
+
compressed: buf.readUInt32LE(p + 20),
|
|
32
|
+
size: buf.readUInt32LE(p + 24),
|
|
33
|
+
mode: buf.readUInt32LE(p + 38) >>> 16,
|
|
34
|
+
local: buf.readUInt32LE(p + 42),
|
|
35
|
+
dir: name.endsWith('/'),
|
|
36
|
+
});
|
|
37
|
+
p += 46 + nameLen + extraLen + commentLen;
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function listZip(buf) {
|
|
43
|
+
return entries(buf).map(({ name, method, compressed, size, dir, mode }) => ({ name, method, compressed, size, dir, mode }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function readZip(buf) {
|
|
47
|
+
const files = new Map();
|
|
48
|
+
for (const e of entries(buf)) {
|
|
49
|
+
if (e.dir) continue;
|
|
50
|
+
if (e.flags & 1) throw new ZipError(`"${e.name}" is password protected. Zip it again without a password.`);
|
|
51
|
+
files.set(e.name, unpack(buf, e));
|
|
52
|
+
}
|
|
53
|
+
return files;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* One file out of a zip, without unpacking anything else: null when it isn't there. `maxBytes` is
|
|
58
|
+
* the most it may be: a bigger one throws, before any of it is unpacked.
|
|
59
|
+
*/
|
|
60
|
+
export function readFile(buf, name, maxBytes = Infinity) {
|
|
61
|
+
const e = entries(buf).find((x) => !x.dir && x.name === name);
|
|
62
|
+
if (!e) return null;
|
|
63
|
+
if (e.flags & 1) throw new ZipError(`"${e.name}" is password protected. Zip it again without a password.`);
|
|
64
|
+
if (e.size > maxBytes) throw new ZipError(`"${e.name}" is too big to read here.`);
|
|
65
|
+
return unpack(buf, e);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function findEnd(buf) {
|
|
69
|
+
const stop = Math.max(0, buf.length - 22 - 0xffff);
|
|
70
|
+
/* The real end record reaches the end of the file exactly; one hidden inside a comment does not. */
|
|
71
|
+
for (let p = buf.length - 22; p >= stop; p--) {
|
|
72
|
+
if (buf.readUInt32LE(p) === EOCD && p + 22 + buf.readUInt16LE(p + 20) === buf.length) return p;
|
|
73
|
+
}
|
|
74
|
+
throw new ZipError('This is not a zip file, or it is damaged.');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function unpack(buf, e) {
|
|
78
|
+
if (e.local + 30 > buf.length || buf.readUInt32LE(e.local) !== LOCAL) throw new ZipError(`The zip is damaged at "${e.name}".`);
|
|
79
|
+
const start = e.local + 30 + buf.readUInt16LE(e.local + 26) + buf.readUInt16LE(e.local + 28);
|
|
80
|
+
const raw = buf.subarray(start, start + e.compressed);
|
|
81
|
+
let out;
|
|
82
|
+
if (e.method === 0) out = Buffer.from(raw);
|
|
83
|
+
/* Never inflated past the size the zip claims: a zip that lies about its size stops there, not at gigabytes. */
|
|
84
|
+
else if (e.method === 8) {
|
|
85
|
+
try { out = inflateRawSync(raw, { maxOutputLength: Math.max(1, e.size) }); } catch { throw new ZipError(`The zip is damaged at "${e.name}": it is not the size the zip says.`); }
|
|
86
|
+
}
|
|
87
|
+
else throw new ZipError(`"${e.name}" uses a compression the checker does not read. Zip it again with a normal zip tool.`);
|
|
88
|
+
if (out.length !== e.size) throw new ZipError(`The zip is damaged at "${e.name}": it is not the size the zip says.`);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Writes a zip of { path: text or bytes }, in the order given, every file deflated. Each entry is
|
|
94
|
+
* dated 1 January 1980 (the earliest a zip can say), so the same files always give the same bytes.
|
|
95
|
+
*/
|
|
96
|
+
export function writeZip(files) {
|
|
97
|
+
const DATE = 0x0021;
|
|
98
|
+
const locals = [];
|
|
99
|
+
const centrals = [];
|
|
100
|
+
let offset = 0;
|
|
101
|
+
for (const [name, body] of Object.entries(files)) {
|
|
102
|
+
const data = Buffer.isBuffer(body) ? body : Buffer.from(String(body));
|
|
103
|
+
const packed = deflateRawSync(data, { level: 9 });
|
|
104
|
+
const nameBuf = Buffer.from(name);
|
|
105
|
+
const head = (sig, more) => {
|
|
106
|
+
const b = Buffer.alloc(more);
|
|
107
|
+
b.writeUInt32LE(sig, 0);
|
|
108
|
+
return b;
|
|
109
|
+
};
|
|
110
|
+
/* The fields both records share: version, flags (names are UTF-8), deflate, time, date, crc, sizes, name length. */
|
|
111
|
+
const shared = (b, at) => {
|
|
112
|
+
b.writeUInt16LE(20, at);
|
|
113
|
+
b.writeUInt16LE(0x800, at + 2);
|
|
114
|
+
b.writeUInt16LE(8, at + 4);
|
|
115
|
+
b.writeUInt16LE(0, at + 6);
|
|
116
|
+
b.writeUInt16LE(DATE, at + 8);
|
|
117
|
+
b.writeUInt32LE(crc32(data), at + 10);
|
|
118
|
+
b.writeUInt32LE(packed.length, at + 14);
|
|
119
|
+
b.writeUInt32LE(data.length, at + 18);
|
|
120
|
+
b.writeUInt16LE(nameBuf.length, at + 22);
|
|
121
|
+
};
|
|
122
|
+
const local = head(LOCAL, 30);
|
|
123
|
+
shared(local, 4);
|
|
124
|
+
const central = head(CENTRAL, 46);
|
|
125
|
+
central.writeUInt16LE(20, 4);
|
|
126
|
+
shared(central, 6);
|
|
127
|
+
central.writeUInt32LE(offset, 42);
|
|
128
|
+
locals.push(local, nameBuf, packed);
|
|
129
|
+
centrals.push(central, nameBuf);
|
|
130
|
+
offset += 30 + nameBuf.length + packed.length;
|
|
131
|
+
}
|
|
132
|
+
const dir = Buffer.concat(centrals);
|
|
133
|
+
const count = Object.keys(files).length;
|
|
134
|
+
const end = Buffer.alloc(22);
|
|
135
|
+
end.writeUInt32LE(EOCD, 0);
|
|
136
|
+
end.writeUInt16LE(count, 8);
|
|
137
|
+
end.writeUInt16LE(count, 10);
|
|
138
|
+
end.writeUInt32LE(dir.length, 12);
|
|
139
|
+
end.writeUInt32LE(offset, 16);
|
|
140
|
+
return Buffer.concat([...locals, dir, end]);
|
|
141
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/* Play sessions to numbers, with the guards that keep them honest. Plain ESM with no Node imports. */
|
|
2
|
+
|
|
3
|
+
export const GUARDS = { capMs: 2 * 60 * 60 * 1000, maxSessionMs: 24 * 60 * 60 * 1000 };
|
|
4
|
+
|
|
5
|
+
const r3 = (x) => Math.round(x * 1000) / 1000;
|
|
6
|
+
const r1 = (x) => Math.round(x * 10) / 10;
|
|
7
|
+
const share = (n, d) => (d ? r3(n / d) : 0);
|
|
8
|
+
const isPlay = (s) => s.played || s.activeMs > 0;
|
|
9
|
+
|
|
10
|
+
function median(list) {
|
|
11
|
+
if (!list.length) return null;
|
|
12
|
+
const a = [...list].sort((x, y) => x - y);
|
|
13
|
+
const m = a.length >> 1;
|
|
14
|
+
return a.length % 2 ? a[m] : Math.round((a[m - 1] + a[m]) / 2);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function group(list, keyOf) {
|
|
18
|
+
const m = new Map();
|
|
19
|
+
for (const x of list) {
|
|
20
|
+
const k = keyOf(x);
|
|
21
|
+
if (!m.has(k)) m.set(k, []);
|
|
22
|
+
m.get(k).push(x);
|
|
23
|
+
}
|
|
24
|
+
return m;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function rollup(sessions, { from = null, to = null, capMs = GUARDS.capMs } = {}) {
|
|
28
|
+
let dropped = 0;
|
|
29
|
+
const best = new Map();
|
|
30
|
+
for (const s of sessions) {
|
|
31
|
+
if (!s || !s.game || !s.device || !s.session || !(s.activeMs >= 0) || s.activeMs > GUARDS.maxSessionMs) { dropped++; continue; }
|
|
32
|
+
if ((from && s.day < from) || (to && s.day > to)) continue;
|
|
33
|
+
const had = best.get(s.session);
|
|
34
|
+
if (!had || s.activeMs > had.activeMs) best.set(s.session, s);
|
|
35
|
+
}
|
|
36
|
+
const kept = [...best.values()];
|
|
37
|
+
|
|
38
|
+
/* The cap: one browser, one game, one day. Minutes past it are not counted. */
|
|
39
|
+
const counted = new Map();
|
|
40
|
+
for (const [, list] of group(kept, (s) => `${s.device}|${s.game}|${s.day}`)) {
|
|
41
|
+
let left = capMs;
|
|
42
|
+
for (const s of [...list].sort((a, b) => a.startedAt - b.startedAt || (a.session < b.session ? -1 : 1))) {
|
|
43
|
+
const take = Math.min(s.activeMs, left);
|
|
44
|
+
left -= take;
|
|
45
|
+
counted.set(s.session, take);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const games = [];
|
|
50
|
+
for (const [game, list] of group(kept, (s) => s.game)) {
|
|
51
|
+
const plays = list.filter(isPlay);
|
|
52
|
+
const byDevice = group(plays, (s) => s.device);
|
|
53
|
+
const players = byDevice.size;
|
|
54
|
+
const ms = list.reduce((sum, s) => sum + counted.get(s.session), 0);
|
|
55
|
+
games.push({
|
|
56
|
+
game,
|
|
57
|
+
plays: plays.length,
|
|
58
|
+
players,
|
|
59
|
+
minutes: r1(ms / 60_000),
|
|
60
|
+
minutesPerPlayer: players ? r1(ms / 60_000 / players) : 0,
|
|
61
|
+
pastFirstMinute: share([...byDevice.values()].filter((l) => l.some((s) => s.firstMinute)).length, players),
|
|
62
|
+
returning: share([...byDevice.values()].filter((l) => new Set(l.map((s) => s.day)).size >= 2).length, players),
|
|
63
|
+
loadFailures: share(list.filter((s) => s.loadFailed).length, list.length),
|
|
64
|
+
likes: new Set(list.filter((s) => s.liked).map((s) => s.device)).size,
|
|
65
|
+
readyMs: median(list.filter((s) => s.readyMs != null).map((s) => s.readyMs)),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
games.sort((a, b) => b.minutes - a.minutes || (a.game < b.game ? -1 : 1));
|
|
69
|
+
|
|
70
|
+
const devices = group(kept.filter(isPlay), (s) => s.device);
|
|
71
|
+
const site = {
|
|
72
|
+
players: devices.size,
|
|
73
|
+
returning: share([...devices.values()].filter((l) => new Set(l.map((s) => s.day)).size >= 2).length, devices.size),
|
|
74
|
+
gamesPerPlayer: devices.size ? r1([...devices.values()].reduce((sum, l) => sum + new Set(l.map((s) => s.game)).size, 0) / devices.size) : 0,
|
|
75
|
+
secondGame: share([...devices.values()].filter((l) => new Set(l.map((s) => s.game)).size >= 2).length, devices.size),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return { games, site, minutes: Object.fromEntries(games.map((g) => [g.game, g.minutes])), dropped };
|
|
79
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/* The AI brief: the rulebook written out for a coding assistant. Built from rules/Rulebook and the catalog. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { RULES, ALLOWED, LIMITS } from '../Rulebook/Rulebook.js';
|
|
4
|
+
import { needs, shortlist } from '../../catalog/Needs/Needs.js';
|
|
5
|
+
import { rollup } from '../../metrics/Rollup/Rollup.js';
|
|
6
|
+
import { LEVELS, OWN_SHARE } from '../../dev/Levels/Levels.js';
|
|
7
|
+
import { LIMITS as ACH, ICONS } from '../../achievements/Achievements/Achievements.js';
|
|
8
|
+
import { starterFiles, STARTER_URL } from '../Starter/Starter.js';
|
|
9
|
+
import { LIMITS as LISTING, CONTROL_KEYS } from '../../catalog/Listing/Listing.js';
|
|
10
|
+
import { CATEGORIES } from '../../catalog/Kinds/Kinds.js';
|
|
11
|
+
|
|
12
|
+
/* The catalog the site shows. The brief lists what it lacks, worked out the same way the site does. */
|
|
13
|
+
export function catalog() {
|
|
14
|
+
return JSON.parse(readFileSync(new URL('../../../site/data/games.json', import.meta.url), 'utf8'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* Play minutes per game, rolled up from the site's sessions, so the brief weighs kinds as the site does. */
|
|
18
|
+
export function minutes() {
|
|
19
|
+
try {
|
|
20
|
+
return rollup(JSON.parse(readFileSync(new URL('../../../site/data/demo-sessions.json', import.meta.url), 'utf8'))).minutes;
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const pkg = { version: '0.1' };
|
|
27
|
+
|
|
28
|
+
export function brief({ wanted = shortlist(needs(catalog(), { minutes: minutes() })) } = {}) {
|
|
29
|
+
const line = (r) => `- [${r.id}] ${r.brief}`;
|
|
30
|
+
const auto = RULES.filter((r) => r.check !== 'person' && !r.optional);
|
|
31
|
+
const optional = RULES.filter((r) => r.optional);
|
|
32
|
+
const person = RULES.filter((r) => r.check === 'person');
|
|
33
|
+
return `# First Byte: what we expect from a game (v${pkg.version})
|
|
34
|
+
|
|
35
|
+
You are helping a developer get a browser game picked for First Byte, a site that
|
|
36
|
+
shows a few new games each week. Check the game against the rules below. If it
|
|
37
|
+
breaks one, name the rule by its id and say how to fix it, before anything else.
|
|
38
|
+
|
|
39
|
+
The developer can run every automatic check themselves, two ways:
|
|
40
|
+
|
|
41
|
+
- On the site: drop the zip at firstbyte.games/send and press "Just check it". Nothing
|
|
42
|
+
goes to our team until they say so, and the report has a "Copy for my AI" button.
|
|
43
|
+
- On their machine: npx firstbyte check path/to/build.zip
|
|
44
|
+
|
|
45
|
+
Both give PASS or FAIL for each rule id below, with the fix (--json prints a report you can
|
|
46
|
+
read). Aim for no FAIL before the game is sent. LOOK means the checker could not tell: read it.
|
|
47
|
+
The quickest start is the starter game at the end of this page: it already passes every check.
|
|
48
|
+
|
|
49
|
+
## Ready to send: checked automatically
|
|
50
|
+
${auto.map(line).join('\n')}
|
|
51
|
+
|
|
52
|
+
## Optional
|
|
53
|
+
${optional.map(line).join('\n')}
|
|
54
|
+
|
|
55
|
+
## Quality review: played by our team
|
|
56
|
+
After a game passes the checks above, our team plays it and grades each of these good,
|
|
57
|
+
needs work, or must fix, with feedback on anything that is not good. Only must fix stops a
|
|
58
|
+
game being picked; needs work is advice. The developer sees every grade and the feedback.
|
|
59
|
+
Help the developer play their own game against each one before sending.
|
|
60
|
+
${person.map(line).join('\n')}
|
|
61
|
+
|
|
62
|
+
## Allowed
|
|
63
|
+
${ALLOWED.map((a) => `- ${a}`).join('\n')}
|
|
64
|
+
|
|
65
|
+
## The SDK (optional)
|
|
66
|
+
<script src="https://firstbyte.games/sdk.js"></script>
|
|
67
|
+
|
|
68
|
+
- FirstByte.ready() once, when the first frame is on screen
|
|
69
|
+
- FirstByte.playing(true) when a round starts; FirstByte.playing(false) when it ends
|
|
70
|
+
- FirstByte.breakTime() an ad, only while playing(false). Resolves { shown }.
|
|
71
|
+
While playing it is refused and resolves { shown: false }.
|
|
72
|
+
- FirstByte.save(data) progress, anything JSON can store, up to ${LIMITS.saveBytes / 1024 / 1024} MB
|
|
73
|
+
- FirstByte.load() the saved progress, or null
|
|
74
|
+
- FirstByte.score(n) an optional score board
|
|
75
|
+
- FirstByte.achieve(id) an achievement earned, by its id in achievements.json; only the first time is new
|
|
76
|
+
- FirstByte.on(name, fn) 'mute', 'unmute', 'pause' (before an ad), 'resume'
|
|
77
|
+
|
|
78
|
+
Every call works without the site too: on its own the game saves to the browser
|
|
79
|
+
and breakTime() resolves { shown: false } at once, so nothing needs a special case.
|
|
80
|
+
|
|
81
|
+
## Achievements (optional)
|
|
82
|
+
Two steps. 1: put achievements.json next to index.html:
|
|
83
|
+
|
|
84
|
+
{ "achievements": [
|
|
85
|
+
{ "id": "first-win", "name": "First win", "about": "Win a round.", "icon": "crown" },
|
|
86
|
+
{ "id": "untouched", "name": "Untouched", "about": "Clear a level without a hit.", "secret": true }
|
|
87
|
+
] }
|
|
88
|
+
|
|
89
|
+
2: call FirstByte.achieve('first-win') when the player earns it. Calling it again is fine.
|
|
90
|
+
|
|
91
|
+
- Up to ${ACH.most}. An id is lowercase letters, digits and hyphens, up to ${ACH.idChars}; a name up to
|
|
92
|
+
${ACH.nameChars} letters; "about" up to ${ACH.aboutChars}. Plain words: no links, no < or >.
|
|
93
|
+
- "icon" is optional, one of: ${ICONS.join(', ')}. Pictures are drawn for you.
|
|
94
|
+
- "secret": true shows a question mark until it is earned.
|
|
95
|
+
- npx firstbyte check checks the file (F7) and every unlock while it plays (P9), and says exactly
|
|
96
|
+
what to add or fix.
|
|
97
|
+
Achievements are for players' fun: they never pay, and never count toward a level or a badge.
|
|
98
|
+
|
|
99
|
+
## The game's page (optional)
|
|
100
|
+
Two files next to index.html fill in the boxes when the game is sent, so nothing is typed twice.
|
|
101
|
+
|
|
102
|
+
game.json, with any of these:
|
|
103
|
+
|
|
104
|
+
{ "name": "Moon Hop",
|
|
105
|
+
"hook": "Hop between moons that shrink.",
|
|
106
|
+
"controls": [ { "keys": ["arrows", "wasd"], "does": "Move" }, { "keys": ["space"], "does": "Jump" } ],
|
|
107
|
+
"kinds": ["quick-runs"] }
|
|
108
|
+
|
|
109
|
+
- "name" up to ${LISTING.name} letters; "hook" is one line on what the player does, up to ${LISTING.hook}. Plain words, no links.
|
|
110
|
+
- "controls": up to ${LISTING.controls} rows, each 1 to ${LISTING.keys} keys and what they do in a word or two (up to ${LISTING.does} letters).
|
|
111
|
+
The keys are: ${Object.keys(CONTROL_KEYS).join(', ')}.
|
|
112
|
+
- "kinds": 1 to ${LISTING.kinds} of: ${CATEGORIES.map((k) => k.id).join(', ')}.
|
|
113
|
+
|
|
114
|
+
cover.jpg: the picture players see. A JPEG, 16:9 (like 1280 × 720), at least ${LISTING.coverWidth} wide, under 1 MB.
|
|
115
|
+
|
|
116
|
+
Our team picks the mood, the week and the address, and can change any of this. Help the developer
|
|
117
|
+
write both files: a hook that says what you do, not what the game is called.
|
|
118
|
+
|
|
119
|
+
## Good to know
|
|
120
|
+
- The game plays in a frame on the page: 16:9 on a computer, close to that on a phone, and it
|
|
121
|
+
changes size. Fill the window and scale the picture to fit, as the starter's style.css does.
|
|
122
|
+
- Many players are on phones, with no keyboard. Taps as well as keys reach more of them.
|
|
123
|
+
- Zip the build folder: index.html at the top, or inside the one folder that holds everything.
|
|
124
|
+
- The checker clicks, then presses Space, Enter, the arrow keys, W and D. It listens for a sound
|
|
125
|
+
and looks for FirstByte.playing(true) after the first of them.
|
|
126
|
+
|
|
127
|
+
## Exporting from an engine
|
|
128
|
+
- Unity: build for Web (WebGL) and zip the build folder (index.html, Build, TemplateData).
|
|
129
|
+
Brotli, Gzip or no compression all work: .br and .gz files are sent the way the browser needs.
|
|
130
|
+
- Godot 4.3 or newer: export for Web with Thread Support off (the default), and name the export index.html.
|
|
131
|
+
- Vite, webpack and the like: make every path relative (Vite: base: './'), then zip dist.
|
|
132
|
+
- Any engine: leave out other sites' SDKs, load nothing from a CDN, and play a sound on the first input.
|
|
133
|
+
|
|
134
|
+
## What gets a game picked
|
|
135
|
+
Something new: an idea, a look or a feeling we have not seen lately. Polish helps,
|
|
136
|
+
but a polished copy is not picked. Help the developer write one sentence on
|
|
137
|
+
"what's new about it". We read that first.
|
|
138
|
+
|
|
139
|
+
## Games we want most right now
|
|
140
|
+
Worked out from the games already on the site: the kinds it has fewest of.
|
|
141
|
+
${wanted.map((w) => `- ${w.level}: ${w.name}`).join('\n')}
|
|
142
|
+
|
|
143
|
+
## Pay
|
|
144
|
+
- Players who come through your own link (firstbyte.games/games/<id>?by=<you>): you keep ${OWN_SHARE}% of the ad money.
|
|
145
|
+
- Players First Byte brings: you keep a share that grows with your level:
|
|
146
|
+
${LEVELS.slice(1).map((l) => ` - ${l.name}: ${l.share}%`).join('\n')}
|
|
147
|
+
- Levels come from games picked, clean reviews and players who stay. Raw play counts never raise one,
|
|
148
|
+
and a level is never lost for a quiet spell.
|
|
149
|
+
- Until ads are live, a fixed monthly pool is split by real plays (a minute or more) the same way.
|
|
150
|
+
- Paid monthly, after the ad network pays us; under $25 rolls over to the next month.
|
|
151
|
+
- Developers never pay to be picked.
|
|
152
|
+
|
|
153
|
+
## A game that passes every check
|
|
154
|
+
Start from this: a whole game in a few small files, also at ${STARTER_URL} (with its cover.jpg)
|
|
155
|
+
The comments name the rule each line is there for.
|
|
156
|
+
${Object.entries(starterFiles()).filter(([name, text]) => typeof text === 'string' && name !== 'README.txt').map(([name, text]) => `
|
|
157
|
+
### ${name}
|
|
158
|
+
\`\`\`
|
|
159
|
+
${text.trimEnd()}
|
|
160
|
+
\`\`\``).join('\n')}
|
|
161
|
+
|
|
162
|
+
## Send it
|
|
163
|
+
At firstbyte.games/send: sign in with an email, drop the zip, and say in one sentence
|
|
164
|
+
what's new. The name, the hook, the controls, the kinds and the cover fill themselves in from
|
|
165
|
+
game.json and cover.jpg, or the developer types them there. The same checks run on it there, the
|
|
166
|
+
report shows in a minute or two, and our team answers within a week.
|
|
167
|
+
`;
|
|
168
|
+
}
|