@jgengine/core 0.11.0 → 0.13.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 (256) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/ai/populationDirector.d.ts +103 -0
  3. package/dist/ai/populationDirector.js +190 -0
  4. package/dist/ai/pursuit.d.ts +56 -0
  5. package/dist/ai/pursuit.js +53 -0
  6. package/dist/authoring.d.ts +1 -1
  7. package/dist/authoring.js +1 -1
  8. package/dist/combat/effects.d.ts +11 -4
  9. package/dist/combat/effects.js +24 -17
  10. package/dist/combat/magazine.d.ts +13 -0
  11. package/dist/combat/magazine.js +27 -0
  12. package/dist/combat/vfxPresets.d.ts +176 -0
  13. package/dist/combat/vfxPresets.js +74 -0
  14. package/dist/combat/weaponFire.d.ts +114 -0
  15. package/dist/combat/weaponFire.js +96 -0
  16. package/dist/combat.d.ts +5 -2
  17. package/dist/combat.js +4 -1
  18. package/dist/devtools/controls.d.ts +38 -0
  19. package/dist/devtools/controls.js +181 -0
  20. package/dist/devtools/devtools.d.ts +5 -197
  21. package/dist/devtools/devtools.js +38 -774
  22. package/dist/devtools/discover.d.ts +32 -0
  23. package/dist/devtools/discover.js +240 -0
  24. package/dist/devtools/fallbackSeams.d.ts +50 -0
  25. package/dist/devtools/fallbackSeams.js +111 -0
  26. package/dist/devtools/frame.d.ts +15 -0
  27. package/dist/devtools/frame.js +247 -0
  28. package/dist/devtools/logs.d.ts +15 -0
  29. package/dist/devtools/logs.js +86 -0
  30. package/dist/devtools/overrides.d.ts +16 -0
  31. package/dist/devtools/overrides.js +66 -0
  32. package/dist/devtools/types.d.ts +212 -0
  33. package/dist/devtools/types.js +1 -0
  34. package/dist/devtools/urlFlags.d.ts +22 -0
  35. package/dist/devtools/urlFlags.js +62 -0
  36. package/dist/economy/auctionBook.d.ts +122 -0
  37. package/dist/economy/auctionBook.js +213 -0
  38. package/dist/economy/priceHistory.d.ts +44 -0
  39. package/dist/economy/priceHistory.js +89 -0
  40. package/dist/economy/unlockPoints.d.ts +92 -0
  41. package/dist/economy/unlockPoints.js +103 -0
  42. package/dist/editor/commandApply.d.ts +5 -0
  43. package/dist/editor/commandApply.js +755 -0
  44. package/dist/editor/commands.d.ts +48 -3
  45. package/dist/editor/commands.js +40 -754
  46. package/dist/editor/directives.d.ts +94 -0
  47. package/dist/editor/directives.js +206 -0
  48. package/dist/editor/document.d.ts +37 -2
  49. package/dist/editor/document.js +422 -6
  50. package/dist/editor/entityCatalog.d.ts +42 -0
  51. package/dist/editor/entityCatalog.js +101 -0
  52. package/dist/editor/environment.d.ts +74 -0
  53. package/dist/editor/environment.js +169 -0
  54. package/dist/editor/index.d.ts +26 -1
  55. package/dist/editor/index.js +8 -1
  56. package/dist/editor/minimap.d.ts +31 -0
  57. package/dist/editor/minimap.js +73 -0
  58. package/dist/editor/streamer.d.ts +66 -0
  59. package/dist/editor/streamer.js +68 -0
  60. package/dist/editor/types.d.ts +143 -0
  61. package/dist/editor/world.d.ts +136 -0
  62. package/dist/editor/world.js +303 -0
  63. package/dist/game/breeding.d.ts +161 -0
  64. package/dist/game/breeding.js +181 -0
  65. package/dist/game/cameraConfig.d.ts +451 -0
  66. package/dist/game/cameraConfig.js +1 -0
  67. package/dist/game/clipRoles.d.ts +51 -0
  68. package/dist/game/clipRoles.js +142 -0
  69. package/dist/game/defineGame.d.ts +16 -9
  70. package/dist/game/defineGame.js +14 -6
  71. package/dist/game/defineSystem.d.ts +2 -0
  72. package/dist/game/defineSystem.js +2 -0
  73. package/dist/game/events.d.ts +28 -0
  74. package/dist/game/partAnimation.d.ts +78 -0
  75. package/dist/game/partAnimation.js +147 -0
  76. package/dist/game/playableGame.d.ts +72 -440
  77. package/dist/game/playableGame.js +1 -1
  78. package/dist/game/progression.d.ts +35 -0
  79. package/dist/game/progression.js +22 -1
  80. package/dist/game/quest.js +1 -3
  81. package/dist/game/tribe.d.ts +184 -0
  82. package/dist/game/tribe.js +432 -0
  83. package/dist/gameplay.d.ts +3 -1
  84. package/dist/gameplay.js +3 -1
  85. package/dist/inventory/encumbrance.d.ts +69 -0
  86. package/dist/inventory/encumbrance.js +68 -0
  87. package/dist/inventory/inventoryModel.d.ts +24 -8
  88. package/dist/inventory/inventoryModel.js +47 -8
  89. package/dist/item/durability.js +1 -3
  90. package/dist/meta/changelog.d.ts +1 -1
  91. package/dist/meta/changelog.js +48 -1
  92. package/dist/movement/movementModel.d.ts +15 -1
  93. package/dist/movement/movementModel.js +33 -15
  94. package/dist/movement/playerMovement.js +102 -2
  95. package/dist/multiplayer/combatSnapshot.js +13 -8
  96. package/dist/multiplayer/presenceModel.d.ts +2 -0
  97. package/dist/multiplayer/presenceModel.js +8 -0
  98. package/dist/physics/drivableVehicle.d.ts +2 -0
  99. package/dist/physics/drivableVehicle.js +1 -1
  100. package/dist/physics/flightDynamics.d.ts +82 -0
  101. package/dist/physics/flightDynamics.js +165 -0
  102. package/dist/physics/gravityField.d.ts +25 -0
  103. package/dist/physics/gravityField.js +41 -0
  104. package/dist/physics/kinematicVehicle.d.ts +87 -0
  105. package/dist/physics/kinematicVehicle.js +193 -11
  106. package/dist/physics/physicsWorld.d.ts +26 -0
  107. package/dist/physics/physicsWorld.js +109 -117
  108. package/dist/physics/vehicleObstacles.d.ts +44 -0
  109. package/dist/physics/vehicleObstacles.js +115 -0
  110. package/dist/random/rng.d.ts +4 -1
  111. package/dist/random/rng.js +4 -1
  112. package/dist/runtime/adapter.d.ts +13 -0
  113. package/dist/runtime/adapter.js +13 -0
  114. package/dist/runtime/context/combat.d.ts +51 -0
  115. package/dist/runtime/context/combat.js +131 -0
  116. package/dist/runtime/context/combatFx.js +15 -5
  117. package/dist/runtime/context/deathLoot.d.ts +30 -0
  118. package/dist/runtime/context/deathLoot.js +39 -0
  119. package/dist/runtime/context/player.d.ts +48 -0
  120. package/dist/runtime/context/player.js +125 -0
  121. package/dist/runtime/context/scene.d.ts +60 -0
  122. package/dist/runtime/context/scene.js +329 -0
  123. package/dist/runtime/context/snapshotCodecs.d.ts +12 -0
  124. package/dist/runtime/context/snapshotCodecs.js +26 -0
  125. package/dist/runtime/descriptors/baseline.js +26 -3
  126. package/dist/runtime/descriptors/features.d.ts +5 -0
  127. package/dist/runtime/descriptors/features.js +20 -2
  128. package/dist/runtime/gameContext.d.ts +2 -428
  129. package/dist/runtime/gameContext.js +133 -500
  130. package/dist/runtime/gameContextTypes.d.ts +500 -0
  131. package/dist/runtime/gameContextTypes.js +1 -0
  132. package/dist/runtime/headlessRunner.d.ts +17 -2
  133. package/dist/runtime/headlessRunner.js +15 -0
  134. package/dist/runtime/hostPolicy.d.ts +51 -0
  135. package/dist/runtime/hostPolicy.js +68 -0
  136. package/dist/runtime/hostedGameRunner.d.ts +3 -1
  137. package/dist/runtime/hostedGameRunner.js +1 -0
  138. package/dist/runtime/hostedWorldSession.d.ts +3 -1
  139. package/dist/runtime/hostedWorldSession.js +1 -0
  140. package/dist/runtime/worldSnapshot.d.ts +13 -1
  141. package/dist/runtime/worldSnapshot.js +15 -3
  142. package/dist/scene/assetCatalog.d.ts +7 -0
  143. package/dist/scene/assetSpace.js +1 -3
  144. package/dist/scene/authoredTriggers.d.ts +50 -0
  145. package/dist/scene/authoredTriggers.js +114 -0
  146. package/dist/scene/builtinSceneKinds.js +8 -3
  147. package/dist/scene/colliders.d.ts +79 -0
  148. package/dist/scene/colliders.js +170 -0
  149. package/dist/scene/collisionMesh.d.ts +94 -0
  150. package/dist/scene/collisionMesh.js +699 -0
  151. package/dist/scene/companion.d.ts +147 -0
  152. package/dist/scene/companion.js +193 -0
  153. package/dist/scene/entityStats.d.ts +7 -9
  154. package/dist/scene/entityStats.js +19 -15
  155. package/dist/scene/sceneKinds.d.ts +16 -0
  156. package/dist/scene/sceneKinds.js +4 -0
  157. package/dist/scene/sceneRaycast.js +15 -0
  158. package/dist/stats/spawnLevelStats.d.ts +110 -0
  159. package/dist/stats/spawnLevelStats.js +140 -0
  160. package/dist/stats/statModifiers.d.ts +16 -0
  161. package/dist/stats/statModifiers.js +30 -1
  162. package/dist/stats/statPool.d.ts +70 -0
  163. package/dist/stats/statPool.js +62 -0
  164. package/dist/store/changeSignal.d.ts +3 -0
  165. package/dist/store/changeSignal.js +2 -0
  166. package/dist/store/observableKeyedStore.d.ts +2 -0
  167. package/dist/store/observableKeyedStore.js +1 -0
  168. package/dist/survival/decayMeter.js +1 -3
  169. package/dist/survival/regionHealth.js +1 -3
  170. package/dist/ui/hudLayout.d.ts +5 -0
  171. package/dist/ui/hudLayout.js +17 -1
  172. package/dist/ui/panelModel.d.ts +120 -0
  173. package/dist/ui/panelModel.js +168 -0
  174. package/dist/ui.d.ts +1 -0
  175. package/dist/ui.js +1 -0
  176. package/dist/world/authoredEntities.d.ts +29 -0
  177. package/dist/world/authoredEntities.js +29 -0
  178. package/dist/world/authoredObjects.d.ts +15 -1
  179. package/dist/world/authoredObjects.js +13 -1
  180. package/dist/world/authoredSpawn.d.ts +39 -0
  181. package/dist/world/authoredSpawn.js +37 -0
  182. package/dist/world/buildSockets.d.ts +152 -0
  183. package/dist/world/buildSockets.js +188 -0
  184. package/dist/world/buildingLots.d.ts +84 -0
  185. package/dist/world/buildingLots.js +119 -0
  186. package/dist/world/buildings.d.ts +6 -0
  187. package/dist/world/cityBlocks.d.ts +152 -0
  188. package/dist/world/cityBlocks.js +670 -0
  189. package/dist/world/cityContent.d.ts +77 -0
  190. package/dist/world/cityContent.js +261 -0
  191. package/dist/world/cityGenerator.d.ts +41 -0
  192. package/dist/world/cityGenerator.js +58 -0
  193. package/dist/world/cityGeometry.d.ts +114 -0
  194. package/dist/world/cityGeometry.js +573 -0
  195. package/dist/world/cityKind.d.ts +314 -0
  196. package/dist/world/cityKind.js +1578 -0
  197. package/dist/world/environmentSummary.js +57 -1
  198. package/dist/world/features.d.ts +53 -5
  199. package/dist/world/features.js +15 -3
  200. package/dist/world/grassKind.js +2 -2
  201. package/dist/world/markers.d.ts +50 -4
  202. package/dist/world/markers.js +49 -0
  203. package/dist/world/massing.js +1 -1
  204. package/dist/world/minimapBake.d.ts +78 -0
  205. package/dist/world/minimapBake.js +208 -0
  206. package/dist/world/minimapTrack.d.ts +17 -0
  207. package/dist/world/minimapTrack.js +22 -0
  208. package/dist/world/place.d.ts +166 -0
  209. package/dist/world/place.js +96 -0
  210. package/dist/world/placeAsset.js +3 -1
  211. package/dist/world/poleLineKind.d.ts +40 -0
  212. package/dist/world/poleLineKind.js +97 -0
  213. package/dist/world/polyline.js +9 -2
  214. package/dist/world/resourceNode.d.ts +109 -0
  215. package/dist/world/resourceNode.js +140 -0
  216. package/dist/world/roads.d.ts +19 -2
  217. package/dist/world/roads.js +60 -3
  218. package/dist/world/scatter.js +2 -20
  219. package/dist/world/streetGenerator.d.ts +159 -0
  220. package/dist/world/streetGenerator.js +684 -0
  221. package/dist/world/streets.d.ts +103 -1
  222. package/dist/world/streets.js +273 -0
  223. package/dist/world/terraform.js +58 -88
  224. package/dist/world/terrain.d.ts +65 -1
  225. package/dist/world/terrain.js +119 -2
  226. package/dist/world.d.ts +14 -5
  227. package/dist/world.js +12 -3
  228. package/package.json +1 -1
  229. package/skills/game-design/SKILL.md +28 -0
  230. package/skills/game-design/agents/openai.yaml +4 -0
  231. package/skills/game-design/references/application-playbook.md +170 -0
  232. package/skills/game-design/references/field-guide.md +288 -0
  233. package/skills/jgengine/SKILL.md +8 -4
  234. package/skills/jgengine/api.md +182 -81
  235. package/skills/jgengine/capabilities.md +104 -2
  236. package/skills/jgengine/recipes/minimal-game.md +88 -0
  237. package/skills/jgengine-combat/SKILL.md +19 -1
  238. package/skills/jgengine-combat/api.md +75 -2
  239. package/skills/jgengine-combat/capabilities.md +61 -1
  240. package/skills/jgengine-combat/recipes/portable-damage-effects.md +197 -0
  241. package/skills/jgengine-combat/recipes/portable-runtime-state.md +154 -0
  242. package/skills/jgengine-combat/recipes/portable-stat-pools.md +122 -0
  243. package/skills/jgengine-combat/recipes/portable-weapon-plumbing.md +156 -0
  244. package/skills/jgengine-combat/recipes/visible-attacks.md +81 -0
  245. package/skills/jgengine-combat/reference.md +33 -4
  246. package/skills/jgengine-gameplay/SKILL.md +8 -0
  247. package/skills/jgengine-gameplay/api.md +182 -26
  248. package/skills/jgengine-gameplay/capabilities.md +96 -2
  249. package/skills/jgengine-gameplay/recipes/portable-xp-leveling.md +168 -0
  250. package/skills/jgengine-gameplay/reference-systems.md +10 -5
  251. package/skills/jgengine-world/SKILL.md +13 -0
  252. package/skills/jgengine-world/api.md +453 -21
  253. package/skills/jgengine-world/capabilities.md +112 -2
  254. package/skills/jgengine-world/recipes/commanding-entities.md +128 -0
  255. package/skills/jgengine-world/reference.md +43 -4
  256. package/skills/jgengine/reference-cartridge.md +0 -72
@@ -1,4 +1,4 @@
1
- import type { BiomeBand, EnvironmentWorldFeature, TerrainDetailConfig, TerrainEnvironmentConfig, TerrainEnvironmentDescriptor, TerrainIslandDescriptor, TerrainMaterial, TerrainMaterialMaps, WorldBounds, WorldFeature } from "./features.js";
1
+ import type { BiomeBand, EnvironmentWorldFeature, RoadEnvironmentDescriptor, TerrainDetailConfig, TerrainEnvironmentConfig, TerrainEnvironmentDescriptor, TerrainIslandDescriptor, TerrainMaterial, TerrainMaterialMaps, WorldBounds, WorldFeature } from "./features.js";
2
2
  import type { AvoidZone } from "./geometry.js";
3
3
  import { type TerrainPathProfile } from "./pathTerrain.js";
4
4
  import type { TerraformSnapshot } from "./terraform.js";
@@ -107,6 +107,25 @@ export declare function flattenFieldAround(base: TerrainField, zones: readonly A
107
107
  * through the one seam every consumer already reads.
108
108
  * @internal
109
109
  */
110
+ /**
111
+ * Drapes each `road()` ribbon's `elevation` onto the ground so a body standing on a road snaps to the
112
+ * road *surface* the renderer draws (`sampleHeight + elevation`), not the bare terrain beneath it. Without
113
+ * this the ground field and {@link RoadRibbons}/{@link CityRenderer} disagree by `elevation` per road, and
114
+ * anything grounded on a road — the player, NPCs, spawns via `groundHeightAt` — sinks by that offset into
115
+ * the asphalt. Overlapping ribbons (intersections) take the highest lift. Only `sampleHeight` is draped:
116
+ * the road ribbons are flat, so `sampleNormal` stays the smooth terrain normal — draping it too would spoof
117
+ * a near-vertical slope at every curb edge and trip slope-slide.
118
+ * @internal — reached through `environment({ roads })`; not called directly by games.
119
+ */
120
+ export declare function roadDrapedField(base: TerrainField, roads: readonly RoadEnvironmentDescriptor[]): TerrainField;
121
+ /**
122
+ * The full ground field for an environment world: base `terrain` composed with any `islands`, then
123
+ * any authored `sculpt` snapshot, then any `clearings`, then any `roads` draped on top — so an
124
+ * editor-sculpted heightfield drives both the rendered mesh and player collision, gameplay spots
125
+ * stay level, and anything grounded on a road stands on the drawn asphalt rather than the bare
126
+ * terrain beneath it, through the one seam every consumer already reads.
127
+ * @internal
128
+ */
110
129
  export declare function resolveEnvironmentField(feature: EnvironmentWorldFeature): TerrainField;
111
130
  export interface TerrainSlopeSample {
112
131
  /** Unit XZ direction pointing downhill; `[0, 0]` on level ground. */
@@ -124,6 +143,51 @@ export declare function sampleSlope(field: TerrainField, x: number, z: number):
124
143
  * @internal
125
144
  */
126
145
  export declare function slopeForce(field: TerrainField, x: number, z: number, scale?: number): readonly [number, number];
146
+ /** XZ region a {@link raycastHeightField} march is clipped to. */
147
+ export interface HeightFieldRayBounds {
148
+ minX: number;
149
+ minZ: number;
150
+ maxX: number;
151
+ maxZ: number;
152
+ }
153
+ /** Tuning for {@link raycastHeightField}: march resolution and refinement depth. */
154
+ export interface HeightFieldRaycastOptions {
155
+ /** XZ region to march within; the ray is clipped to it before any sampling. */
156
+ bounds: HeightFieldRayBounds;
157
+ /**
158
+ * March step in world units. Use about half the field's cell size — features narrower than one
159
+ * step can be skipped. Defaults to 1/256 of the larger bounds span, clamped to `[0.25, 4]`.
160
+ */
161
+ step?: number;
162
+ /** Bisection iterations refining the crossing once found (default 8 ≈ step/256 precision). */
163
+ refine?: number;
164
+ /** Stop marching past this ray distance (default: the full bounds crossing). */
165
+ maxDistance?: number;
166
+ /**
167
+ * Hard cap on march samples (default 4096). Bounds the work for rays the XZ slab cannot clip —
168
+ * a near-vertical ray inside bounds has an enormous slab crossing, and an upward ray never
169
+ * meets the surface at all; the cap turns both into a prompt miss instead of a stall.
170
+ */
171
+ maxSteps?: number;
172
+ }
173
+ /** Where a {@link raycastHeightField} march crossed the surface. */
174
+ export interface HeightFieldRayHit {
175
+ x: number;
176
+ y: number;
177
+ z: number;
178
+ /** Ray-parameter distance from the origin to the hit (direction is normalized internally). */
179
+ distance: number;
180
+ }
181
+ /**
182
+ * Intersects a ray with a `sampleHeight` field by fixed-step raymarching plus bisection — the
183
+ * O(steps) editor/gameplay picking seam that replaces brute-force triangle raycasts against a
184
+ * tessellated ground mesh (tens of thousands of triangle tests per pick on a sculpt-sized grid).
185
+ * The ray is clipped to `bounds` on XZ first, marched at `step`, and the first above→below
186
+ * crossing is bisected. An origin already under the surface hits immediately at entry. Returns
187
+ * null when the clipped ray never crosses the surface.
188
+ * @capability terrain-raycast pick a point on a heightfield along a camera/pointer ray
189
+ */
190
+ export declare function raycastHeightField(sampleHeight: (x: number, z: number) => number, origin: readonly [number, number, number], direction: readonly [number, number, number], options: HeightFieldRaycastOptions): HeightFieldRayHit | null;
127
191
  export interface TerrainPalette {
128
192
  low: string;
129
193
  high: string;
@@ -1,5 +1,5 @@
1
1
  import { withPathProfiles } from "./pathTerrain.js";
2
- import { nearestOnPath } from "./roads.js";
2
+ import { isOnRoad, nearestOnPath } from "./roads.js";
3
3
  function clamp01(value) {
4
4
  return value < 0 ? 0 : value > 1 ? 1 : value;
5
5
  }
@@ -174,6 +174,10 @@ export function arenaField(config = {}) {
174
174
  export function groundFieldFor(world) {
175
175
  if (world !== undefined && world.kind === "environment")
176
176
  return resolveEnvironmentField(world);
177
+ // Place worlds (`world()` from world/place) stand on a flat baseline field: flat/board grounds are
178
+ // exactly y=0, while round/voxel grounds keep their sampled shape in the game's own generation
179
+ // systems (the substrate declaration never bakes a heightfield). Editor-authored sculpt still
180
+ // layers through the environment path above.
177
181
  return flatField();
178
182
  }
179
183
  /** Whether a world declares real terrain (base heightfield or islands) rather than a flat plane — gates terrain-floor sampling in the movement controllers.
@@ -304,15 +308,54 @@ export function flattenFieldAround(base, zones) {
304
308
  * through the one seam every consumer already reads.
305
309
  * @internal
306
310
  */
311
+ /**
312
+ * Drapes each `road()` ribbon's `elevation` onto the ground so a body standing on a road snaps to the
313
+ * road *surface* the renderer draws (`sampleHeight + elevation`), not the bare terrain beneath it. Without
314
+ * this the ground field and {@link RoadRibbons}/{@link CityRenderer} disagree by `elevation` per road, and
315
+ * anything grounded on a road — the player, NPCs, spawns via `groundHeightAt` — sinks by that offset into
316
+ * the asphalt. Overlapping ribbons (intersections) take the highest lift. Only `sampleHeight` is draped:
317
+ * the road ribbons are flat, so `sampleNormal` stays the smooth terrain normal — draping it too would spoof
318
+ * a near-vertical slope at every curb edge and trip slope-slide.
319
+ * @internal — reached through `environment({ roads })`; not called directly by games.
320
+ */
321
+ export function roadDrapedField(base, roads) {
322
+ if (roads.length === 0)
323
+ return base;
324
+ const sampleHeight = (x, z) => {
325
+ let lift = 0;
326
+ for (const road of roads) {
327
+ if (road.elevation > lift && isOnRoad(road.path, road.width, x, z))
328
+ lift = road.elevation;
329
+ }
330
+ return base.sampleHeight(x, z) + lift;
331
+ };
332
+ return {
333
+ sampleHeight,
334
+ sampleNormal: base.sampleNormal,
335
+ ...(base.bounds === undefined ? {} : { bounds: base.bounds }),
336
+ ...(base.waterLevel === undefined ? {} : { waterLevel: base.waterLevel }),
337
+ };
338
+ }
339
+ /**
340
+ * The full ground field for an environment world: base `terrain` composed with any `islands`, then
341
+ * any authored `sculpt` snapshot, then any `clearings`, then any `roads` draped on top — so an
342
+ * editor-sculpted heightfield drives both the rendered mesh and player collision, gameplay spots
343
+ * stay level, and anything grounded on a road stands on the drawn asphalt rather than the bare
344
+ * terrain beneath it, through the one seam every consumer already reads.
345
+ * @internal
346
+ */
307
347
  export function resolveEnvironmentField(feature) {
308
348
  const base = feature.terrain === undefined ? null : resolveTerrainField(feature.terrain);
309
349
  const composed = feature.islands === undefined || feature.islands.length === 0
310
350
  ? base ?? flatField()
311
351
  : composeIslandFields(base, feature.islands);
312
352
  const sculpted = feature.sculpt === undefined ? composed : sculptedField(composed, feature.sculpt);
313
- return feature.clearings === undefined || feature.clearings.length === 0
353
+ const cleared = feature.clearings === undefined || feature.clearings.length === 0
314
354
  ? sculpted
315
355
  : flattenFieldAround(sculpted, feature.clearings);
356
+ return feature.roads === undefined || feature.roads.length === 0
357
+ ? cleared
358
+ : roadDrapedField(cleared, feature.roads);
316
359
  }
317
360
  /** Local slope from the field's normal — the input for gravity-roll, ski acceleration, and slide checks (#284.6).
318
361
  * @internal
@@ -338,6 +381,80 @@ export function slopeForce(field, x, z, scale = 9.8) {
338
381
  return [0, 0];
339
382
  return [nx * scale, nz * scale];
340
383
  }
384
+ /**
385
+ * Intersects a ray with a `sampleHeight` field by fixed-step raymarching plus bisection — the
386
+ * O(steps) editor/gameplay picking seam that replaces brute-force triangle raycasts against a
387
+ * tessellated ground mesh (tens of thousands of triangle tests per pick on a sculpt-sized grid).
388
+ * The ray is clipped to `bounds` on XZ first, marched at `step`, and the first above→below
389
+ * crossing is bisected. An origin already under the surface hits immediately at entry. Returns
390
+ * null when the clipped ray never crosses the surface.
391
+ * @capability terrain-raycast pick a point on a heightfield along a camera/pointer ray
392
+ */
393
+ export function raycastHeightField(sampleHeight, origin, direction, options) {
394
+ const length = Math.hypot(direction[0], direction[1], direction[2]);
395
+ if (length < 1e-12)
396
+ return null;
397
+ const dx = direction[0] / length;
398
+ const dy = direction[1] / length;
399
+ const dz = direction[2] / length;
400
+ const { bounds } = options;
401
+ // Clip [t0, t1] to the XZ slab of bounds.
402
+ let t0 = 0;
403
+ let t1 = options.maxDistance ?? Infinity;
404
+ for (const [o, d, min, max] of [
405
+ [origin[0], dx, bounds.minX, bounds.maxX],
406
+ [origin[2], dz, bounds.minZ, bounds.maxZ],
407
+ ]) {
408
+ if (Math.abs(d) < 1e-12) {
409
+ if (o < min || o > max)
410
+ return null;
411
+ continue;
412
+ }
413
+ const ta = (min - o) / d;
414
+ const tb = (max - o) / d;
415
+ const near = Math.min(ta, tb);
416
+ const far = Math.max(ta, tb);
417
+ if (near > t0)
418
+ t0 = near;
419
+ if (far < t1)
420
+ t1 = far;
421
+ }
422
+ if (t1 <= t0)
423
+ return null;
424
+ const spanX = bounds.maxX - bounds.minX;
425
+ const spanZ = bounds.maxZ - bounds.minZ;
426
+ const step = options.step ?? Math.min(4, Math.max(0.25, Math.max(spanX, spanZ) / 256));
427
+ const refine = options.refine ?? 8;
428
+ const maxSteps = options.maxSteps ?? 4096;
429
+ const above = (t) => origin[1] + dy * t - sampleHeight(origin[0] + dx * t, origin[2] + dz * t);
430
+ let prevT = t0;
431
+ if (above(t0) <= 0) {
432
+ return { x: origin[0] + dx * t0, y: origin[1] + dy * t0, z: origin[2] + dz * t0, distance: t0 };
433
+ }
434
+ let steps = 0;
435
+ while (prevT < t1 && steps < maxSteps) {
436
+ steps += 1;
437
+ const t = Math.min(prevT + step, t1);
438
+ if (above(t) <= 0) {
439
+ let lo = prevT;
440
+ let hi = t;
441
+ for (let i = 0; i < refine; i += 1) {
442
+ const mid = (lo + hi) / 2;
443
+ if (above(mid) <= 0)
444
+ hi = mid;
445
+ else
446
+ lo = mid;
447
+ }
448
+ const x = origin[0] + dx * hi;
449
+ const z = origin[2] + dz * hi;
450
+ return { x, y: sampleHeight(x, z), z, distance: hi };
451
+ }
452
+ if (t >= t1)
453
+ break;
454
+ prevT = t;
455
+ }
456
+ return null;
457
+ }
341
458
  export const DEFAULT_TERRAIN_MATERIAL = "grass";
342
459
  export const TERRAIN_MATERIAL_PALETTES = {
343
460
  grass: { low: "#30402c", high: "#7f8b50", waterline: "#1d4c6e" },
package/dist/world.d.ts CHANGED
@@ -22,7 +22,7 @@ export { assignFormationSlots, boxFormation, circleFormation, facingYaw, lineFor
22
22
  export { createGlideModel } from "./movement/glideModel.js";
23
23
  export { createGrappleSwing } from "./movement/grappleSwing.js";
24
24
  export { createLeaderTrail } from "./movement/leaderTrail.js";
25
- export { MOVEMENT_TUNING } from "./movement/movementModel.js";
25
+ export { MOVEMENT_TUNING, type CollisionObstacle } from "./movement/movementModel.js";
26
26
  export { resolvePlayerMovementTuning, stepPlayerMovement } from "./movement/playerMovement.js";
27
27
  export { POSE_HITBOX, createPoseState, type MovementPose } from "./movement/poseState.js";
28
28
  export { steerYaw } from "./movement/steering.js";
@@ -37,14 +37,17 @@ export { createBuoyantBody } from "./physics/buoyancy.js";
37
37
  export { Carryable, carrySpeedMultiplier } from "./physics/carryable.js";
38
38
  export { createDamageModel } from "./physics/damageZones.js";
39
39
  export { tickDrivableVehicle } from "./physics/drivableVehicle.js";
40
+ export { createAircraftDynamics, type AircraftDynamics, type AircraftKind, type AircraftOptions, type AircraftStep, type AircraftTuning, type FlightControlInput, type FlightControlRates, type FlightVector, } from "./physics/flightDynamics.js";
40
41
  export { ForceVolume, PlatformCarry } from "./physics/forceVolume.js";
41
- export { createKinematicVehicle, type KinematicVehicle, type KinematicVehicleStep, type KinematicVehicleTuning, } from "./physics/kinematicVehicle.js";
42
+ export { combineGravity, pointGravity, uniformGravity, type GravityField, type GravityVector, type PointGravityOptions, } from "./physics/gravityField.js";
43
+ export { createKinematicVehicle, type KinematicChassisTuning, type KinematicDynamicsTuning, type KinematicPowertrainTuning, type KinematicSteeringTuning, type KinematicVehicle, type KinematicVehicleStep, type KinematicVehicleTuning, } from "./physics/kinematicVehicle.js";
42
44
  export { PhysicsWorld, SHAPE_BOX, SHAPE_SPHERE, type AddBodyOptions, type CollisionEvent, type PhysicsStats, } from "./physics/physicsWorld.js";
43
45
  export { createRagdoll } from "./physics/ragdoll.js";
44
46
  export { SpatialGrid } from "./physics/spatialGrid.js";
45
47
  export { StructureGraph, type CollapseEvent, type StructureMaterial } from "./physics/structure.js";
46
48
  export { Glide, Grapple } from "./physics/traversal.js";
47
49
  export { DEFAULT_GRIP_CURVE, createVehicleBody, sampleGripCurve, type GripCurve } from "./physics/vehicleBody.js";
50
+ export { createVehicleObstacleClamp, type VehicleImpact, type VehicleObstacleClamp, } from "./physics/vehicleObstacles.js";
48
51
  export { createAssetCatalog, type AssetCatalog, type ModelAssetRef, type ModelDims } from "./scene/assetCatalog.js";
49
52
  export { partsBounds, registerAssetGenerator, type GeneratedAsset, type GeneratedPart } from "./scene/assetGenerator.js";
50
53
  export { applyRotationPolicy, headingToRotationY, normalizeDegrees, parseAssetSpace, parseRotationPolicy, resolveAnchorOffset, resolveFacingRotationY, rotatedFootprint, rotationYToHeading, snapHeading, toEngineUnits, validateAssetSpace, type AssetAnchor, type AssetSpace, type AssetSpaceIssue, type PlacementRotationPolicy, } from "./scene/assetSpace.js";
@@ -62,7 +65,7 @@ export { MountController, createMountController } from "./scene/mount.js";
62
65
  export { objectVisualScale, type ObjectVisual, type SceneObject } from "./scene/objectStore.js";
63
66
  export { type PaintStroke } from "./scene/paintLayer.js";
64
67
  export { type RosterEntry } from "./scene/roster.js";
65
- export { parseParams, registerSceneKind, type ParamField, type ParamSchema, type ParsedParams, type SceneKindObject, type SceneKindResolveContext, type WeightedParamEntry, } from "./scene/sceneKinds.js";
68
+ export { findSchemaPreset, parseParams, registerSceneKind, type ParamField, type ParamPreset, type ParamSchema, type ParsedParams, type SceneKindObject, type SceneKindResolveContext, type WeightedParamEntry, } from "./scene/sceneKinds.js";
66
69
  export { firstImpact, hitsUntilBlocked, type SceneRaycastApi, type SceneRaycastHit } from "./scene/sceneRaycast.js";
67
70
  export { createSelectionSet, isMarquee, screenRect, selectWithinRect, type ScreenRect, type SelectionSet, } from "./scene/selection.js";
68
71
  export { createSelectionBookmarks, recallSelectionBookmark, type BookmarkRecallMode, type RecallBookmarkOptions, type SelectionBookmarkSnapshot, type SelectionBookmarks, type SelectionPruneResult, } from "./scene/selectionBookmarks.js";
@@ -89,6 +92,9 @@ export { buildingIndex, type BuildingIndex } from "./world/buildingIndex.js";
89
92
  export { type BuildingPaletteOverrides, type BuildingStyle } from "./world/buildings.js";
90
93
  export { CarvableField, VoxelVolume, carvableTerrain, type VoxelMaterial } from "./world/carve.js";
91
94
  export { catenaryCurve, sagCurve } from "./world/catenary.js";
95
+ export { type CityBlockKind } from "./world/cityBlocks.js";
96
+ export { CITY_LOT_CLASSES, CITY_TREE_SPECIES, type CityLotClass, type CityLotPiece, type CityPieceRole, type CityPieceShape, type CityTreeSpecies, type CityZoneBand, type CityZoneProfile, } from "./world/cityContent.js";
97
+ export { CITY_DEFAULTS, CITY_KIND, CITY_SCHEMA, CITY_ZONE_KIND, CITY_ZONE_SCHEMA, resolveCityObject, type CityBlock, type CityBridge, type CityDriveway, type CityHedge, type CityIntersection, type CityLight, type CityLot, type CityParcel, type CityParcelFrontageOut, type CityPark, type CityParking, type CityResolveContext, type CityRules, type CityStreet, type CityTree, type ResolvedCity, } from "./world/cityKind.js";
92
98
  export { snapToNearest, socketWorldPosition, socketsCompatible, worldSockets } from "./world/connectors.js";
93
99
  export { createEnvironmentField, type EnvironmentField, type HeatSource } from "./world/envField.js";
94
100
  export { resolveStructureBuildings, summarizeEnvironment } from "./world/environmentSummary.js";
@@ -100,14 +106,17 @@ export { GRASS_SCHEMA } from "./world/grassKind.js";
100
106
  export { resolveGridInstances } from "./world/gridInstances.js";
101
107
  export { createLodScheduler } from "./world/lod.js";
102
108
  export { mapLayerColor, type MapCellStates, type MapRoute, type MapZone } from "./world/mapLayers.js";
103
- export { DEFAULT_MARKER_KINDS, createMarkerSet, markerKindStyle, type MapMarker, type MarkerKindStyle, type MarkerSet, } from "./world/markers.js";
109
+ export { DEFAULT_MARKER_KINDS, createMarkerSet, createMarkerSource, markerKindStyle, type MapMarker, type MarkerCollection, type MarkerKindStyle, type MarkerSet, type MarkerSource, type MarkerSourceOptions, type MarkerView, } from "./world/markers.js";
104
110
  export { bearingToCardinal, clampToMinimapEdge, compassBearing, headingToBearing, projectToMinimap, relativeBearing, unprojectFromMinimap, type Cardinal, type MinimapView, type WorldXZ, } from "./world/minimap.js";
111
+ export { DEFAULT_MINIMAP_PALETTE, bakeMinimapBackground, bakeMinimapImage, encodeBakePng, minimapBakeToPngDataUri, type MinimapBake, type MinimapBakeBounds, type MinimapBakeOptions, type MinimapBakePalette, type MinimapBakeSource, type MinimapBakeZone, } from "./world/minimapBake.js";
105
112
  export { placeAlongPath } from "./world/pathInstances.js";
106
113
  export { withPathProfiles, type PathHeightPolicy, type PathRetaining, type TerrainPathProfile, } from "./world/pathTerrain.js";
114
+ export { isPlaceWorld, resolveWorldPhysics, seedForPlace, world, type BoardGround, type BoardGroundSize, type FlatGround, type FlatGroundSize, type GroundConfig, type GroundGenerator, type GroundMode, type PlaceConfig, type PlaceWorldFeature, type ResolvedGround, type RoundGround, type RoundGroundSize, type SurfaceLaws, type VoxelGround, type VoxelGroundSize, } from "./world/place.js";
107
115
  export { placeAssetFromCommit, resolvePlaceAsset, toEditorMarker, toStructureInput, type PlaceAssetResult, } from "./world/placeAsset.js";
108
116
  export { createPlacedStructureStore, type PlacedStructure } from "./world/placedStructureStore.js";
109
117
  export { validatePlacement, type PlacementRules } from "./world/placement.js";
110
118
  export { createPlacementController, quarterTurnsToRotationY, type PlacementCommit, type PlacementController, type PlacementPreview, type SnapMode, } from "./world/placementController.js";
119
+ export { POLE_LINE_SCHEMA, resolvePoleLine, type ResolvedPoleLine } from "./world/poleLineKind.js";
111
120
  export { composeRealm } from "./world/realm.js";
112
121
  export { createRegionField, isRegionField, type RegionField } from "./world/regions.js";
113
122
  export { buildRoadRibbon, dashSegments } from "./world/roads.js";
@@ -116,7 +125,7 @@ export { pickWeighted, scatterItems, type ScatterInstance } from "./world/scatte
116
125
  export { SCATTER_PATH_KIND, clearanceZonesFrom, distanceToPolygonEdge, isScatterPath, pointInPolygon, polygonArea, polygonBounds, readScatterPalette, readScatterRules, resolveScatter, resolveScatterRegion, scatterRegionEstimate, scatterRegionFromPath, type ScatterTerrain, } from "./world/scatterRegion.js";
117
126
  export { SOIL_KIND, SOIL_SCHEMA, type SoilRules } from "./world/soilKind.js";
118
127
  export { annulusRegion, boxRegion, customRegion, discRegion, pointSetRegion, polygonRegion, rectRegion, sampleBatch, samplePoint, sampleStratified, shellRegion, sphereRegion, weightedRegion, type AreaDistribution, type FallbackPolicy, type Point3, type RadialDistribution, type SampleBatchOptions, type SampleBatchResult, type SampleConstraints, type SamplePoint, type SamplePointOptions, type SampleReason, type SampleRegion, type SampleResult, type StratifiedOptions, type VolumeDistribution, type WeightedRegionEntry, } from "./world/spatialSample.js";
119
- export { furnitureSpots, laneCenters, offsetPath, parkingSpots, sidewalkPoint, sidewalkWidthOf, } from "./world/streets.js";
128
+ export { distanceToRoadEdge, furnitureSpots, laneCenters, offsetPath, parkingSpots, roadSurfaceSampler, sidewalkPoint, sidewalkWidthOf, type RoadSurfaceOptions, } from "./world/streets.js";
120
129
  export { solveSupport, toDebrisBodies, type SupportResult } from "./world/support.js";
121
130
  export { applyDeltaToSnapshot, applySurfaceDeltaToSnapshot, beginSurfaceStroke, beginTerraformStroke, createEditableTerrain, createTerraformBrush, createTerrainSnapshot, editableTerrainFromSnapshot, migrateTerrainSnapshot, revertDeltaFromSnapshot, revertSurfaceDeltaFromSnapshot, type EditableTerrain, type SurfaceDelta, type SurfaceStroke, type TerraformDelta, type TerraformEdit, type TerraformFalloff, type TerraformMode, type TerraformShape, type TerraformSnapshot, type TerraformStroke, type TerrainMaterialLayer, type TerrainSurfaceRule, } from "./world/terraform.js";
122
131
  export { TERRAIN_MATERIAL_PALETTES, applyPathProfiles, type NoiseFieldConfig, type ResolvedTerrainDetail, type TerrainField, type TerrainPalette, } from "./world/terrain.js";
package/dist/world.js CHANGED
@@ -37,7 +37,9 @@ export { createBuoyantBody } from "./physics/buoyancy.js";
37
37
  export { Carryable, carrySpeedMultiplier } from "./physics/carryable.js";
38
38
  export { createDamageModel } from "./physics/damageZones.js";
39
39
  export { tickDrivableVehicle } from "./physics/drivableVehicle.js";
40
+ export { createAircraftDynamics, } from "./physics/flightDynamics.js";
40
41
  export { ForceVolume, PlatformCarry } from "./physics/forceVolume.js";
42
+ export { combineGravity, pointGravity, uniformGravity, } from "./physics/gravityField.js";
41
43
  export { createKinematicVehicle, } from "./physics/kinematicVehicle.js";
42
44
  export { PhysicsWorld, SHAPE_BOX, SHAPE_SPHERE, } from "./physics/physicsWorld.js";
43
45
  export { createRagdoll } from "./physics/ragdoll.js";
@@ -45,6 +47,7 @@ export { SpatialGrid } from "./physics/spatialGrid.js";
45
47
  export { StructureGraph } from "./physics/structure.js";
46
48
  export { Glide, Grapple } from "./physics/traversal.js";
47
49
  export { DEFAULT_GRIP_CURVE, createVehicleBody, sampleGripCurve } from "./physics/vehicleBody.js";
50
+ export { createVehicleObstacleClamp, } from "./physics/vehicleObstacles.js";
48
51
  export { createAssetCatalog } from "./scene/assetCatalog.js";
49
52
  export { partsBounds, registerAssetGenerator } from "./scene/assetGenerator.js";
50
53
  export { applyRotationPolicy, headingToRotationY, normalizeDegrees, parseAssetSpace, parseRotationPolicy, resolveAnchorOffset, resolveFacingRotationY, rotatedFootprint, rotationYToHeading, snapHeading, toEngineUnits, validateAssetSpace, } from "./scene/assetSpace.js";
@@ -62,7 +65,7 @@ export { MountController, createMountController } from "./scene/mount.js";
62
65
  export { objectVisualScale } from "./scene/objectStore.js";
63
66
  export {} from "./scene/paintLayer.js";
64
67
  export {} from "./scene/roster.js";
65
- export { parseParams, registerSceneKind, } from "./scene/sceneKinds.js";
68
+ export { findSchemaPreset, parseParams, registerSceneKind, } from "./scene/sceneKinds.js";
66
69
  export { firstImpact, hitsUntilBlocked } from "./scene/sceneRaycast.js";
67
70
  export { createSelectionSet, isMarquee, screenRect, selectWithinRect, } from "./scene/selection.js";
68
71
  export { createSelectionBookmarks, recallSelectionBookmark, } from "./scene/selectionBookmarks.js";
@@ -89,6 +92,9 @@ export { buildingIndex } from "./world/buildingIndex.js";
89
92
  export {} from "./world/buildings.js";
90
93
  export { CarvableField, VoxelVolume, carvableTerrain } from "./world/carve.js";
91
94
  export { catenaryCurve, sagCurve } from "./world/catenary.js";
95
+ export {} from "./world/cityBlocks.js";
96
+ export { CITY_LOT_CLASSES, CITY_TREE_SPECIES, } from "./world/cityContent.js";
97
+ export { CITY_DEFAULTS, CITY_KIND, CITY_SCHEMA, CITY_ZONE_KIND, CITY_ZONE_SCHEMA, resolveCityObject, } from "./world/cityKind.js";
92
98
  export { snapToNearest, socketWorldPosition, socketsCompatible, worldSockets } from "./world/connectors.js";
93
99
  export { createEnvironmentField } from "./world/envField.js";
94
100
  export { resolveStructureBuildings, summarizeEnvironment } from "./world/environmentSummary.js";
@@ -100,14 +106,17 @@ export { GRASS_SCHEMA } from "./world/grassKind.js";
100
106
  export { resolveGridInstances } from "./world/gridInstances.js";
101
107
  export { createLodScheduler } from "./world/lod.js";
102
108
  export { mapLayerColor } from "./world/mapLayers.js";
103
- export { DEFAULT_MARKER_KINDS, createMarkerSet, markerKindStyle, } from "./world/markers.js";
109
+ export { DEFAULT_MARKER_KINDS, createMarkerSet, createMarkerSource, markerKindStyle, } from "./world/markers.js";
104
110
  export { bearingToCardinal, clampToMinimapEdge, compassBearing, headingToBearing, projectToMinimap, relativeBearing, unprojectFromMinimap, } from "./world/minimap.js";
111
+ export { DEFAULT_MINIMAP_PALETTE, bakeMinimapBackground, bakeMinimapImage, encodeBakePng, minimapBakeToPngDataUri, } from "./world/minimapBake.js";
105
112
  export { placeAlongPath } from "./world/pathInstances.js";
106
113
  export { withPathProfiles, } from "./world/pathTerrain.js";
114
+ export { isPlaceWorld, resolveWorldPhysics, seedForPlace, world, } from "./world/place.js";
107
115
  export { placeAssetFromCommit, resolvePlaceAsset, toEditorMarker, toStructureInput, } from "./world/placeAsset.js";
108
116
  export { createPlacedStructureStore } from "./world/placedStructureStore.js";
109
117
  export { validatePlacement } from "./world/placement.js";
110
118
  export { createPlacementController, quarterTurnsToRotationY, } from "./world/placementController.js";
119
+ export { POLE_LINE_SCHEMA, resolvePoleLine } from "./world/poleLineKind.js";
111
120
  export { composeRealm } from "./world/realm.js";
112
121
  export { createRegionField, isRegionField } from "./world/regions.js";
113
122
  export { buildRoadRibbon, dashSegments } from "./world/roads.js";
@@ -116,7 +125,7 @@ export { pickWeighted, scatterItems } from "./world/scatterItems.js";
116
125
  export { SCATTER_PATH_KIND, clearanceZonesFrom, distanceToPolygonEdge, isScatterPath, pointInPolygon, polygonArea, polygonBounds, readScatterPalette, readScatterRules, resolveScatter, resolveScatterRegion, scatterRegionEstimate, scatterRegionFromPath, } from "./world/scatterRegion.js";
117
126
  export { SOIL_KIND, SOIL_SCHEMA } from "./world/soilKind.js";
118
127
  export { annulusRegion, boxRegion, customRegion, discRegion, pointSetRegion, polygonRegion, rectRegion, sampleBatch, samplePoint, sampleStratified, shellRegion, sphereRegion, weightedRegion, } from "./world/spatialSample.js";
119
- export { furnitureSpots, laneCenters, offsetPath, parkingSpots, sidewalkPoint, sidewalkWidthOf, } from "./world/streets.js";
128
+ export { distanceToRoadEdge, furnitureSpots, laneCenters, offsetPath, parkingSpots, roadSurfaceSampler, sidewalkPoint, sidewalkWidthOf, } from "./world/streets.js";
120
129
  export { solveSupport, toDebrisBodies } from "./world/support.js";
121
130
  export { applyDeltaToSnapshot, applySurfaceDeltaToSnapshot, beginSurfaceStroke, beginTerraformStroke, createEditableTerrain, createTerraformBrush, createTerrainSnapshot, editableTerrainFromSnapshot, migrateTerrainSnapshot, revertDeltaFromSnapshot, revertSurfaceDeltaFromSnapshot, } from "./world/terraform.js";
122
131
  export { TERRAIN_MATERIAL_PALETTES, applyPathProfiles, } from "./world/terrain.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jgengine/core",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "jgengine core — agent-first game framework SDK (npm @jgengine/core). Entity stores, commands, combat, inventory, multiplayer seams. Zero dependencies. Not an ECS. https://jgengine.com",
5
5
  "keywords": [
6
6
  "jgengine",
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: game-design
3
+ description: Design, audit, implement, and validate player experience, loops, systems, progression, and balance.
4
+ ---
5
+
6
+ # Game design
7
+
8
+ ## Ownership
9
+
10
+ Own the intended player experience and the rules that produce it: fantasy, pillars, verbs, decisions, feedback, loops, resources, progression, challenge, failure, onboarding, and social dynamics. Treat design claims as hypotheses proved by play, not a feature inventory or genre imitation — no genre kits, presets, or archetypes; every game is a custom composition of needs (see [AGENTS.md](../../../AGENTS.md)).
11
+
12
+ Use `level-design` for spatial realization; route implementation to `jgengine-gameplay`, `jgengine-world`, `jgengine-combat`, `jgengine-ui`, `jgengine-multiplayer` once intent is coherent.
13
+
14
+ Read [references/application-playbook.md](references/application-playbook.md) only when the task explicitly calls for design depth — a design brief, a redesign, or "make this fun/better" work; it is not a mandatory step of creating a game. Read [references/field-guide.md](references/field-guide.md) when the task needs deeper loop, economy, progression, genre, accessibility, or research guidance.
15
+
16
+ ## Choose the mode
17
+
18
+ Greenfield: produce a vertical-slice contract (promise, pillars, core decision, loops, progression, failure/recovery) and build the smallest slice testing the riskiest assumption — see playbook §1. Existing game: reconstruct what it actually does from code and play, rank root problems by impact/confidence/reach/effort — see playbook §2.
19
+
20
+ “Improve with game design” is an implementation request, not just an audit: select the highest-leverage intervention, implement it through shared engine seams, and prove the changed player behavior.
21
+
22
+ ## Required output contract
23
+
24
+ Every design pass yields an observed journey, a north star (promise, pillars, anti-pillars, core decision), a loop/flow model, a ranked bottleneck list with cited evidence, an intervention stack, a chosen design slice, and acceptance evidence. See [references/application-playbook.md](references/application-playbook.md) for the full contract and execution rules (verb->feedback->consequence chains, loop/progression/challenge discipline, upstream ownership).
25
+
26
+ ## Completion
27
+
28
+ An audit is not completion for a build/improve request. Finish when the slice is playable, a fresh player can state goal/choice/consequence, failure/recovery behave as intended, and evidence supports the pillars. Use `jgengine-verify` and `workflow` to ship.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Game Design"
3
+ short_description: "Design coherent game loops and systems"
4
+ default_prompt: "Use $game-design to audit or design this game, implement its highest-leverage design slice, and prove the changed player behavior."
@@ -0,0 +1,170 @@
1
+ # Applying game design
2
+
3
+ Use this playbook to turn a pitch or an existing game into implemented, testable change. Its purpose is to prevent “design work” from ending as generic advice.
4
+
5
+ ## Contents
6
+
7
+ 1. Greenfield procedure
8
+ 2. Existing-game audit
9
+ 3. Mandatory models
10
+ 4. Ranking interventions
11
+ 5. Design-slice specification
12
+ 6. Implementation and proof
13
+ 7. Failure modes
14
+
15
+ ## 1. Greenfield procedure
16
+
17
+ ### Frame the bet
18
+
19
+ Write a compact contract before broad code or content:
20
+
21
+ | Field | Required form |
22
+ | --- | --- |
23
+ | audience/context | prior skills, player count, platform/input, session length, accessibility assumptions |
24
+ | player promise | “The player repeatedly [verb/decision] so they feel [specific experience]” |
25
+ | pillars | two or three observable behaviors or feelings |
26
+ | anti-pillars | experiences the game must not drift toward |
27
+ | core decision | situation, known information, viable options, tradeoff, consequence, recurrence |
28
+ | completion proof | one end-to-end scenario a target player can perform and explain |
29
+ | falsifier | observation that would show the design does not work |
30
+
31
+ ### Build the minimum design
32
+
33
+ 1. Model each core verb from cue through future consequence.
34
+ 2. Draw moment, encounter, session, and meta loops.
35
+ 3. Draw resources and feedback structures.
36
+ 4. Map player skills and progression channels.
37
+ 5. Define failure, recovery, stopping, and replay.
38
+ 6. Create a content grammar: a small set of mechanics crossed with contexts and constraints.
39
+ 7. Select the riskiest assumption and build one vertical design slice around it.
40
+
41
+ Do not build the entire feature list first. A vertical slice contains real input, meaningful state, feedback, one decision that recurs, failure/recovery, and a downstream consequence.
42
+
43
+ ## 2. Existing-game audit
44
+
45
+ ### Reconstruct reality
46
+
47
+ Inspect actual code, catalogs, scene documents, UI, tests, captures, and live play. Do not infer the game from its title or README.
48
+
49
+ Trace four journeys when applicable:
50
+
51
+ - **first minute:** first input, goal, threat, reward, confusion, and reason to continue
52
+ - **first objective:** learning sequence, decisions, failure, recovery, payoff, and next goal
53
+ - **representative session:** loop renewal, variety, resource pressure, build choices, pacing, and stopping point
54
+ - **campaign/meta:** unlock cadence, content reuse, escalation, economy stability, mastery, and ending/replay
55
+
56
+ For each journey, record timestamps or event order:
57
+
58
+ `cue -> player belief -> action -> system response -> feedback -> state change -> next choice`
59
+
60
+ Mark dead time, repeated decisions, forced actions, hidden consequences, false affordances, unexplained failure, and rewards that do not alter later play.
61
+
62
+ ### Build a system-coupling map
63
+
64
+ Inventory verbs, enemies/problems, items/tools, progression, economy, quests/objectives, world states, social systems, and failure. For each system ask:
65
+
66
+ - Which pillar does it serve?
67
+ - Which loop consumes its output?
68
+ - What player decision does it create or transform?
69
+ - Where is it taught, tested, combined, and mastered?
70
+ - What happens if it is removed?
71
+
72
+ Flag systems that are present but disconnected, content whose only variation is numbers or nouns, and rewards that bypass the core play.
73
+
74
+ ### Diagnose decision density
75
+
76
+ Do not maximize decisions per second. Find long spans where the player executes an already-solved action without new information, tradeoffs, expression, pressure, or mastery. Measure:
77
+
78
+ - time to first meaningful decision
79
+ - meaningful decisions per encounter/objective
80
+ - time between new information and commitment
81
+ - percentage of objectives using each verb or decision type
82
+ - repeated content before context changes
83
+ - time from failure to a useful retry
84
+
85
+ ## 3. Mandatory models
86
+
87
+ ### Loop table
88
+
89
+ | Horizon | Cue/goal | Decision/action | Feedback | State changed | Why repeat? | Failure risk |
90
+ | --- | --- | --- | --- | --- | --- | --- |
91
+
92
+ Reject any row whose “state changed” or “why repeat” is empty.
93
+
94
+ ### Resource-flow table
95
+
96
+ | Resource | Source | Store/cap | Spend/convert | Sink | Player decision | Feedback/runaway risk |
97
+ | --- | --- | --- | --- | --- | --- | --- |
98
+
99
+ Include time, health, space, information, attention, action opportunities, and social trust when relevant.
100
+
101
+ ### Progression table
102
+
103
+ | Unlock/reward | Channel | New decision or capability | Content it recontextualizes | Risk of invalidation/grind | Proof |
104
+ | --- | --- | --- | --- | --- | --- |
105
+
106
+ Channels are mastery, access, breadth, power, and expression/status. Passive percentages without a changed decision must justify their place.
107
+
108
+ ### Objective/encounter variety matrix
109
+
110
+ Cross objective verbs with information state, constraints, enemy/problem behavior, topology, resource pressure, failure condition, and consequence. This exposes campaigns where every mission is the same verb with different nouns.
111
+
112
+ ## 4. Ranking interventions
113
+
114
+ Separate symptoms from root causes. “Quests are boring” is a symptom. “Every quest uses the same kill-count transition and no objective changes space, resources, or strategy” is a testable cause.
115
+
116
+ Rank each candidate:
117
+
118
+ | Candidate | Player behavior changed | Pillar impact | Reach | Evidence/confidence | Effort/risk | Dependencies | Shared owner |
119
+ | --- | --- | --- | --- | --- | --- | --- | --- |
120
+
121
+ Use three horizons:
122
+
123
+ - **Minimum correction:** remove the largest contradiction or unblock the loop.
124
+ - **Strong target:** make one representative slice deliver the promise end to end.
125
+ - **Multiplier:** expand the proven grammar across content, progression, social play, or replay.
126
+
127
+ Choose by leverage, not novelty. Prefer a change that improves many encounters or future games over bespoke content with the same underlying decision.
128
+
129
+ ## 5. Design-slice specification
130
+
131
+ The selected slice must state:
132
+
133
+ - before behavior and evidence
134
+ - target behavior and player belief
135
+ - mechanics/dynamics expected to cause the change
136
+ - objective/encounter sequence and pacing beats
137
+ - resources, rewards, failure, recovery, and downstream consequence
138
+ - affected catalogs/config, shared package seams, scene semantics, UI feedback, and tests
139
+ - tuning variables with starting hypotheses and safe bounds
140
+ - explicit non-goals and content held constant
141
+ - acceptance scenario and falsifiers
142
+
143
+ If another game could use the mechanic, define the package primitive first and adopt it here. Keep game-local code for content and feel.
144
+
145
+ ## 6. Implementation and proof
146
+
147
+ When the user asks to build or improve:
148
+
149
+ 1. Implement the shared primitive or use an existing capability.
150
+ 2. Adopt it in one complete game slice.
151
+ 3. Author spatial content through `level-design` and the editor.
152
+ 4. Add deterministic tests for transitions, resources, failure, and progression.
153
+ 5. Exercise the observable scenario with representative input.
154
+ 6. Capture before/after evidence for behavior, not only appearance.
155
+ 7. Evaluate the falsifier honestly; revise or remove a failed intervention.
156
+
157
+ Useful evidence includes time to first decision, objective completion, route choice, build choice, resource state, failure cause, retry time, objective-verb distribution, and a player’s ability to explain goal/action/consequence. Metrics need a named hypothesis; do not optimize them in isolation.
158
+
159
+ ## 7. Failure modes
160
+
161
+ - producing a long GDD instead of a playable slice
162
+ - listing features without naming changed decisions
163
+ - adding content to a shallow objective grammar
164
+ - using passive progression to disguise unchanged play
165
+ - copying a genre’s surface without its causal dynamics
166
+ - treating more rewards as more motivation
167
+ - fixing comprehension only with text or HUD
168
+ - reporting a diagnosis after the user asked for improvement
169
+ - calling deterministic tests proof that the experience works
170
+ - calling a prettier screenshot proof that the loop works