@origingame/engine 0.0.0-stage → 0.1.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 (158) hide show
  1. package/bin/og.mjs +25 -0
  2. package/dist/web/origin-engine.d.ts +1233 -0
  3. package/dist/web/origin-engine.js +8628 -0
  4. package/dist/web/origin-engine_bg.wasm +0 -0
  5. package/dist/web/origin-engine_bg.wasm.d.ts +366 -0
  6. package/dist/web-publish/origin-engine-lanes.js +8509 -0
  7. package/dist/web-publish/origin-engine-lanes_bg.wasm +0 -0
  8. package/dist/web-publish/origin-engine.d.ts +1176 -0
  9. package/dist/web-publish/origin-engine.js +8313 -0
  10. package/dist/web-publish/origin-engine_bg.wasm +0 -0
  11. package/dist/web-publish/origin-engine_bg.wasm.d.ts +347 -0
  12. package/dist/web-publish/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  13. package/dist/web-publish-2d/origin-engine-lanes.js +8509 -0
  14. package/dist/web-publish-2d/origin-engine-lanes_bg.wasm +0 -0
  15. package/dist/web-publish-2d/origin-engine.d.ts +1176 -0
  16. package/dist/web-publish-2d/origin-engine.js +8313 -0
  17. package/dist/web-publish-2d/origin-engine_bg.wasm +0 -0
  18. package/dist/web-publish-2d/origin-engine_bg.wasm.d.ts +347 -0
  19. package/dist/web-publish-2d/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  20. package/knowledge/README.md +31 -0
  21. package/knowledge/knowledge.json +13 -0
  22. package/knowledge/looks/catalogue.json +1871 -0
  23. package/knowledge/package.json +33 -0
  24. package/knowledge/rules/platform.json +329 -0
  25. package/knowledge/scaffold/README.md +27 -0
  26. package/knowledge/scaffold/distribution.json +48 -0
  27. package/knowledge/scaffold/origin-engine.json +19 -0
  28. package/knowledge/scaffold/template/.origin/setup +14 -0
  29. package/knowledge/scaffold/template/LICENSES.md +23 -0
  30. package/knowledge/scaffold/template/README.md +37 -0
  31. package/knowledge/scaffold/template/assets/ai/guard.ogt +48 -0
  32. package/knowledge/scaffold/template/assets/audio/click.ogt +9 -0
  33. package/knowledge/scaffold/template/assets/fonts/NotoSansSC-Regular-subset.ttf.ogt +12 -0
  34. package/knowledge/scaffold/template/assets/fonts/OFL.txt +93 -0
  35. package/knowledge/scaffold/template/assets/looks/origin-game.ogt +12 -0
  36. package/knowledge/scaffold/template/assets/nav/yard.ogt +27 -0
  37. package/knowledge/scaffold/template/assets/scenes/main.ogt +34 -0
  38. package/knowledge/scaffold/template/assets/strings/en.ogt +14 -0
  39. package/knowledge/scaffold/template/assets/textures/stone_n.png.ogt +7 -0
  40. package/knowledge/scaffold/template/gitattributes +22 -0
  41. package/knowledge/scaffold/template/package.json +18 -0
  42. package/knowledge/scaffold/template/project.ogt +25 -0
  43. package/knowledge/scaffold/template/src/main.ts +246 -0
  44. package/knowledge/scaffold/template/tests/guard.og.ts +67 -0
  45. package/knowledge/scaffold/template/tests/smoke.og.ts +43 -0
  46. package/knowledge/scaffold/template/tsconfig.json +17 -0
  47. package/knowledge/scripts/lib.ts +203 -0
  48. package/knowledge/scripts/mount.ts +210 -0
  49. package/knowledge/scripts/pack.ts +24 -0
  50. package/knowledge/scripts/scaffold.ts +72 -0
  51. package/knowledge/scripts/validate.ts +749 -0
  52. package/knowledge/skills/og-ai/SKILL.md +386 -0
  53. package/knowledge/skills/og-audio/SKILL.md +191 -0
  54. package/knowledge/skills/og-build/SKILL.md +330 -0
  55. package/knowledge/skills/og-core/SKILL.md +285 -0
  56. package/knowledge/skills/og-feel/SKILL.md +385 -0
  57. package/knowledge/skills/og-game/SKILL.md +1479 -0
  58. package/knowledge/skills/og-i18n/SKILL.md +220 -0
  59. package/knowledge/skills/og-platform-sdk/SKILL.md +199 -0
  60. package/knowledge/skills/og-taste/SKILL.md +537 -0
  61. package/knowledge/skills/og-ui/SKILL.md +444 -0
  62. package/knowledge/wiki/ai.md +627 -0
  63. package/knowledge/wiki/anim.md +1187 -0
  64. package/knowledge/wiki/atmosphere.md +636 -0
  65. package/knowledge/wiki/audio.md +732 -0
  66. package/knowledge/wiki/camera.md +711 -0
  67. package/knowledge/wiki/commands.md +357 -0
  68. package/knowledge/wiki/game.md +220 -0
  69. package/knowledge/wiki/i18n.md +213 -0
  70. package/knowledge/wiki/index.md +1027 -0
  71. package/knowledge/wiki/input.md +1714 -0
  72. package/knowledge/wiki/load.md +1280 -0
  73. package/knowledge/wiki/math.md +166 -0
  74. package/knowledge/wiki/nav.md +1154 -0
  75. package/knowledge/wiki/physics.md +3142 -0
  76. package/knowledge/wiki/platform.md +857 -0
  77. package/knowledge/wiki/probe.md +1692 -0
  78. package/knowledge/wiki/reflect.md +285 -0
  79. package/knowledge/wiki/render.md +3511 -0
  80. package/knowledge/wiki/rng.md +393 -0
  81. package/knowledge/wiki/stream.md +376 -0
  82. package/knowledge/wiki/system.md +197 -0
  83. package/knowledge/wiki/systems.md +43 -0
  84. package/knowledge/wiki/terrain.md +727 -0
  85. package/knowledge/wiki/tilemap.md +422 -0
  86. package/knowledge/wiki/time.md +150 -0
  87. package/knowledge/wiki/transform.md +230 -0
  88. package/knowledge/wiki/tween.md +580 -0
  89. package/knowledge/wiki/ui.md +8000 -0
  90. package/knowledge/wiki/world.md +909 -0
  91. package/package.json +68 -4
  92. package/schema/api.schema.json +29675 -0
  93. package/shell/README.md +22 -0
  94. package/shell/brand/README.md +23 -0
  95. package/shell/brand/icon-192.png +0 -0
  96. package/shell/brand/icon-512.png +0 -0
  97. package/shell/brand/mark-on-paper.svg +6 -0
  98. package/shell/brand/origin-mark.svg +5 -0
  99. package/shell/brand/origin-motion.css +251 -0
  100. package/shell/brand/tokens.css +20 -0
  101. package/shell/brand.ts +132 -0
  102. package/shell/page.ts +715 -0
  103. package/shell/platform.ts +203 -0
  104. package/shell/player.ts +238 -0
  105. package/shell/shell.css +185 -0
  106. package/shell/sw.ts +177 -0
  107. package/shell/transport.ts +515 -0
  108. package/shell/wire.ts +369 -0
  109. package/src/e6.ts +69 -0
  110. package/src/env.d.ts +100 -0
  111. package/src/generated/abi.ts +980 -0
  112. package/src/index.ts +193 -0
  113. package/src/node/audio.ts +86 -0
  114. package/src/node/build.ts +109 -0
  115. package/src/node/device.ts +981 -0
  116. package/src/node/doctor.ts +60 -0
  117. package/src/node/index.ts +102 -0
  118. package/src/node/platform.ts +24 -0
  119. package/src/node/playtest-run.ts +249 -0
  120. package/src/node/png.ts +130 -0
  121. package/src/node/polish.ts +976 -0
  122. package/src/node/run.ts +373 -0
  123. package/src/node/web-build.ts +808 -0
  124. package/src/p2.ts +35 -0
  125. package/src/platform-local.ts +211 -0
  126. package/src/playtest.ts +131 -0
  127. package/src/runtime.ts +1509 -0
  128. package/src/systems/cameras.ts +247 -0
  129. package/src/ui-kit/bind.ts +141 -0
  130. package/src/ui-kit/huds.ts +303 -0
  131. package/src/ui-kit/index.ts +36 -0
  132. package/src/ui-kit/menus.ts +187 -0
  133. package/src/ui-kit/settings.ts +131 -0
  134. package/src/ui-kit/store.ts +222 -0
  135. package/src/ui-kit/story.ts +89 -0
  136. package/src/ui-kit/util.ts +106 -0
  137. package/src/web/a11y.ts +429 -0
  138. package/src/web/audio-worklet.ts +193 -0
  139. package/src/web/audio.ts +307 -0
  140. package/src/web/basis.ts +239 -0
  141. package/src/web/gamepad.ts +123 -0
  142. package/src/web/host.ts +166 -0
  143. package/src/web/input.ts +237 -0
  144. package/src/web/lanes.ts +21 -0
  145. package/src/web/play.ts +20 -0
  146. package/src/web/rpc-ring.ts +110 -0
  147. package/src/web/settle.ts +122 -0
  148. package/src/web/shell.ts +643 -0
  149. package/src/web/text-input.ts +248 -0
  150. package/src/web/worker.ts +1002 -0
  151. package/types/bindings.json +13654 -0
  152. package/types/index.d.ts +20090 -0
  153. package/vendor/basis/LICENSE +201 -0
  154. package/vendor/basis/NOTICE +15 -0
  155. package/vendor/basis/README.md +18 -0
  156. package/vendor/basis/basis_transcoder.js +19 -0
  157. package/vendor/basis/basis_transcoder.wasm +0 -0
  158. package/README.md +0 -3
@@ -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.
@@ -0,0 +1,12 @@
1
+ type look
2
+ version 1
3
+ ---
4
+ # The game's look (og-taste §12): the frame's art direction as data, named
5
+ # by GameDesc.look in src/main.ts and applied before start runs. It starts
6
+ # from the catalogue's faceted-low-poly preset (flat facets on every lit
7
+ # material, a soft vignette, AgX tone mapping); a block written below wins
8
+ # over the preset field by field, and `extends` takes any catalogue slug
9
+ # (packages/knowledge/looks/catalogue.json). `npm create @origingame/game`
10
+ # writes the game's own look from its premise, or from --look <slug>.
11
+ name "Origin Game"
12
+ extends "faceted-low-poly"
@@ -0,0 +1,27 @@
1
+ type navmesh
2
+ version 1
3
+ ---
4
+ # The yard's navmesh, baked by `og cook` (og.nav.load("nav/yard.ogt")): the
5
+ # ground and the wall `start` builds in src/main.ts, voxelised for an agent
6
+ # 0.4 m wide and 1.8 m tall. A `scene` or `model` entry bakes glTF geometry
7
+ # instead of boxes.
8
+ agent {
9
+ radius 0.4
10
+ height 1.8
11
+ climb 0.4
12
+ slope 45
13
+ }
14
+ cellSize 0.25
15
+ tileSize 32
16
+ bounds {
17
+ min -12 -1 -12
18
+ max 12 3 12
19
+ }
20
+ box {
21
+ center 0 -0.1 0
22
+ size 30 0.2 30
23
+ }
24
+ box {
25
+ center -3 1 -2
26
+ size 0.6 2 6
27
+ }
@@ -0,0 +1,34 @@
1
+ type scene
2
+ version 1
3
+ ---
4
+ name "Main"
5
+ entity "ground" {
6
+ Transform {
7
+ position 0 0 0
8
+ quaternion 0 0 0 1
9
+ scale 1 1 1
10
+ }
11
+ }
12
+ entity "dropship" {
13
+ model "models/dropship.glb"
14
+ Transform {
15
+ position 0 1.5 0
16
+ quaternion 0 0 0 1
17
+ scale 1 1 1
18
+ }
19
+ }
20
+ entity "trickster" {
21
+ model "models/walker.glb"
22
+ Transform {
23
+ position 2 0 0
24
+ quaternion 0 0.7071068 0 0.7071068
25
+ scale 1 1 1
26
+ }
27
+ entity "marker" {
28
+ Transform {
29
+ position 0 2.2 0
30
+ quaternion 0 0 0 1
31
+ scale 0.25 0.25 0.25
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,14 @@
1
+ type strings
2
+ version 1
3
+ ---
4
+ # The template's strings (og.i18n, og-i18n §1): every word the menu shows
5
+ # is a key here, never a literal in a system. This is the base table, in
6
+ # the game's source language; a locale is its own file beside it
7
+ # (`zh-CN.ogt`, with the same keys and its `fonts` line), loaded in `start`.
8
+ locale "en"
9
+ base true
10
+ string "menu.title" "Origin Engine"
11
+ string "menu.prompt" "Press Start to begin"
12
+ string "menu.spinning" "Spinning {speed} rad/s"
13
+ string "menu.start" "Start"
14
+ string "menu.started" "Started"
@@ -0,0 +1,7 @@
1
+ type import
2
+ version 1
3
+ ---
4
+ # A tangent-space normal map: UASTC, linear (colour textures default to ETC1S, sRGB).
5
+ texture {
6
+ kind normal
7
+ }
@@ -0,0 +1,22 @@
1
+ # Media to Git LFS, as the platform's other scaffolds route them; text stays
2
+ # diffable (.ogt scenes and settings are line-based text by design).
3
+ *.glb filter=lfs diff=lfs merge=lfs -text
4
+ *.gltf filter=lfs diff=lfs merge=lfs -text
5
+ *.bin filter=lfs diff=lfs merge=lfs -text
6
+ *.png filter=lfs diff=lfs merge=lfs -text
7
+ *.jpg filter=lfs diff=lfs merge=lfs -text
8
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
9
+ *.webp filter=lfs diff=lfs merge=lfs -text
10
+ *.ktx2 filter=lfs diff=lfs merge=lfs -text
11
+ *.hdr filter=lfs diff=lfs merge=lfs -text
12
+ *.exr filter=lfs diff=lfs merge=lfs -text
13
+ *.wav filter=lfs diff=lfs merge=lfs -text
14
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
15
+ *.ogg filter=lfs diff=lfs merge=lfs -text
16
+ *.flac filter=lfs diff=lfs merge=lfs -text
17
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
18
+ *.ttf filter=lfs diff=lfs merge=lfs -text
19
+ *.otf filter=lfs diff=lfs merge=lfs -text
20
+ *.woff2 filter=lfs diff=lfs merge=lfs -text
21
+ *.ogt text eol=lf
22
+ *.ts text eol=lf
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "origin-game",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "og dev .",
8
+ "start": "og run .",
9
+ "build": "og build .",
10
+ "publish-build": "og build . --publish",
11
+ "cook": "og cook .",
12
+ "check": "og check .",
13
+ "test": "og test ."
14
+ },
15
+ "dependencies": {
16
+ "@origingame/engine": "0.1.0"
17
+ }
18
+ }
@@ -0,0 +1,25 @@
1
+ type project
2
+ version 1
3
+ ---
4
+ # The project manifest (docs/design.md §2.5): `og run`, `og build`, `og cook`,
5
+ # `og dev` and `og test` read it. `npm create @origingame/game` fills in the
6
+ # name and id.
7
+ name "Origin Game"
8
+ id "origin-game"
9
+ # The engine this game is written against (design §9: upgrades are explicit).
10
+ engine "0.1.0"
11
+ entry "src/main.ts"
12
+ # 2d (orthographic camera, sprites, 2D physics) or 3d.
13
+ profile "3d"
14
+ tick 60
15
+ seed 1
16
+ scenes {
17
+ main "scenes/main.ogt"
18
+ }
19
+ scene main
20
+ publish {
21
+ # `og build --publish` keeps only the player-facing probe members
22
+ # (hello, tick, state, pick, entity, input, capture).
23
+ probe player
24
+ out "dist"
25
+ }
@@ -0,0 +1,246 @@
1
+ // The game entry: its default export is og.game(...). `og run .` runs it
2
+ // headless with the probe; `og dev .` reloads it on every save; `og build .`
3
+ // bundles it for the play page.
4
+ //
5
+ // This is the hello of docs/design.md §3.2 (Health, Velocity, Move) grown
6
+ // into a scene: scenes/main.ogt (cooked from assets/scenes/main.ogt) spawns
7
+ // the ground, the dropship and the trickster before the first tick; `start`
8
+ // gives the ground its mesh and collider, drops a crate above it, puts the
9
+ // camera, the UI font and the string table (assets/strings/en.ogt) in
10
+ // place. The Start button of the menu panel (or S or Enter) starts the
11
+ // trickster spinning and lets the crate fall.
12
+ //
13
+ // A guard walks the yard: a state machine in assets/ai/guard.ogt (og.ai)
14
+ // patrols its post on the navmesh baked from assets/nav/yard.ogt (og.nav),
15
+ // sees the trickster only inside its view cone and not through the wall,
16
+ // raises the alarm and chases it, then searches and goes back.
17
+ //
18
+ // The frame's look is data: GameDesc.look names a file under assets/looks/
19
+ // that extends a preset of the style catalogue, applied before start runs.
20
+
21
+ import { og, defineComponent, defineResource, defineSystem, bool, f32, Vector3, SHAPE_BOX } from "@origingame/engine";
22
+ import type { World } from "@origingame/engine";
23
+
24
+ export const Health = defineComponent("Health", {
25
+ hp: f32(100, { min: 0, max: 1000, tunable: true, label: "Health" }),
26
+ max: f32(100),
27
+ });
28
+
29
+ export const Velocity = defineComponent("Velocity", { v: Vector3() });
30
+
31
+ /** Turns an entity about +Y; 0 until the player starts. */
32
+ export const Spin = defineComponent("Spin", {
33
+ speed: f32(0, { min: -10, max: 10, step: 0.1, unit: "rad", tunable: true, label: "Spin speed" }),
34
+ target: f32(1.5, { min: -10, max: 10, tunable: true, label: "Spin when started" }),
35
+ });
36
+
37
+ /** Whether the player has pressed Start. */
38
+ export const Run = defineResource("Run", { started: bool(), chimed: bool() });
39
+
40
+ /** The guard's alarms, raised by its machine's `alarm` command. */
41
+ export const Alarm = defineComponent("Alarm", { raised: f32(0) });
42
+
43
+ export const Move = defineSystem("Move", { reads: [Velocity], writes: [og.Transform] }, (q, time) => {
44
+ for (const a of q.archetypes()) {
45
+ const p = a.column(og.Transform).position;
46
+ const v = a.column(Velocity).v;
47
+ for (let i = 0; i < a.count; i++) {
48
+ p[i * 3] += v[i * 3] * time.dt;
49
+ p[i * 3 + 1] += v[i * 3 + 1] * time.dt;
50
+ p[i * 3 + 2] += v[i * 3 + 2] * time.dt;
51
+ }
52
+ }
53
+ });
54
+
55
+ /**
56
+ * The menu panel: the title, the trickster's state and the Start button.
57
+ * A click on Start (or S or Enter) starts the run; the button then reads
58
+ * "Started" and stays inert.
59
+ */
60
+ export const Menu = defineSystem("Menu", { reads: [Spin, og.Input], writes: [Run] }, (q, _time, world) => {
61
+ const run = world.resource(Run);
62
+ const input = world.resource(og.Input);
63
+ if (!run.ok || !input.ok) return;
64
+ let speed = 0;
65
+ for (const a of q.archetypes()) if (a.count > 0) speed = a.column(Spin).speed[0]!;
66
+ const started = run.value.started;
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
+ 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" } });
70
+ const start = og.ui.button("Start", og.i18n.t(world, started ? "menu.started" : "menu.start"), { variant: "primary", size: "large", disabled: started });
71
+ if (!started && (start.clicked || input.value.pressed("KeyS") || input.value.pressed("Enter"))) run.value.started = true;
72
+ }));
73
+ });
74
+
75
+ /** Once started, every Spin turns at its target speed. */
76
+ export const StartSpin = defineSystem("StartSpin", { reads: [Run], writes: [Spin], after: ["Menu"] }, (q, _time, world) => {
77
+ const run = world.resource(Run);
78
+ if (!run.ok || !run.value.started) return;
79
+ for (const a of q.archetypes()) {
80
+ const s = a.column(Spin);
81
+ for (let k = 0; k < a.count; k++) if (s.speed[k] === 0) s.speed[k] = s.target[k]!;
82
+ }
83
+ });
84
+
85
+ /** Once started, held bodies (gravityScale 0) fall. */
86
+ export const Drop = defineSystem("Drop", { reads: [Run], writes: [og.RigidBody], after: ["Menu"] }, (q, _time, world) => {
87
+ const run = world.resource(Run);
88
+ if (!run.ok || !run.value.started) return;
89
+ for (const a of q.archetypes()) {
90
+ const g = a.column(og.RigidBody).gravityScale;
91
+ for (let k = 0; k < a.count; k++) if (g[k] === 0) g[k] = 1;
92
+ }
93
+ });
94
+
95
+ /** Once started, the crate's blip plays once (an AudioSource inserted held, released here). */
96
+ export const Chime = defineSystem("Chime", { writes: [Run, og.AudioSource], after: ["Menu"] }, (q, _time, world) => {
97
+ const run = world.resource(Run);
98
+ if (!run.ok || !run.value.started || run.value.chimed) return;
99
+ run.value.chimed = true;
100
+ for (const a of q.archetypes()) a.column(og.AudioSource).playing.fill(1);
101
+ });
102
+
103
+ /** Rotates by Spin.speed about +Y: q' = q * (axis-angle about Y). */
104
+ export const Rotate = defineSystem("Rotate", { reads: [Spin], writes: [og.Transform], after: ["StartSpin"] }, (q, time) => {
105
+ for (const a of q.archetypes()) {
106
+ const r = a.column(og.Transform).quaternion;
107
+ const s = a.column(Spin).speed;
108
+ for (let i = 0; i < a.count; i++) {
109
+ const half = (s[i] * time.dt) / 2;
110
+ // Small-angle rotation, renormalised: deterministic arithmetic only.
111
+ const sy = half - (half * half * half) / 6;
112
+ const cw = 1 - (half * half) / 2;
113
+ const x = r[i * 4], y = r[i * 4 + 1], z = r[i * 4 + 2], w = r[i * 4 + 3];
114
+ const nx = x * cw - z * sy, ny = y * cw + w * sy, nz = z * cw + x * sy, nw = w * cw - y * sy;
115
+ const n = Math.sqrt(nx * nx + ny * ny + nz * nz + nw * nw);
116
+ r[i * 4] = nx / n;
117
+ r[i * 4 + 1] = ny / n;
118
+ r[i * 4 + 2] = nz / n;
119
+ r[i * 4 + 3] = nw / n;
120
+ }
121
+ }
122
+ });
123
+
124
+ function spawnWave(world: World, count: number): void {
125
+ const ship = og.load.gltf(world, "models/dropship.glb");
126
+ if (!ship.ok) throw new Error(ship.reason);
127
+ for (let i = 0; i < count; i++) {
128
+ const e = world.instantiate(ship.value, { name: `wave-${world.tick}-${i}`, position: { x: -4 + i * 1.5, y: 4, z: -3 } });
129
+ if (!e.ok) throw new Error(e.reason);
130
+ world.insert(e.value, Velocity, { v: { x: 0, y: -0.5, z: 0 } });
131
+ }
132
+ }
133
+
134
+ function must<T>(r: { ok: true; value: T } | { ok: false; reason: string }): T {
135
+ if (!r.ok) throw new Error(r.reason);
136
+ return r.value;
137
+ }
138
+
139
+ export default og.game({
140
+ tick: 60,
141
+ seed: 1,
142
+ scenes: { main: "scenes/main.ogt" },
143
+ // The art direction as data (og-taste §12): applied after the scene
144
+ // spawns and before start, which may still change any of it.
145
+ look: "looks/origin-game.ogt",
146
+ resources: [Run],
147
+ systems: [Move, Menu, StartSpin, Drop, Chime, Rotate],
148
+ // MSAA keeps world-space sprites and text sharp; TAA would blur them across
149
+ // frames. The UI draws over the finished frame either way.
150
+ render: { antialias: "msaa4" },
151
+ start(world) {
152
+ // The camera looks down -Z at the scene from in front.
153
+ const camera = must(world.resource(og.Camera));
154
+ camera.position = { x: 0.4, y: 1.8, z: 8 };
155
+ camera.quaternion = { x: 0, y: 0, z: 0, w: 1 };
156
+ must(world.resource(og.RenderSettings)).sky = true;
157
+
158
+ // The ground: a 30 m slab whose top is y = 0, drawn and collided with.
159
+ const ground = world.find("ground");
160
+ if (ground !== null) {
161
+ const slab = must(og.render.boxGeometry(world, { width: 30, height: 0.2, depth: 30 }));
162
+ const stone = must(og.render.standardMaterial(world, { color: { r: 0.18, g: 0.2, b: 0.24 }, roughness: 0.95 }));
163
+ world.set(ground, og.Transform, { position: { x: 0, y: -0.1, z: 0 } });
164
+ world.insert(ground, og.Mesh, { geometry: slab, material: stone, receiveShadow: true });
165
+ world.insert(ground, og.Collider, { shape: SHAPE_BOX, size: { x: 30, y: 0.2, z: 30 } });
166
+ }
167
+
168
+ // The crate: a dynamic body held in the air (gravityScale 0) until Start.
169
+ const cube = must(og.render.boxGeometry(world, {}));
170
+ const amber = must(og.render.standardMaterial(world, { color: { r: 0.9, g: 0.55, b: 0.08 }, roughness: 0.6 }));
171
+ const crate = must(world.spawn({ name: "crate", position: { x: -2.4, y: 4, z: 0.5 } }));
172
+ world.insert(crate, og.Mesh, { geometry: cube, material: amber, castShadow: true, receiveShadow: true });
173
+ world.insert(crate, og.RigidBody, { gravityScale: 0 });
174
+ world.insert(crate, og.Collider, { shape: SHAPE_BOX });
175
+ const blip = og.load.sound(world, "audio/blip.wav");
176
+ if (blip.ok) world.insert(crate, og.AudioSource, { sound: blip.value, playing: false, spatial: true });
177
+
178
+ const trickster = world.find("trickster");
179
+ if (trickster !== null) {
180
+ world.insert(trickster, Spin);
181
+ world.insert(trickster, Health);
182
+ // What the guard looks for: team 1, looked at 1 m above its feet.
183
+ world.insert(trickster, og.Perceivable, { team: 1, eyeHeight: 1 });
184
+ }
185
+
186
+ // The wall the navmesh was baked around (assets/nav/yard.ogt): drawn, and solid to the guard's sight.
187
+ const wall = must(world.spawn({ name: "wall", position: { x: -3, y: 1, z: -2 } }));
188
+ const slabGeo = must(og.render.boxGeometry(world, { width: 0.6, height: 2, depth: 6 }));
189
+ const plaster = must(og.render.standardMaterial(world, { color: { r: 0.55, g: 0.52, b: 0.48 }, roughness: 0.9 }));
190
+ world.insert(wall, og.Mesh, { geometry: slabGeo, material: plaster, castShadow: true, receiveShadow: true });
191
+ world.insert(wall, og.Collider, { shape: SHAPE_BOX, size: { x: 0.6, y: 2, z: 6 } });
192
+
193
+ // The guard: the walker model, moved by og.nav on the baked navmesh and run by og.ai's machine.
194
+ const yard = must(og.nav.load(world, "nav/yard.ogt"));
195
+ const mind = must(og.ai.load(world, "ai/guard.ogt"));
196
+ const walker = must(og.load.gltf(world, "models/walker.glb"));
197
+ const guard = must(world.instantiate(walker, { name: "guard", position: { x: -6, y: 0, z: -3 } }));
198
+ // Facing east (+X), towards the wall: its view cone is 120° around the way it faces until it moves.
199
+ world.set(guard, og.Transform, { quaternion: { x: 0, y: Math.SQRT1_2, z: 0, w: Math.SQRT1_2 } });
200
+ world.insert(guard, og.NavAgent, { nav: yard.mesh, speed: 1.5, acceleration: 12, radius: 0.4, faceMovement: true, turnSpeed: 8 });
201
+ world.insert(guard, og.AiAgent, { behaviour: mind.behaviour });
202
+ world.insert(guard, og.Perception, { sight: 9, fov: 120, eyeHeight: 1.6, team: 2 });
203
+ world.insert(guard, Alarm);
204
+ // Every string the menu shows (og-i18n §1): load each locale's table here.
205
+ must(og.i18n.load(world, "strings/en.ogt"));
206
+ const font = og.load.font(world, "fonts/NotoSansSC-Regular-subset.ttf");
207
+ // A press answers with a sound as well as its look (og-taste §6): the `click` preset, synthesised by og cook.
208
+ const click = og.load.sound(world, "audio/click.ogt");
209
+ og.ui.configure(world, { ...(font.ok ? { font: font.value } : {}), ...(click.ok ? { sounds: { press: click.value } } : {}) });
210
+ },
211
+ commands: {
212
+ spawn_wave: (world, args) => spawnWave(world, Number(args[0] ?? 3)),
213
+ // The guard's machine raises it on entering `alert`; og.ai passes the guard's handle first.
214
+ alarm: (world, args) => {
215
+ const guard = Number(args[0]) as never;
216
+ const a = must(world.get(guard, Alarm));
217
+ must(world.set(guard, Alarm, { raised: a.raised + 1 }) as never);
218
+ },
219
+ /** `lure:<x>:<z>`: moves the trickster on the ground. */
220
+ lure: (world, args) => {
221
+ const t = world.find("trickster");
222
+ if (t === null) throw new Error("no trickster");
223
+ must(world.set(t, og.Transform, { position: { x: Number(args[0]), y: 0, z: Number(args[1]) } }) as never);
224
+ },
225
+ },
226
+ commandHelp: {
227
+ spawn_wave: { usage: "[count]", doc: "Drop that many dropships (3 by default)." },
228
+ alarm: { usage: "<guard>", doc: "The guard's state machine raises it on entering alert; og.ai passes the guard's handle." },
229
+ lure: { usage: "<x>:<z>", doc: "Move the trickster on the ground." },
230
+ },
231
+ facts: (world) => {
232
+ const run = world.resource(Run);
233
+ const trickster = world.find("trickster");
234
+ const spin = trickster === null ? null : world.get(trickster, Spin);
235
+ const crate = world.find("crate");
236
+ const at = crate === null ? null : world.get(crate, og.Transform);
237
+ const guard = world.find("guard");
238
+ const mind = guard === null ? null : (og.ai.describe(world, guard) as { state: string } | null);
239
+ return {
240
+ started: run.ok && run.value.started,
241
+ guard: mind?.state ?? null,
242
+ spin: spin?.ok ? spin.value.speed : null,
243
+ crateY: at?.ok ? at.value.position.y : null,
244
+ };
245
+ },
246
+ });
@@ -0,0 +1,67 @@
1
+ // The guard (assets/ai/guard.ogt, a state machine on og.ai; the navmesh
2
+ // cooked from assets/nav/yard.ogt, walked by og.nav). Facing east at its
3
+ // first post, it does not see the trickster behind the wall (in range, in
4
+ // its cone) nor behind it (in range, in the open); in front of it, it does,
5
+ // raises the alarm once and chases; when the trickster slips behind the wall
6
+ // it searches where it last saw it and returns to its patrol 3 s later.
7
+ import { playtest } from "@origingame/engine/playtest";
8
+
9
+ interface AiDump {
10
+ behaviour: string;
11
+ kind: string;
12
+ state: string;
13
+ sees: boolean;
14
+ }
15
+ interface EntityDump {
16
+ components: Record<string, Record<string, unknown>>;
17
+ }
18
+
19
+ const at = (run: { json<T>(f: string): T }, f: string) => run.json<EntityDump>(f).components["og.Transform"]!["position"] as number[];
20
+
21
+ export default playtest({
22
+ name: "the guard patrols, sees inside its cone and not through the wall, chases, searches and returns",
23
+ commands: [
24
+ "0.3:lure:0:-3",
25
+ "0.4:dump_ai:guard:walled.json",
26
+ "0.4:dump_entity:guard:g0.json",
27
+ "0.5:lure:-6:-7",
28
+ "0.7:dump_ai:guard:behind.json",
29
+ "1.0:lure:-4:-1",
30
+ "1.1:dump_ai:guard:front.json",
31
+ "2.2:dump_entity:guard:chasing.json",
32
+ "2.2:dump_ai:guard:chase.json",
33
+ "2.3:lure:-1:-4",
34
+ "2.6:dump_ai:guard:lost.json",
35
+ "6.0:dump_ai:guard:back.json",
36
+ "6.0:dump_entity:guard:end.json",
37
+ "6.1:quit",
38
+ ].join(";"),
39
+ check(run, t) {
40
+ t.equal(run.warnings.join("; "), "", "the script ran without warnings");
41
+ const walled = run.json<AiDump>("walled.json");
42
+ t.equal(walled.behaviour, "guard", "the guard runs assets/ai/guard.ogt");
43
+ t.equal(walled.kind, "machine", "a state machine");
44
+ t.equal(walled.state, "patrol", "it patrols");
45
+ t.equal(walled.sees, false, "the wall hides the trickster 6 m ahead, inside its cone and its 9 m sight");
46
+ const g0 = at(run, "g0.json");
47
+ t.ok(Math.abs(g0[1]!) < 0.2, `it stands on the navmesh's surface (y ${g0[1]!.toFixed(3)})`);
48
+ const behind = run.json<AiDump>("behind.json");
49
+ t.equal(behind.sees, false, "4 m behind it, in the open, the trickster is outside its 120° cone");
50
+ t.equal(behind.state, "patrol", "so it keeps patrolling");
51
+
52
+ const front = run.json<AiDump>("front.json");
53
+ t.equal(front.sees, true, "in front of it the trickster is seen");
54
+ t.equal(front.state, "alert", "and the guard is alert");
55
+ const chase = run.json<AiDump>("chase.json");
56
+ t.equal(chase.state, "alert", "still chasing a second later");
57
+ const c = at(run, "chasing.json");
58
+ const d = Math.hypot(c[0]! + 4, c[2]! + 1);
59
+ t.ok(d < 2.0, `it closed in on the trickster (${d.toFixed(2)} m)`);
60
+
61
+ const lost = run.json<AiDump>("lost.json");
62
+ t.equal(lost.sees, false, "behind the wall the trickster is hidden");
63
+ t.equal(lost.state, "search", "so the guard searches");
64
+ t.equal(run.json<AiDump>("back.json").state, "patrol", "three seconds later it is back on patrol");
65
+ t.equal(run.json<EntityDump>("end.json").components["Alarm"]!["raised"], 1, "the alarm was raised once, on entering alert");
66
+ },
67
+ });
@@ -0,0 +1,43 @@
1
+ // The template's playtest, run by `og test` through `og run --headless
2
+ // --commands`: a tap on the menu's Start button (found by its UI id, no key
3
+ // fallback) starts the trickster spinning and drops the crate onto the
4
+ // ground; the frame, the dumps and the UI tree are written.
5
+ import { playtest } from "@origingame/engine/playtest";
6
+
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
+ 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
+ },
43
+ });
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2022"],
7
+ "types": [],
8
+ "strict": true,
9
+ "exactOptionalPropertyTypes": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "isolatedModules": true,
12
+ "verbatimModuleSyntax": true,
13
+ "allowImportingTsExtensions": true,
14
+ "noEmit": true
15
+ },
16
+ "include": ["src/**/*.ts", "tests/**/*.ts"]
17
+ }