@origingame/create-game 0.2.0 → 0.4.0

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.
Files changed (163) hide show
  1. package/README.md +2 -2
  2. package/archetypes/README.md +2 -1
  3. package/archetypes/arena/.origin/setup +14 -0
  4. package/archetypes/arena/LICENSES.md +8 -0
  5. package/archetypes/arena/README.md +67 -0
  6. package/archetypes/arena/assets/audio/coin.ogt +9 -0
  7. package/archetypes/arena/assets/audio/dash.ogt +9 -0
  8. package/archetypes/arena/assets/audio/win.ogt +9 -0
  9. package/archetypes/arena/assets/fx/coin.ogt +20 -0
  10. package/archetypes/arena/assets/looks/arena.ogt +10 -0
  11. package/archetypes/arena/gitattributes +22 -0
  12. package/archetypes/arena/gitignore +8 -0
  13. package/archetypes/arena/host.d.ts +46 -0
  14. package/archetypes/arena/package.json +18 -0
  15. package/archetypes/arena/project.ogt +14 -0
  16. package/archetypes/arena/src/game.ts +314 -0
  17. package/archetypes/arena/src/main.ts +100 -0
  18. package/archetypes/arena/tests/duel.og.ts +32 -0
  19. package/archetypes/arena/tests/solo.og.ts +22 -0
  20. package/archetypes/arena/tsconfig.json +17 -0
  21. package/archetypes/idle/LICENSES.md +1 -1
  22. package/archetypes/idle/README.md +5 -5
  23. package/archetypes/idle/assets/looks/idle.ogt +2 -2
  24. package/archetypes/idle/assets/{skins → styles}/sparkorb/LICENSES.md +6 -6
  25. package/archetypes/idle/assets/{skins/sparkorb/skin.ogt → styles/sparkorb/style.ogt} +47 -47
  26. package/archetypes/idle/package.json +1 -1
  27. package/archetypes/idle/project.ogt +1 -1
  28. package/archetypes/idle/references/metal/card.png +0 -0
  29. package/archetypes/idle/references/metal/orbit.png +0 -0
  30. package/archetypes/idle/references/metal/title.png +0 -0
  31. package/archetypes/idle/src/components.ts +1 -1
  32. package/archetypes/idle/src/main.ts +5 -5
  33. package/archetypes/idle/src/ui.ts +13 -13
  34. package/archetypes/idle/tools/make-assets.py +5 -5
  35. package/archetypes/match3/package.json +1 -1
  36. package/archetypes/match3/project.ogt +1 -1
  37. package/archetypes/rhythm/LICENSES.md +1 -1
  38. package/archetypes/rhythm/README.md +5 -5
  39. package/archetypes/rhythm/assets/{skins → styles}/lanebeat/LICENSES.md +6 -6
  40. package/archetypes/rhythm/assets/{skins/lanebeat/skin.ogt → styles/lanebeat/style.ogt} +45 -45
  41. package/archetypes/rhythm/package.json +1 -1
  42. package/archetypes/rhythm/project.ogt +1 -1
  43. package/archetypes/rhythm/references/metal/results.png +0 -0
  44. package/archetypes/rhythm/references/metal/title.png +0 -0
  45. package/archetypes/rhythm/src/components.ts +1 -1
  46. package/archetypes/rhythm/src/main.ts +3 -3
  47. package/archetypes/rhythm/src/ui.ts +12 -12
  48. package/archetypes/roguelike/LICENSES.md +1 -1
  49. package/archetypes/roguelike/README.md +5 -5
  50. package/archetypes/roguelike/assets/{skins → styles}/lampdive/LICENSES.md +6 -6
  51. package/archetypes/roguelike/assets/{skins/lampdive/skin.ogt → styles/lampdive/style.ogt} +41 -41
  52. package/archetypes/roguelike/package.json +1 -1
  53. package/archetypes/roguelike/project.ogt +1 -1
  54. package/archetypes/roguelike/references/metal/over.png +0 -0
  55. package/archetypes/roguelike/references/metal/title.png +0 -0
  56. package/archetypes/roguelike/src/components.ts +1 -1
  57. package/archetypes/roguelike/src/main.ts +2 -2
  58. package/archetypes/roguelike/src/ui.ts +8 -8
  59. package/archetypes/runner/package.json +1 -1
  60. package/archetypes/runner/project.ogt +1 -1
  61. package/archetypes/third-person/LICENSES.md +1 -1
  62. package/archetypes/third-person/README.md +4 -4
  63. package/archetypes/third-person/assets/{skins → styles}/ember/LICENSES.md +4 -4
  64. package/archetypes/third-person/assets/{skins/ember/skin.ogt → styles/ember/style.ogt} +40 -41
  65. package/archetypes/third-person/package.json +1 -1
  66. package/archetypes/third-person/project.ogt +1 -1
  67. package/archetypes/third-person/references/metal/beacon.png +0 -0
  68. package/archetypes/third-person/references/metal/dawn.png +0 -0
  69. package/archetypes/third-person/references/metal/title.png +0 -0
  70. package/archetypes/third-person/references/webgl2/beacon.png +0 -0
  71. package/archetypes/third-person/src/components.ts +1 -1
  72. package/archetypes/third-person/src/main.ts +3 -3
  73. package/archetypes/third-person/src/sound.ts +1 -1
  74. package/archetypes/third-person/src/ui.ts +11 -11
  75. package/archetypes/topdown/package.json +1 -1
  76. package/archetypes/topdown/project.ogt +1 -1
  77. package/archetypes/tower-defense/LICENSES.md +1 -1
  78. package/archetypes/tower-defense/README.md +5 -5
  79. package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LICENSES.md +4 -4
  80. package/archetypes/tower-defense/assets/styles/pathguard/atlas.png +0 -0
  81. package/archetypes/tower-defense/assets/styles/pathguard/style.ogt +111 -0
  82. package/archetypes/tower-defense/package.json +1 -1
  83. package/archetypes/tower-defense/project.ogt +1 -1
  84. package/archetypes/tower-defense/references/metal/end.png +0 -0
  85. package/archetypes/tower-defense/references/metal/title.png +0 -0
  86. package/archetypes/tower-defense/references/metal/wave.png +0 -0
  87. package/archetypes/tower-defense/src/components.ts +1 -1
  88. package/archetypes/tower-defense/src/main.ts +2 -2
  89. package/archetypes/tower-defense/src/ui.ts +20 -18
  90. package/bin/create.ts +11 -8
  91. package/looks/catalogue.json +40 -40
  92. package/package.json +2 -2
  93. package/template/README.md +2 -1
  94. package/template/assets/audio/sting.ogt +10 -0
  95. package/template/assets/timelines/intro.ogt +101 -0
  96. package/template/assets/timelines/narration.srt +11 -0
  97. package/template/host.d.ts +46 -0
  98. package/template/package.json +1 -1
  99. package/template/project.ogt +1 -1
  100. package/template/references/metal/intro-4.png +0 -0
  101. package/template/references/metal/intro-8.png +0 -0
  102. package/template/src/main.ts +1 -1
  103. package/template/tests/frames.ts +134 -0
  104. package/template/tests/intro.og.ts +65 -0
  105. package/template/tests/smoke.og.ts +30 -36
  106. package/template/tsconfig.json +1 -1
  107. package/template-2d/LICENSES.md +1 -0
  108. package/template-2d/README.md +6 -2
  109. package/template-2d/assets/rigs/keeper.ogt +292 -0
  110. package/template-2d/assets/rigs/keeper.png +0 -0
  111. package/template-2d/assets/rigs/keeper.png.ogt +7 -0
  112. package/template-2d/package.json +1 -1
  113. package/template-2d/project.ogt +1 -1
  114. package/template-2d/src/main.ts +240 -4
  115. package/template-2d/tests/keeper.og.ts +178 -0
  116. package/archetypes/tower-defense/assets/skins/pathguard/atlas.png +0 -0
  117. package/archetypes/tower-defense/assets/skins/pathguard/skin.ogt +0 -111
  118. /package/archetypes/idle/assets/{skins → styles}/sparkorb/ChakraPetch-BoldItalic.ttf +0 -0
  119. /package/archetypes/idle/assets/{skins → styles}/sparkorb/ChakraPetch-BoldItalic.ttf.ogt +0 -0
  120. /package/archetypes/idle/assets/{skins → styles}/sparkorb/OFL.txt +0 -0
  121. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Orbitron-Medium.ttf +0 -0
  122. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Orbitron-Medium.ttf.ogt +0 -0
  123. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Rajdhani-Bold.ttf +0 -0
  124. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Rajdhani-Bold.ttf.ogt +0 -0
  125. /package/archetypes/idle/assets/{skins → styles}/sparkorb/atlas.png +0 -0
  126. /package/archetypes/idle/assets/{skins → styles}/sparkorb/atlas.png.ogt +0 -0
  127. /package/archetypes/idle/assets/{skins → styles}/sparkorb/icons.png +0 -0
  128. /package/archetypes/idle/assets/{skins → styles}/sparkorb/icons.png.ogt +0 -0
  129. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/ChakraPetch-Medium.ttf +0 -0
  130. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/ChakraPetch-Medium.ttf.ogt +0 -0
  131. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/JetBrainsMono-Regular.ttf +0 -0
  132. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/JetBrainsMono-Regular.ttf.ogt +0 -0
  133. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/OFL.txt +0 -0
  134. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/Orbitron-Bold.ttf +0 -0
  135. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/Orbitron-Bold.ttf.ogt +0 -0
  136. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/atlas.png +0 -0
  137. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/atlas.png.ogt +0 -0
  138. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/icons.png +0 -0
  139. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/icons.png.ogt +0 -0
  140. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/DotGothic16-Regular.ttf +0 -0
  141. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/DotGothic16-Regular.ttf.ogt +0 -0
  142. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/OFL.txt +0 -0
  143. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/atlas.png +0 -0
  144. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/atlas.png.ogt +0 -0
  145. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/icons.png +0 -0
  146. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/icons.png.ogt +0 -0
  147. /package/archetypes/third-person/assets/{skins → styles}/ember/Cinzel-Bold.ttf +0 -0
  148. /package/archetypes/third-person/assets/{skins → styles}/ember/Cinzel-Bold.ttf.ogt +0 -0
  149. /package/archetypes/third-person/assets/{skins → styles}/ember/Newsreader-Medium.ttf +0 -0
  150. /package/archetypes/third-person/assets/{skins → styles}/ember/Newsreader-Medium.ttf.ogt +0 -0
  151. /package/archetypes/third-person/assets/{skins → styles}/ember/OFL.txt +0 -0
  152. /package/archetypes/third-person/assets/{skins → styles}/ember/atlas.png +0 -0
  153. /package/archetypes/third-person/assets/{skins → styles}/ember/atlas.png.ogt +0 -0
  154. /package/archetypes/third-person/assets/{skins → styles}/ember/icons.png +0 -0
  155. /package/archetypes/third-person/assets/{skins → styles}/ember/icons.png.ogt +0 -0
  156. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/Fredoka-SemiBold.ttf +0 -0
  157. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/Fredoka-SemiBold.ttf.ogt +0 -0
  158. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LilitaOne-Regular.ttf +0 -0
  159. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LilitaOne-Regular.ttf.ogt +0 -0
  160. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/OFL.txt +0 -0
  161. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/atlas.png.ogt +0 -0
  162. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/icons.png +0 -0
  163. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/icons.png.ogt +0 -0
@@ -0,0 +1,101 @@
1
+ type timeline
2
+ version 1
3
+ ---
4
+ name "Intro"
5
+ duration 10
6
+ # The camera's rail: a slow arc in front of the yard, from the left to the right.
7
+ path "flyby" {
8
+ kind catmullRom
9
+ point -5 3.2 9
10
+ point -1.5 2.4 7.5
11
+ point 2 2 7
12
+ point 5 2.8 8.5
13
+ }
14
+ track camera {
15
+ rail "flyby"
16
+ key 0 {
17
+ at 0
18
+ target 0 1 0
19
+ fov 50
20
+ }
21
+ key 9.5 {
22
+ at 1
23
+ target 1.5 1 0
24
+ fov 42
25
+ ease cubicInOut
26
+ }
27
+ }
28
+ track transform "trickster" {
29
+ key 2 {
30
+ position 2 0 0
31
+ }
32
+ key 5 {
33
+ position 0.5 0 1.5
34
+ ease cubicInOut
35
+ }
36
+ }
37
+ track animation "trickster" {
38
+ key 0 {
39
+ clip "idle"
40
+ loop true
41
+ }
42
+ key 2 {
43
+ clip "walk"
44
+ loop true
45
+ blendIn 0.3
46
+ }
47
+ key 5 {
48
+ clip "wave"
49
+ blendIn 0.25
50
+ }
51
+ }
52
+ track caption {
53
+ captions "narration.srt"
54
+ style lg
55
+ anchor bottom
56
+ }
57
+ track audio {
58
+ key 1 {
59
+ sound "audio/blip.wav"
60
+ volume 0.6
61
+ }
62
+ key 5 {
63
+ sound "audio/click.ogt"
64
+ }
65
+ }
66
+ track music {
67
+ key 6 {
68
+ sound "audio/sting.ogt"
69
+ volume 0.7
70
+ fadeIn 0.3
71
+ fadeOut 1
72
+ end 9.5
73
+ loop true
74
+ }
75
+ }
76
+ track event {
77
+ key 5.5 {
78
+ do "spawn_wave:2"
79
+ retroactive true
80
+ }
81
+ }
82
+ track transition {
83
+ key 0 {
84
+ kind fade
85
+ mode in
86
+ duration 1
87
+ }
88
+ key 9 {
89
+ kind fade
90
+ mode out
91
+ duration 1
92
+ }
93
+ }
94
+ track marker {
95
+ key 2 {
96
+ name "walk"
97
+ }
98
+ key 5.5 {
99
+ name "drop"
100
+ }
101
+ }
@@ -0,0 +1,11 @@
1
+ 1
2
+ 00:00:00,800 --> 00:00:02,800
3
+ The yard, before the drop.
4
+
5
+ 2
6
+ 00:00:03,000 --> 00:00:05,200
7
+ The trickster walks out to meet it.
8
+
9
+ 3
10
+ 00:00:06,400 --> 00:00:08,800
11
+ Here they come.
@@ -0,0 +1,46 @@
1
+ // The host this project's playtest helpers (tests/*.ts) touch under bun:
2
+ // `node:` modules, `process`, `Buffer`, `TextEncoder`, `import.meta.url`.
3
+ // Declared here because the project type-checks with `types: []` (no
4
+ // @types/node, no bun-types): `og check` reads them through tsconfig.json's
5
+ // include. Game code (src/) uses none of them.
6
+
7
+ declare module "node:fs" {
8
+ export function existsSync(path: string): boolean;
9
+ export function readFileSync(path: string): Uint8Array;
10
+ export function readFileSync(path: string, encoding: string): string;
11
+ export function writeFileSync(path: string, data: string | Uint8Array): void;
12
+ export function mkdirSync(path: string, options?: { recursive?: boolean }): void;
13
+ export function copyFileSync(from: string, to: string): void;
14
+ }
15
+
16
+ declare module "node:path" {
17
+ export function dirname(path: string): string;
18
+ export function join(...parts: string[]): string;
19
+ export function resolve(...parts: string[]): string;
20
+ }
21
+
22
+ declare module "node:url" {
23
+ export function fileURLToPath(url: string | URL): string;
24
+ }
25
+
26
+ declare module "node:zlib" {
27
+ export function inflateSync(data: Uint8Array): Uint8Array;
28
+ export function deflateSync(data: Uint8Array, options?: { level?: number }): Uint8Array;
29
+ }
30
+
31
+ declare const process: {
32
+ readonly env: Record<string, string | undefined>;
33
+ cwd(): string;
34
+ readonly stdout: { write(text: string): boolean };
35
+ };
36
+ declare const Buffer: { concat(chunks: readonly Uint8Array[]): Uint8Array };
37
+ declare class TextEncoder {
38
+ encode(text: string): Uint8Array;
39
+ }
40
+ declare class URL {
41
+ constructor(url: string, base?: string | URL);
42
+ readonly href: string;
43
+ }
44
+ interface ImportMeta {
45
+ readonly url: string;
46
+ }
@@ -13,6 +13,6 @@
13
13
  "test": "og test ."
14
14
  },
15
15
  "dependencies": {
16
- "@origingame/engine": "0.2.0"
16
+ "@origingame/engine": "0.4.0"
17
17
  }
18
18
  }
@@ -7,7 +7,7 @@ version 1
7
7
  name "Origin Game"
8
8
  id "origin-game"
9
9
  # The engine this game is written against (design §9: upgrades are explicit).
10
- engine "0.2.0"
10
+ engine "0.4.0"
11
11
  entry "src/main.ts"
12
12
  # 2d (orthographic camera, sprites, 2D physics) or 3d.
13
13
  profile "3d"
@@ -66,7 +66,7 @@ export const Menu = defineSystem("Menu", { reads: [Spin, og.Input], writes: [Run
66
66
  const started = run.value.started;
67
67
  og.ui.column("Hud", { padding: { left: 24, top: 24, right: 24, bottom: 24 } }, () => og.ui.panel("Menu", { padding: { left: 20, top: 16, right: 20, bottom: 16 } }, () => {
68
68
  og.ui.label("Title", og.i18n.t(world, "menu.title"), { step: "displaySm" });
69
- og.ui.label("Status", started ? og.i18n.t(world, "menu.spinning", { speed: speed.toFixed(1) }) : og.i18n.t(world, "menu.prompt"), { color: { token: started ? "accentInk" : "fgMuted" } });
69
+ og.ui.label("Status", started ? og.i18n.t(world, "menu.spinning", { speed: speed.toFixed(1) }) : og.i18n.t(world, "menu.prompt"), { color: { token: started ? "highlight" : "inkMuted" } });
70
70
  const start = og.ui.button("Start", og.i18n.t(world, started ? "menu.started" : "menu.start"), { variant: "primary", size: "large", disabled: started });
71
71
  if (!started && (start.clicked || input.value.pressed("KeyS") || input.value.pressed("Enter"))) run.value.started = true;
72
72
  }));
@@ -0,0 +1,134 @@
1
+ // The reference-frame check: decode the PNGs a run wrote and compare them
2
+ // with references/<tier>/ under og-tests' tolerance (a channel off by more
3
+ // than 32/255 is an outlier; fail above 0.5 % outliers or an RGB RMSE above
4
+ // 0.01). A tier without its own references compares with `metal` and says
5
+ // so. `OG_FX_CAPTURE=1 og test .` records this tier's references instead.
6
+ // (Copied from templates/fx-showcase/tests/frames.ts, so the template stands alone.)
7
+
8
+ import { copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
9
+ import { dirname, join, resolve } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { inflateSync } from "node:zlib";
12
+ import type { PlaytestChecks, PlaytestRun } from "@origingame/engine/playtest";
13
+
14
+ export interface Image {
15
+ width: number;
16
+ height: number;
17
+ /** RGBA8 rows. */
18
+ rgba: Uint8Array;
19
+ }
20
+
21
+ /** An 8-bit RGB or RGBA, non-interlaced PNG, unfiltered. */
22
+ export function decodePng(bytes: Uint8Array): Image {
23
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24
+ let at = 8;
25
+ let width = 0;
26
+ let height = 0;
27
+ let channels = 4;
28
+ const idat: Uint8Array[] = [];
29
+ while (at < bytes.length) {
30
+ const len = view.getUint32(at);
31
+ const type = String.fromCharCode(...bytes.subarray(at + 4, at + 8));
32
+ const data = bytes.subarray(at + 8, at + 8 + len);
33
+ if (type === "IHDR") {
34
+ width = view.getUint32(at + 8);
35
+ height = view.getUint32(at + 12);
36
+ const depth = data[8]!;
37
+ const color = data[9]!;
38
+ if (depth !== 8 || (color !== 6 && color !== 2) || data[12] !== 0) throw new Error(`unsupported PNG (depth ${depth}, colour ${color}, interlace ${data[12]})`);
39
+ channels = color === 6 ? 4 : 3;
40
+ } else if (type === "IDAT") idat.push(data);
41
+ else if (type === "IEND") break;
42
+ at += 12 + len;
43
+ }
44
+ const raw = inflateSync(Buffer.concat(idat));
45
+ const stride = width * channels;
46
+ const out = new Uint8Array(width * height * 4);
47
+ const prev = new Uint8Array(stride);
48
+ const cur = new Uint8Array(stride);
49
+ for (let y = 0; y < height; y++) {
50
+ const filter = raw[y * (stride + 1)]!;
51
+ const line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
52
+ for (let i = 0; i < stride; i++) {
53
+ const a = i >= channels ? cur[i - channels]! : 0;
54
+ const b = prev[i]!;
55
+ const c = i >= channels ? prev[i - channels]! : 0;
56
+ let v = line[i]!;
57
+ if (filter === 1) v += a;
58
+ else if (filter === 2) v += b;
59
+ else if (filter === 3) v += (a + b) >> 1;
60
+ else if (filter === 4) {
61
+ const p = a + b - c;
62
+ const pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
63
+ v += pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
64
+ }
65
+ cur[i] = v & 255;
66
+ }
67
+ for (let x = 0; x < width; x++) {
68
+ for (let k = 0; k < 4; k++) out[(y * width + x) * 4 + k] = k < channels ? cur[x * channels + k]! : 255;
69
+ }
70
+ prev.set(cur);
71
+ }
72
+ return { width, height, rgba: out };
73
+ }
74
+
75
+ /** og-tests' rule: outlier fraction and RGB RMSE between two equal-size frames. */
76
+ export function difference(a: Image, b: Image): { outliers: number; rmse: number } {
77
+ if (a.width !== b.width || a.height !== b.height) return { outliers: 1, rmse: 1 };
78
+ let outliers = 0;
79
+ let sum = 0;
80
+ const n = a.width * a.height;
81
+ for (let p = 0; p < n; p++) {
82
+ let out = false;
83
+ for (let k = 0; k < 3; k++) {
84
+ const d = Math.abs(a.rgba[p * 4 + k]! - b.rgba[p * 4 + k]!);
85
+ if (d > 32) out = true;
86
+ const f = d / 255;
87
+ sum += f * f;
88
+ }
89
+ if (out) outliers++;
90
+ }
91
+ return { outliers: outliers / n, rmse: Math.sqrt(sum / (n * 3)) };
92
+ }
93
+
94
+ /** The playtest's output directory (the bundled playtest runs from it). */
95
+ export function outDir(): string {
96
+ return dirname(fileURLToPath(import.meta.url));
97
+ }
98
+
99
+ /** The project's references/, from its og-out/test/<name>/. */
100
+ export function referencesDir(): string {
101
+ return resolve(outDir(), "..", "..", "..", "references");
102
+ }
103
+
104
+ /** Compares each screenshot with its reference (`<prefix><file>`), or records it. */
105
+ export function checkFrames(run: PlaytestRun, t: PlaytestChecks, files: readonly string[], prefix: string): void {
106
+ // Read only where there is a renderer: without one (tier `none`) each frame is
107
+ // reported "no renderer, frame unchecked" and every other check still runs.
108
+ t.frame(files, () => {
109
+ const refs = referencesDir();
110
+ t.ok(existsSync(refs) || process.env.OG_FX_CAPTURE !== undefined, `the references directory exists at ${refs}`);
111
+ const own = join(refs, run.tier);
112
+ const capture = process.env.OG_FX_CAPTURE !== undefined;
113
+ for (const f of files) {
114
+ const actual = join(outDir(), f);
115
+ // Each file on its own: this tier's reference where it has one, metal's otherwise.
116
+ const mine = join(own, prefix + f);
117
+ const ref = capture || existsSync(mine) ? mine : join(refs, "metal", prefix + f);
118
+ if (ref !== mine) process.stdout.write(` note: no ${run.tier} reference for ${prefix}${f}; comparing with metal\n`);
119
+ if (capture) {
120
+ mkdirSync(own, { recursive: true });
121
+ copyFileSync(actual, ref);
122
+ t.ok(true, `recorded ${ref}`);
123
+ continue;
124
+ }
125
+ if (!existsSync(ref)) {
126
+ t.ok(false, `${ref} is missing: record it with OG_FX_CAPTURE=1 og test .`);
127
+ continue;
128
+ }
129
+ const d = difference(decodePng(readFileSync(actual)), decodePng(readFileSync(ref)));
130
+ process.stdout.write(` ${f}: ${(d.outliers * 100).toFixed(3)} % outliers, RMSE ${d.rmse.toFixed(5)} against ${ref}\n`);
131
+ t.ok(d.outliers <= 0.005 && d.rmse <= 0.01, `${f} matches ${prefix}${f}: ${(d.outliers * 100).toFixed(3)} % outliers (≤ 0.5 %), RMSE ${d.rmse.toFixed(5)} (≤ 0.01)`);
132
+ }
133
+ });
134
+ }
@@ -0,0 +1,65 @@
1
+ // The intro cutscene (assets/timelines/intro.ogt) played from the command
2
+ // channel: `timeline:play:intro` makes the entity `timeline-intro`, and the
3
+ // timeline drives the camera along the "flyby" rail, walks the trickster
4
+ // with its clips, shows the narration from narration.srt, plays two sounds,
5
+ // runs `spawn_wave:2` at 5.5 s and fades in and out. At 4 s and 8 s the
6
+ // caption on screen is the .srt's cue for that time and the frames are
7
+ // compared with references/<tier>/intro-4.png and intro-8.png
8
+ // (tests/frames.ts; `OG_FX_CAPTURE=1 og test .` records them). After the end
9
+ // the camera is the game's again.
10
+ import { playtest } from "@origingame/engine/playtest";
11
+ import { checkFrames } from "./frames.ts";
12
+
13
+ interface EntityDump {
14
+ components: Record<string, Record<string, number | boolean | string | number[]>>;
15
+ }
16
+
17
+ interface UiDump {
18
+ elements: Array<{ id: string; text: string; x: number; y: number; width: number; height: number }>;
19
+ }
20
+
21
+ const FILES = ["intro-4.png", "intro-8.png"] as const;
22
+
23
+ export default playtest({
24
+ name: "the intro plays its rail camera, captions, clips, event and fades from timeline:play:intro",
25
+ size: "1280x720",
26
+ commands: [
27
+ "0:timeline:play:intro",
28
+ "4:screenshot:intro-4.png",
29
+ "4:dump_ui:ui-4.json",
30
+ "4:dump_entity:timeline-intro:timeline-4.json",
31
+ "4:dump_entity:trickster:trickster-4.json",
32
+ "8:screenshot:intro-8.png",
33
+ "8:dump_ui:ui-8.json",
34
+ "8:dump_world:world-8.json",
35
+ "10.5:dump_entity:timeline-intro:timeline-end.json",
36
+ "10.5:dump_ui:ui-end.json",
37
+ "10.6:quit",
38
+ ].join(";"),
39
+ check(run, t) {
40
+ t.equal(run.warnings.join("; "), "", "the script ran without warnings");
41
+ t.ok(run.quit, "the script reached quit");
42
+ const caption = (file: string) =>
43
+ run.json<UiDump>(file).elements.find((e) => e.id.startsWith("timeline-caption-") && e.id.endsWith("-text"));
44
+ const at4 = caption("ui-4.json");
45
+ t.equal(at4?.text, "The trickster walks out to meet it.", "at 4 s the caption is the .srt's second cue");
46
+ t.ok(at4 !== undefined && at4.y > 600, `the caption sits at the bottom (y ${at4?.y})`);
47
+ t.equal(caption("ui-8.json")?.text, "Here they come.", "at 8 s the caption is the third cue");
48
+ const tl = run.json<EntityDump>("timeline-4.json").components["og.Timeline"]!;
49
+ t.equal(tl["playing"], true, "the timeline plays at 4 s");
50
+ t.near(Number(tl["time"]), 4, 0.02, "its time is the run's (it started at tick 0)");
51
+ // The transform track walks the trickster from (2 0 0) at 2 s to (0.5 0 1.5) at 5 s.
52
+ const p = run.json<EntityDump>("trickster-4.json").components["og.Transform"]!["position"] as number[];
53
+ t.ok(p[0]! < 2 && p[0]! > 0.5 && p[2]! > 0 && p[2]! < 1.5, `the trickster is on its way at 4 s (${p.join(", ")})`);
54
+ const world = run.json<{ entities: number }>("world-8.json");
55
+ t.ok(world.entities >= 10, `the event key at 5.5 s ran spawn_wave:2 (${world.entities} entities)`);
56
+ const end = run.json<EntityDump>("timeline-end.json").components["og.Timeline"]!;
57
+ t.equal(end["playing"], false, "the timeline ended");
58
+ t.equal(Number(end["time"]), 10, "at its duration");
59
+ t.equal(caption("ui-end.json"), undefined, "no caption after the end");
60
+ t.frame(FILES, () => {
61
+ for (const f of FILES) t.equal(run.png(f).width, 1280, `${f} is 1280 wide`);
62
+ });
63
+ checkFrames(run, t, FILES, "");
64
+ },
65
+ });
@@ -1,43 +1,37 @@
1
1
  // The template's playtest, run by `og test` through `og run --headless
2
2
  // --commands`: a tap on the menu's Start button (found by its UI id, no key
3
3
  // fallback) starts the trickster spinning and drops the crate onto the
4
- // ground; the frame, the dumps and the UI tree are written.
4
+ // ground. Every check is an `expect:` step evaluated in the run at its tick
5
+ // (docs/design.md §3.4): a failed one fails the run with the tick and what
6
+ // it observed, and a frame one without a renderer is reported unchecked.
7
+ // The frame, the scene described as data, the dumps and the UI tree are
8
+ // written beside them.
5
9
  import { playtest } from "@origingame/engine/playtest";
6
10
 
7
- interface EntityDump {
8
- components: Record<string, Record<string, number | boolean | string | number[]>>;
9
- }
10
-
11
- interface UiDump {
12
- elements: Array<{ id: string; parent: string; text: string; x: number; y: number; width: number; height: number }>;
13
- }
14
-
15
11
  export default playtest({
16
- name: "A tap on Start spins the trickster and drops the crate; the run writes its frame, dumps and UI tree",
17
- commands:
18
- "0.5:touch_move_to:Start;0.6:touch_start;0.7:touch_end;" +
19
- "2.0:screenshot:smoke.png;2.1:dump_entity:trickster:trickster.json;2.15:dump_entity:crate:crate.json;" +
20
- "2.2:dump_world:world.json;2.3:dump_ui:ui.json;2.5:quit",
21
- check(run, t) {
22
- t.ok(run.quit, "the script reached quit");
23
- // Frames are read inside t.frame: without a renderer (og test in a sandbox
24
- // with no GPU) the frame is reported unchecked and every other check runs.
25
- t.frame("smoke.png", () => {
26
- const frame = run.png("smoke.png");
27
- t.ok(frame.width > 0 && frame.height > 0, `a ${frame.width}x${frame.height} frame was captured`);
28
- });
29
- const world = run.json<{ entities: number; systems: Array<{ name: string; matched: number | null }> }>("world.json");
30
- t.ok(world.entities >= 5, `the scene spawned with the crate (${world.entities} entities)`);
31
- t.ok(world.systems.some((s) => s.name === "Rotate" && s.matched === 1), "Rotate matches the trickster");
32
- const ui = run.json<UiDump>("ui.json");
33
- const start = ui.elements.find((e) => e.id === "Start");
34
- t.ok(start !== undefined && start.width > 0 && start.height > 0, "the UI tree has the Start button with bounds");
35
- t.ok(start?.text === "Started", `the button reads "${start?.text}" after the tap`);
36
- const trickster = run.json<EntityDump>("trickster.json");
37
- const spin = trickster.components["Spin"]!;
38
- t.ok(Number(spin["speed"]) > 0, `the trickster spins (${spin["speed"]} rad/s)`);
39
- const crate = run.json<EntityDump>("crate.json");
40
- const y = (crate.components["og.Transform"]!["position"] as number[])[1]!;
41
- t.ok(y > 0.4 && y < 0.6, `the crate fell from 4 m and rests on the ground (y ${y.toFixed(3)})`);
42
- },
12
+ name: "A tap on Start spins the trickster and drops the crate; the run writes its frame, description, dumps and UI tree",
13
+ commands: [
14
+ "0.5:touch_move_to:Start",
15
+ "0.6:touch_start",
16
+ "0.7:touch_end",
17
+ // The tap was one press; the run started; the button says so.
18
+ "0.8:expect:event:og.PointerDown:1",
19
+ "0.8:expect:state:started==true",
20
+ "0.9:expect:ui:text:=Started",
21
+ // The trickster spins; the crate fell from 4 m and rests on the ground.
22
+ "2.0:expect:state:spin>0",
23
+ "2.0:expect:entity:crate:within:-3,0.4,-1,1,0.6,2",
24
+ "2.0:expect:event:og.CollisionStarted",
25
+ // The frame (1280x720): the sky at the top, the crate and the trickster where they stand.
26
+ "2.0:screenshot:smoke.png",
27
+ "2.0:expect:region:560,16,64,24:color:#9da5b1:24",
28
+ "2.0:expect:entity:crate:within:380,360,280,240",
29
+ "2.0:expect:entity:trickster:within:640,300,240,280",
30
+ "2.1:describe:describe.json",
31
+ "2.1:dump_entity:trickster:trickster.json",
32
+ "2.15:dump_entity:crate:crate.json",
33
+ "2.2:dump_world:world.json",
34
+ "2.3:dump_ui:ui.json",
35
+ "2.5:quit",
36
+ ].join(";"),
43
37
  });
@@ -13,5 +13,5 @@
13
13
  "allowImportingTsExtensions": true,
14
14
  "noEmit": true
15
15
  },
16
- "include": ["src/**/*.ts", "tests/**/*.ts"]
16
+ "include": ["src/**/*.ts", "tests/**/*.ts", "host.d.ts"]
17
17
  }
@@ -9,6 +9,7 @@ its `tools/make-assets.py`), and the rest is written by hand.
9
9
  | `assets/sprites/courier.png`, `assets/sprites/coin.png` and their `.ogt` | CC0 1.0 | self-made: the runner archetype's courier and coin |
10
10
  | `assets/tiles/city.png` | CC0 1.0 | self-made: the runner archetype's city tileset |
11
11
  | `assets/tiles/city.ogt`, `assets/maps/level.ogt` | CC0 1.0 | self-made, written by hand |
12
+ | `assets/rigs/keeper.png`, `assets/rigs/keeper.ogt` | CC0 1.0 | self-made: the lamp keeper's parts drawn with ImageMagick primitives, its rig written by hand |
12
13
  | `assets/audio/jump.wav`, `assets/audio/coin.wav` | CC0 1.0 | self-made: the runner archetype's synthesised tones |
13
14
  | `assets/fonts/ui.ttf` | SIL Open Font License 1.1 (`assets/fonts/OFL.txt`) | Noto Sans SC Regular, subset to Latin-1 by the runner archetype from the project template's `assets/fonts/NotoSansSC-Regular-subset.ttf` |
14
15
  | `assets/looks/*.ogt`, `assets/strings/*.ogt`, every other `.ogt` | CC0 1.0 | self-made, written by hand |
@@ -5,11 +5,14 @@ a premise that says 2D, platformer, side-scroller, metroidvania or pixel
5
5
  art): the smallest whole 2D Origin Engine project. A courier runs and jumps
6
6
  the rooftops of one level, takes coins, jumps up through one-way ledges and
7
7
  lands on them, loses a life in the pit and clears the level at the far
8
- wall; Escape (or the HUD's Pause) opens the pause menu.
8
+ wall; Escape (or the HUD's Pause) opens the pause menu. Beside the spawn a
9
+ lamp keeper, a 2D skeletal rig, breathes on a ramp with its feet planted
10
+ and walks along it when sent (`keeper:<x>`): it turns over a few ticks,
11
+ steps along the plank, lets both feet land and turns back.
9
12
 
10
13
  ```sh
11
14
  og run . # headless with the probe; og dev . reloads on save
12
- og test . # tests/smoke.og.ts
15
+ og test . # tests/smoke.og.ts, tests/keeper.og.ts
13
16
  og build . # the play page
14
17
  ```
15
18
 
@@ -20,6 +23,7 @@ og build . # the play page
20
23
  | The project in the 2D profile: an orthographic camera, sprites, 2D physics | `project.ogt`, `start` in `src/main.ts` | og-game §2, §8 |
21
24
  | A hand-written tilemap over a tileset: a parallax skyline, roofs that collide, ledges on their own collider layer (`colliderLayers 2`) that the controller makes one-way | `assets/maps/level.ogt`, `assets/tiles/city.ogt` | og-game §8 (the grammar) |
22
25
  | A flipbook sheet, its clips numbered in file order and checked against the code | `assets/sprites/courier.ogt`, `CLIP`, `checkClips` | og-game §8 |
26
+ | A 2D skeletal rig: bones, slots, region attachments, a weighted-mesh cape the idle clip deforms, two-bone IK legs planted on a slope (og.IkTarget2D) and stepping along it under a walk clip with Bézier keys (turning over 12 ticks, no foot faster than the gait's swing, settling before idle), its clip events (breaths, footfalls) read as og.Skeleton2DEvent, its lantern an og.Light2D under og.Lighting2D (layers 1 and 2) | `assets/rigs/keeper.ogt`, `spawnKeeper`, `Walk`, `Plant`, `tests/keeper.og.ts` | og-game §8 |
23
27
  | og.PlatformerController: run, jump (held for the full height), coyote time, the jump buffer, one-way ledges, Down to drop | `Control`, the hero in `start` | og-game §13; og-feel §12 |
24
28
  | The map's objects: the spawn, the coins, the goal | `start`, `Pickups` | og-game §8 |
25
29
  | Input on the press's tick: keys, a pad, the HUD's touch controls on a phone | `Control`, `Hud` | og-feel §1; og-ui §5 |