@origingame/create-game 0.1.1 → 0.3.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 (179) hide show
  1. package/README.md +17 -9
  2. package/archetypes/README.md +5 -2
  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 +3 -3
  23. package/archetypes/idle/assets/looks/idle.ogt +1 -1
  24. package/archetypes/idle/assets/{skins → styles}/sparkorb/LICENSES.md +4 -4
  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/main.ts +2 -2
  32. package/archetypes/idle/src/ui.ts +11 -11
  33. package/archetypes/idle/tools/make-assets.py +4 -4
  34. package/archetypes/match3/package.json +1 -1
  35. package/archetypes/match3/project.ogt +1 -1
  36. package/archetypes/rhythm/LICENSES.md +1 -1
  37. package/archetypes/rhythm/README.md +3 -3
  38. package/archetypes/rhythm/assets/{skins → styles}/lanebeat/LICENSES.md +4 -4
  39. package/archetypes/rhythm/assets/{skins/lanebeat/skin.ogt → styles/lanebeat/style.ogt} +45 -45
  40. package/archetypes/rhythm/package.json +1 -1
  41. package/archetypes/rhythm/project.ogt +1 -1
  42. package/archetypes/rhythm/references/metal/results.png +0 -0
  43. package/archetypes/rhythm/references/metal/title.png +0 -0
  44. package/archetypes/rhythm/src/main.ts +2 -2
  45. package/archetypes/rhythm/src/ui.ts +11 -11
  46. package/archetypes/roguelike/LICENSES.md +1 -1
  47. package/archetypes/roguelike/README.md +3 -3
  48. package/archetypes/roguelike/assets/{skins → styles}/lampdive/LICENSES.md +4 -4
  49. package/archetypes/roguelike/assets/{skins/lampdive/skin.ogt → styles/lampdive/style.ogt} +41 -41
  50. package/archetypes/roguelike/package.json +1 -1
  51. package/archetypes/roguelike/project.ogt +1 -1
  52. package/archetypes/roguelike/references/metal/over.png +0 -0
  53. package/archetypes/roguelike/references/metal/title.png +0 -0
  54. package/archetypes/roguelike/src/main.ts +2 -2
  55. package/archetypes/roguelike/src/ui.ts +7 -7
  56. package/archetypes/runner/package.json +1 -1
  57. package/archetypes/runner/project.ogt +1 -1
  58. package/archetypes/third-person/LICENSES.md +1 -1
  59. package/archetypes/third-person/README.md +3 -3
  60. package/archetypes/third-person/assets/{skins → styles}/ember/LICENSES.md +2 -2
  61. package/archetypes/third-person/assets/{skins/ember/skin.ogt → styles/ember/style.ogt} +40 -41
  62. package/archetypes/third-person/package.json +1 -1
  63. package/archetypes/third-person/project.ogt +1 -1
  64. package/archetypes/third-person/references/metal/beacon.png +0 -0
  65. package/archetypes/third-person/references/metal/dawn.png +0 -0
  66. package/archetypes/third-person/references/metal/title.png +0 -0
  67. package/archetypes/third-person/references/webgl2/beacon.png +0 -0
  68. package/archetypes/third-person/src/main.ts +2 -2
  69. package/archetypes/third-person/src/ui.ts +10 -10
  70. package/archetypes/topdown/package.json +1 -1
  71. package/archetypes/topdown/project.ogt +1 -1
  72. package/archetypes/tower-defense/LICENSES.md +1 -1
  73. package/archetypes/tower-defense/README.md +5 -5
  74. package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LICENSES.md +4 -4
  75. package/archetypes/tower-defense/assets/styles/pathguard/atlas.png +0 -0
  76. package/archetypes/tower-defense/assets/styles/pathguard/style.ogt +111 -0
  77. package/archetypes/tower-defense/package.json +1 -1
  78. package/archetypes/tower-defense/project.ogt +1 -1
  79. package/archetypes/tower-defense/references/metal/end.png +0 -0
  80. package/archetypes/tower-defense/references/metal/title.png +0 -0
  81. package/archetypes/tower-defense/references/metal/wave.png +0 -0
  82. package/archetypes/tower-defense/src/main.ts +2 -2
  83. package/archetypes/tower-defense/src/ui.ts +19 -17
  84. package/bin/create.ts +80 -20
  85. package/looks/catalogue.json +40 -40
  86. package/package.json +5 -4
  87. package/template/README.md +2 -1
  88. package/template/assets/audio/sting.ogt +10 -0
  89. package/template/assets/timelines/intro.ogt +101 -0
  90. package/template/assets/timelines/narration.srt +11 -0
  91. package/template/host.d.ts +46 -0
  92. package/template/package.json +1 -1
  93. package/template/project.ogt +1 -1
  94. package/template/references/metal/intro-4.png +0 -0
  95. package/template/references/metal/intro-8.png +0 -0
  96. package/template/src/main.ts +1 -1
  97. package/template/tests/frames.ts +134 -0
  98. package/template/tests/intro.og.ts +65 -0
  99. package/template/tests/smoke.og.ts +30 -36
  100. package/template/tsconfig.json +1 -1
  101. package/template-2d/.origin/setup +14 -0
  102. package/template-2d/LICENSES.md +15 -0
  103. package/template-2d/README.md +42 -0
  104. package/template-2d/assets/audio/coin.wav +0 -0
  105. package/template-2d/assets/audio/jump.wav +0 -0
  106. package/template-2d/assets/fonts/OFL.txt +93 -0
  107. package/template-2d/assets/fonts/ui.ttf +0 -0
  108. package/template-2d/assets/fonts/ui.ttf.ogt +11 -0
  109. package/template-2d/assets/looks/origin-game-2d.ogt +12 -0
  110. package/template-2d/assets/maps/level.ogt +112 -0
  111. package/template-2d/assets/rigs/keeper.ogt +292 -0
  112. package/template-2d/assets/rigs/keeper.png +0 -0
  113. package/template-2d/assets/rigs/keeper.png.ogt +7 -0
  114. package/template-2d/assets/sprites/coin.ogt +11 -0
  115. package/template-2d/assets/sprites/coin.png +0 -0
  116. package/template-2d/assets/sprites/coin.png.ogt +7 -0
  117. package/template-2d/assets/sprites/courier.ogt +34 -0
  118. package/template-2d/assets/sprites/courier.png +0 -0
  119. package/template-2d/assets/sprites/courier.png.ogt +7 -0
  120. package/template-2d/assets/strings/en.ogt +11 -0
  121. package/template-2d/assets/tiles/city.ogt +17 -0
  122. package/template-2d/assets/tiles/city.png +0 -0
  123. package/template-2d/assets/tiles/city.png.ogt +7 -0
  124. package/template-2d/gitattributes +22 -0
  125. package/template-2d/gitignore +8 -0
  126. package/template-2d/package.json +18 -0
  127. package/template-2d/project.ogt +21 -0
  128. package/template-2d/src/main.ts +460 -0
  129. package/template-2d/tests/keeper.og.ts +93 -0
  130. package/template-2d/tests/smoke.og.ts +60 -0
  131. package/template-2d/tsconfig.json +17 -0
  132. package/archetypes/tower-defense/assets/skins/pathguard/atlas.png +0 -0
  133. package/archetypes/tower-defense/assets/skins/pathguard/skin.ogt +0 -111
  134. /package/archetypes/idle/assets/{skins → styles}/sparkorb/ChakraPetch-BoldItalic.ttf +0 -0
  135. /package/archetypes/idle/assets/{skins → styles}/sparkorb/ChakraPetch-BoldItalic.ttf.ogt +0 -0
  136. /package/archetypes/idle/assets/{skins → styles}/sparkorb/OFL.txt +0 -0
  137. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Orbitron-Medium.ttf +0 -0
  138. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Orbitron-Medium.ttf.ogt +0 -0
  139. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Rajdhani-Bold.ttf +0 -0
  140. /package/archetypes/idle/assets/{skins → styles}/sparkorb/Rajdhani-Bold.ttf.ogt +0 -0
  141. /package/archetypes/idle/assets/{skins → styles}/sparkorb/atlas.png +0 -0
  142. /package/archetypes/idle/assets/{skins → styles}/sparkorb/atlas.png.ogt +0 -0
  143. /package/archetypes/idle/assets/{skins → styles}/sparkorb/icons.png +0 -0
  144. /package/archetypes/idle/assets/{skins → styles}/sparkorb/icons.png.ogt +0 -0
  145. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/ChakraPetch-Medium.ttf +0 -0
  146. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/ChakraPetch-Medium.ttf.ogt +0 -0
  147. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/JetBrainsMono-Regular.ttf +0 -0
  148. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/JetBrainsMono-Regular.ttf.ogt +0 -0
  149. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/OFL.txt +0 -0
  150. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/Orbitron-Bold.ttf +0 -0
  151. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/Orbitron-Bold.ttf.ogt +0 -0
  152. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/atlas.png +0 -0
  153. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/atlas.png.ogt +0 -0
  154. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/icons.png +0 -0
  155. /package/archetypes/rhythm/assets/{skins → styles}/lanebeat/icons.png.ogt +0 -0
  156. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/DotGothic16-Regular.ttf +0 -0
  157. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/DotGothic16-Regular.ttf.ogt +0 -0
  158. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/OFL.txt +0 -0
  159. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/atlas.png +0 -0
  160. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/atlas.png.ogt +0 -0
  161. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/icons.png +0 -0
  162. /package/archetypes/roguelike/assets/{skins → styles}/lampdive/icons.png.ogt +0 -0
  163. /package/archetypes/third-person/assets/{skins → styles}/ember/Cinzel-Bold.ttf +0 -0
  164. /package/archetypes/third-person/assets/{skins → styles}/ember/Cinzel-Bold.ttf.ogt +0 -0
  165. /package/archetypes/third-person/assets/{skins → styles}/ember/Newsreader-Medium.ttf +0 -0
  166. /package/archetypes/third-person/assets/{skins → styles}/ember/Newsreader-Medium.ttf.ogt +0 -0
  167. /package/archetypes/third-person/assets/{skins → styles}/ember/OFL.txt +0 -0
  168. /package/archetypes/third-person/assets/{skins → styles}/ember/atlas.png +0 -0
  169. /package/archetypes/third-person/assets/{skins → styles}/ember/atlas.png.ogt +0 -0
  170. /package/archetypes/third-person/assets/{skins → styles}/ember/icons.png +0 -0
  171. /package/archetypes/third-person/assets/{skins → styles}/ember/icons.png.ogt +0 -0
  172. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/Fredoka-SemiBold.ttf +0 -0
  173. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/Fredoka-SemiBold.ttf.ogt +0 -0
  174. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LilitaOne-Regular.ttf +0 -0
  175. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/LilitaOne-Regular.ttf.ogt +0 -0
  176. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/OFL.txt +0 -0
  177. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/atlas.png.ogt +0 -0
  178. /package/archetypes/tower-defense/assets/{skins → styles}/pathguard/icons.png +0 -0
  179. /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.1.1"
16
+ "@origingame/engine": "0.3.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.1.1"
10
+ engine "0.3.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
  }
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ # Prepares this Game's cloud sandbox snapshot: Origin runs it once per
3
+ # snapshot build, in the checkout, without a terminal, for at most 20 minutes,
4
+ # and saves the result for new sandboxes of the Game. Keep it idempotent; it
5
+ # never receives credentials. Only ignored output is kept: node_modules/ and
6
+ # cooked/ (og cook is incremental, so a new sandbox starts cooked).
7
+ set -eu
8
+ if [ -f bun.lock ]; then bun install --frozen-lockfile; else bun install; fi
9
+ og="${ORIGIN_OG_BIN:-og}"
10
+ if ! command -v "$og" >/dev/null 2>&1; then
11
+ echo "no og on this executor class; the first og run cooks instead"
12
+ exit 0
13
+ fi
14
+ "$og" cook .
@@ -0,0 +1,15 @@
1
+ # Asset licences
2
+
3
+ Nothing in this project is downloaded: the art and sounds are the engine's
4
+ runner archetype's (`templates/archetypes/runner`, drawn and synthesised by
5
+ its `tools/make-assets.py`), and the rest is written by hand.
6
+
7
+ | File | Licence | Origin |
8
+ |---|---|---|
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
+ | `assets/tiles/city.png` | CC0 1.0 | self-made: the runner archetype's city tileset |
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 |
13
+ | `assets/audio/jump.wav`, `assets/audio/coin.wav` | CC0 1.0 | self-made: the runner archetype's synthesised tones |
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` |
15
+ | `assets/looks/*.ogt`, `assets/strings/*.ogt`, every other `.ogt` | CC0 1.0 | self-made, written by hand |
@@ -0,0 +1,42 @@
1
+ # The 2D starter
2
+
3
+ What `npm create @origingame/game` writes for a 2D game (`--profile 2d`, or
4
+ a premise that says 2D, platformer, side-scroller, metroidvania or pixel
5
+ art): the smallest whole 2D Origin Engine project. A courier runs and jumps
6
+ the rooftops of one level, takes coins, jumps up through one-way ledges and
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. 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>`), stepping on the plank.
11
+
12
+ ```sh
13
+ og run . # headless with the probe; og dev . reloads on save
14
+ og test . # tests/smoke.og.ts, tests/keeper.og.ts
15
+ og build . # the play page
16
+ ```
17
+
18
+ ## What it demonstrates, and the skills it exercises
19
+
20
+ | Part | Where | Skill |
21
+ |---|---|---|
22
+ | The project in the 2D profile: an orthographic camera, sprites, 2D physics | `project.ogt`, `start` in `src/main.ts` | og-game §2, §8 |
23
+ | 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) |
24
+ | A flipbook sheet, its clips numbered in file order and checked against the code | `assets/sprites/courier.ogt`, `CLIP`, `checkClips` | og-game §8 |
25
+ | 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, 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 |
26
+ | 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 |
27
+ | The map's objects: the spawn, the coins, the goal | `start`, `Pickups` | og-game §8 |
28
+ | 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 |
29
+ | The UI kit's platformer HUD and pause menu, every word from the string table | `Hud`, `assets/strings/en.ogt` | og-ui §1, §6; og-i18n §1 |
30
+ | A camera that follows with a dead zone and look-ahead | og.Follow2D on the hero | og-feel §8 |
31
+ | The frame's art direction as data: a look extending the 16bit-pixel preset | `assets/looks/origin-game-2d.ogt` (a created game's is `<id>.ogt`) | og-taste §1, §12 |
32
+ | A playtest that asserts on dumps, never on the code | `tests/smoke.og.ts` | og-build §3, §4 |
33
+
34
+ What a game made from it changes first: the art (the courier and the city
35
+ are the runner archetype's, `templates/archetypes/runner/tools/make-assets.py`
36
+ draws them), the level (`assets/maps/level.ogt`, or a Tiled `.tmj` beside
37
+ it, og-game §8), the controller's tunables (og-feel §12) and what the map's
38
+ objects mean. The 2D archetypes (`templates/archetypes/`) are whole games
39
+ to start from instead: a runner, a top-down room, match-3, a roguelike,
40
+ tower defence, an idle game and a rhythm game.
41
+
42
+ Asset licences: `LICENSES.md`.
@@ -0,0 +1,93 @@
1
+ Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file