threedog 0.8.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/CHANGELOG.md +223 -4
  2. package/README.md +6 -6
  3. package/core/assets/Animator.js +2 -0
  4. package/core/assets/Assets.js +44 -13
  5. package/core/assets/assetEntry.js +87 -22
  6. package/core/assets/assetHot.js +2 -1
  7. package/core/assets/assetReport.js +1 -2
  8. package/core/audio/Audio.js +24 -5
  9. package/core/base/I18n.js +6 -3
  10. package/core/base/Random.js +3 -1
  11. package/core/base/Vars.js +14 -4
  12. package/core/base/errorCodes.js +54 -16
  13. package/core/base/errorHints.js +12 -1
  14. package/core/base/errors.js +6 -4
  15. package/core/base/events.generated.js +10 -0
  16. package/core/base/follows.js +26 -0
  17. package/core/base/math.js +15 -8
  18. package/core/base/params.js +2 -2
  19. package/core/{saves → base}/saveValues.js +24 -6
  20. package/core/base/sections.js +97 -0
  21. package/core/base/spelling.js +32 -0
  22. package/core/base/validate.js +8 -29
  23. package/core/engine/Engine.js +61 -18
  24. package/core/engine/Loading.js +30 -3
  25. package/core/engine/copies.js +1 -1
  26. package/core/engine/headlessLoad.js +30 -13
  27. package/core/engine/lifecycle.js +30 -25
  28. package/core/engine/loop.js +22 -4
  29. package/core/engine/moduleSlots.js +91 -15
  30. package/core/engine/moduleTypes.js +13 -0
  31. package/core/engine/modules.js +248 -62
  32. package/core/engine/page.js +25 -8
  33. package/core/engine/plugins.js +15 -3
  34. package/core/engine/services.js +3 -0
  35. package/core/engine/startup.js +46 -36
  36. package/core/input/Input.js +39 -19
  37. package/core/input/inputKeyboard.js +39 -0
  38. package/core/input/inputPad.js +23 -2
  39. package/core/input/inputPointer.js +3 -1
  40. package/core/input/inputSeat.js +66 -0
  41. package/core/input/inputTouch.js +23 -6
  42. package/core/inspect/DebugOverrides.js +13 -2
  43. package/core/inspect/Describe.js +10 -6
  44. package/core/inspect/Inspect.js +31 -4
  45. package/core/inspect/UrlState.js +14 -10
  46. package/core/inspect/catalog.js +12 -5
  47. package/core/inspect/describeRender.js +3 -2
  48. package/core/inspect/describeText.js +6 -2
  49. package/core/inspect/metadata.generated.js +4140 -0
  50. package/core/inspect/pictureWriters.js +117 -33
  51. package/core/inspect/toolDoor.js +21 -0
  52. package/core/inspect/valueHistory.js +35 -0
  53. package/core/ops/Ops.js +32 -7
  54. package/core/ops/control.js +48 -23
  55. package/core/ops/holds.js +4 -3
  56. package/core/ops/opsAtomic.js +18 -6
  57. package/core/ops/opsCheck.js +7 -5
  58. package/core/ops/opsFail.js +5 -7
  59. package/core/ops/opsRun.js +2 -2
  60. package/core/ops/owned.js +20 -3
  61. package/core/ops/sharedPoint.js +7 -10
  62. package/core/ops/stacks.js +22 -1
  63. package/core/saves/SaveStore.js +52 -26
  64. package/core/saves/Saves.js +122 -27
  65. package/core/saves/saveApply.js +159 -61
  66. package/core/saves/saveFiles.js +30 -25
  67. package/core/saves/saveVersions.js +20 -6
  68. package/core/saves/session.js +76 -33
  69. package/core/saves/stateReplace.js +184 -0
  70. package/core/scene/Rays.js +21 -5
  71. package/core/scene/Views.js +6 -6
  72. package/core/scene/adaptive.js +13 -10
  73. package/core/scene/canvasBox.js +2 -0
  74. package/core/scene/compositeGround.js +72 -0
  75. package/core/scene/floor.js +17 -0
  76. package/core/scene/grid.js +2 -0
  77. package/core/scene/ground.contract.js +14 -0
  78. package/core/scene/ground.js +52 -17
  79. package/core/scene/pixel.js +154 -0
  80. package/core/scene/pixelRatio.js +167 -0
  81. package/core/scene/sceneDelta.js +3 -3
  82. package/core/scene/sceneMethods.js +11 -6
  83. package/core/scene/stepPoses.js +6 -1
  84. package/core/scene/thingExplain.js +1 -1
  85. package/core/scene/thingOps.js +22 -14
  86. package/core/scene/things.js +1 -1
  87. package/core/scene/tier.js +10 -0
  88. package/core/scene/view.js +126 -9
  89. package/core/stream/Batching.js +0 -1
  90. package/core/stream/Stream.js +24 -12
  91. package/core/stream/batchGroups.js +1 -0
  92. package/core/stream/scatter.js +5 -2
  93. package/core/stream/streamSources.js +2 -1
  94. package/core/threads/Commits.js +12 -7
  95. package/core/threads/Jobs.js +15 -5
  96. package/core/threads/Threads.js +5 -2
  97. package/core/time/Clock.js +3 -1
  98. package/core/time/skip.js +10 -4
  99. package/core/time/time.js +16 -10
  100. package/docs/AI.md +89 -72
  101. package/docs/API.md +18 -14
  102. package/docs/CODEMAP.md +68 -40
  103. package/docs/COMMANDS.md +22 -23
  104. package/docs/CONVENTIONS.md +120 -17
  105. package/docs/MIGRATING-0.8.md +2 -0
  106. package/docs/MIGRATING-1.0.md +101 -0
  107. package/docs/THREE.md +65 -12
  108. package/docs/api/cameraRig.md +3 -0
  109. package/docs/api/characters.md +13 -7
  110. package/docs/api/collider3d.md +9 -0
  111. package/docs/api/content.md +16 -15
  112. package/docs/api/dialogue.md +2 -1
  113. package/docs/api/engine.md +18 -16
  114. package/docs/api/events.md +14 -4
  115. package/docs/api/ground.md +2 -2
  116. package/docs/api/i18n.md +1 -1
  117. package/docs/api/input.md +2 -1
  118. package/docs/api/interactions.md +1 -1
  119. package/docs/api/inventory.md +1 -1
  120. package/docs/api/level.md +3 -2
  121. package/docs/api/nav.md +4 -2
  122. package/docs/api/particles.md +8 -5
  123. package/docs/api/pickups.md +1 -1
  124. package/docs/api/post.md +3 -4
  125. package/docs/api/quests.md +4 -2
  126. package/docs/api/rays.md +2 -0
  127. package/docs/api/rigid.md +3 -2
  128. package/docs/api/saves.md +8 -7
  129. package/docs/api/stream.md +4 -5
  130. package/docs/api/terrain.md +3 -4
  131. package/docs/api/terrainDraw.md +1 -1
  132. package/docs/api/timeline.md +2 -2
  133. package/docs/api/tools.md +3 -1
  134. package/docs/api/triggers.md +2 -0
  135. package/docs/api/vegetationDraw.md +1 -1
  136. package/docs/api/water.md +6 -2
  137. package/docs/api/weather.md +19 -4
  138. package/docs/api/weatherDraw.md +1 -1
  139. package/docs/api/world.md +1 -1
  140. package/docs/recipes/01-new-game.md +3 -3
  141. package/docs/recipes/02-npc.md +3 -4
  142. package/docs/recipes/03-items-pickups.md +11 -11
  143. package/docs/recipes/04-quests.md +2 -0
  144. package/docs/recipes/05-props-bake.md +9 -9
  145. package/docs/recipes/06-clock-events.md +6 -6
  146. package/docs/recipes/07-flow-scenes-pause.md +18 -15
  147. package/docs/recipes/08-weather-sky.md +5 -5
  148. package/docs/recipes/09-materials-lights-models.md +3 -3
  149. package/docs/recipes/10-blender-level.md +16 -4
  150. package/docs/recipes/11-vehicles.md +18 -6
  151. package/docs/recipes/12-navmesh.md +52 -8
  152. package/docs/recipes/13-animation.md +34 -8
  153. package/docs/recipes/14-custom-module.md +20 -8
  154. package/docs/recipes/15-perf.md +4 -4
  155. package/docs/recipes/16-dev-bridge.md +9 -8
  156. package/docs/recipes/18-world.md +13 -5
  157. package/docs/recipes/19-shooting-picking.md +3 -2
  158. package/docs/recipes/20-content-actions-save.md +26 -6
  159. package/docs/recipes/21-camera.md +17 -23
  160. package/docs/recipes/22-shop-gold.md +21 -12
  161. package/docs/recipes/23-ops.md +19 -15
  162. package/docs/recipes/26-ui-parts.md +3 -2
  163. package/docs/recipes/27-net.md +3 -3
  164. package/docs/recipes/28-terrain.md +3 -3
  165. package/docs/recipes/29-grid.md +1 -1
  166. package/docs/recipes/30-templates.md +10 -13
  167. package/docs/recipes/31-audio.md +2 -2
  168. package/docs/recipes/32-action-game.md +6 -5
  169. package/docs/recipes/33-stream-sources.md +4 -1
  170. package/docs/recipes/34-environment-lighting.md +7 -8
  171. package/docs/recipes/35-picture-from-reference.md +13 -9
  172. package/docs/recipes/36-ground-plants.md +3 -2
  173. package/docs/recipes/40-scene.md +11 -10
  174. package/docs/recipes/43-shader-patches-surfaces.md +7 -7
  175. package/docs/recipes/44-water-weather-hooks.md +9 -8
  176. package/docs/recipes/45-cascaded-shadows.md +3 -4
  177. package/docs/recipes/46-blender-art-route.md +3 -3
  178. package/docs/recipes/49-game-module-contract.md +2 -1
  179. package/docs/recipes/50-own-renderer.md +1 -0
  180. package/docs/recipes/51-capability-catalog.md +14 -8
  181. package/docs/recipes/52-around-the-picture.md +4 -4
  182. package/docs/recipes/55-mods-time-wrap.md +5 -4
  183. package/docs/recipes/56-webgpu-tsl.md +12 -1
  184. package/docs/recipes/57-control.md +30 -10
  185. package/docs/recipes/58-input.md +13 -0
  186. package/docs/recipes/60-judge-the-picture.md +1 -1
  187. package/docs/recipes/62-picture-code.md +106 -48
  188. package/docs/recipes/63-third-person-start.md +2 -1
  189. package/docs/recipes/64-particles.md +53 -4
  190. package/docs/recipes/65-swarm.md +2 -2
  191. package/docs/recipes/66-common-tasks.md +313 -0
  192. package/examples/action/.threedog/content-index.json +1 -1
  193. package/examples/action/GAMEMAP.md +3 -3
  194. package/examples/perf-island/.threedog/content-index.json +1 -1
  195. package/examples/perf-island/GAMEMAP.md +3 -3
  196. package/examples/perf-island/main.js +2 -2
  197. package/examples/plain-picture/GAMEMAP.md +3 -1
  198. package/examples/rc2d/GAMEMAP.md +1 -1
  199. package/examples/rc2d/rc2d.js +1 -1
  200. package/examples/styletest/.threedog/content-index.json +1 -1
  201. package/examples/styletest/GAMEMAP.md +3 -3
  202. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  203. package/examples/world/.threedog/content-index.json +1 -1
  204. package/examples/world/GAMEMAP.md +5 -4
  205. package/examples/world/main.js +3 -3
  206. package/index.d.ts +8 -5
  207. package/index.js +22 -1
  208. package/llms.txt +2 -1
  209. package/modules/ambience/Ambience.js +5 -3
  210. package/modules/calendar/index.js +7 -5
  211. package/modules/camera/FirstPersonCamera.js +3 -3
  212. package/modules/camera/FixedCamera.js +34 -20
  213. package/modules/camera/FollowCamera.js +20 -11
  214. package/modules/camera/RtsCamera.js +1 -0
  215. package/modules/camera/common.js +33 -22
  216. package/modules/camera/pixelSnap.js +62 -0
  217. package/modules/characters/Character.js +136 -43
  218. package/modules/characters/NPC.js +60 -28
  219. package/modules/characters/assetModel.js +2 -2
  220. package/modules/characters/astar.js +47 -28
  221. package/modules/characters/character.contract.js +21 -0
  222. package/modules/characters/contract.js +17 -3
  223. package/modules/characters/index.js +94 -34
  224. package/modules/characters/moveHelpers.js +80 -15
  225. package/modules/characters/mover.contract.js +14 -0
  226. package/modules/characters/movers/common.js +6 -4
  227. package/modules/characters/movers/rapier.js +12 -5
  228. package/modules/characters/movers/simple.js +25 -12
  229. package/modules/characters/movers/support.js +18 -7
  230. package/modules/characters/npcAvoid.js +15 -12
  231. package/modules/characters/npcSim.js +75 -25
  232. package/modules/characters/npcView.js +13 -6
  233. package/modules/characters/pathAsync.js +74 -24
  234. package/modules/characters/pathJob.js +38 -21
  235. package/modules/characters/player.js +59 -47
  236. package/modules/characters/seat.js +56 -0
  237. package/modules/characters/vehicle.contract.js +8 -5
  238. package/modules/characters/walkTo.js +31 -18
  239. package/modules/collision/Collision.js +44 -26
  240. package/modules/collision/contract.js +2 -2
  241. package/modules/collision/grid.js +6 -1
  242. package/modules/content/explain.js +1 -1
  243. package/modules/content/fields.js +3 -3
  244. package/modules/content/ids.js +3 -1
  245. package/modules/content/index.js +83 -27
  246. package/modules/content/loader.js +110 -130
  247. package/modules/content/markers.js +1 -1
  248. package/modules/content/models.js +48 -14
  249. package/modules/content/packs.js +2 -1
  250. package/modules/content/places.js +5 -4
  251. package/modules/content/props.js +8 -6
  252. package/modules/content/rules.js +29 -47
  253. package/modules/content/templates.js +66 -35
  254. package/modules/content/words.js +19 -6
  255. package/modules/debug/DebugPanel.js +4 -2
  256. package/modules/flow/contract.js +1 -0
  257. package/modules/flow/index.js +24 -14
  258. package/modules/gameplay/Container.js +5 -2
  259. package/modules/gameplay/Containers.js +9 -1
  260. package/modules/gameplay/Dialogue.js +82 -25
  261. package/modules/gameplay/Interactions.js +61 -32
  262. package/modules/gameplay/Inventory.js +56 -13
  263. package/modules/gameplay/Quests.js +133 -24
  264. package/modules/gameplay/boxOps.js +7 -0
  265. package/modules/gameplay/dialogueBubbles.js +14 -9
  266. package/modules/gameplay/inventoryOps.js +11 -7
  267. package/modules/gameplay/pickups.js +43 -16
  268. package/modules/gameplay/questLog.js +4 -2
  269. package/modules/gameplay/questSave.js +6 -1
  270. package/modules/gameplay/quests.contract.js +1 -1
  271. package/modules/grid/Grid.js +1 -1
  272. package/modules/grid/Layer.js +8 -4
  273. package/modules/grid/index.js +21 -15
  274. package/modules/grid/ops.js +43 -46
  275. package/modules/grid/tiles.js +1 -1
  276. package/modules/hlod/index.js +6 -3
  277. package/modules/hud/index.js +6 -4
  278. package/modules/hud/parts.js +4 -4
  279. package/modules/level/contract.js +2 -2
  280. package/modules/level/heightfield.js +17 -21
  281. package/modules/level/index.js +83 -26
  282. package/modules/level/load.js +165 -48
  283. package/modules/level/nodes.js +34 -16
  284. package/modules/lights/index.js +6 -3
  285. package/modules/lights/sources.js +3 -1
  286. package/modules/music/Music.js +4 -2
  287. package/modules/nav/contract.js +7 -5
  288. package/modules/nav/index.js +174 -44
  289. package/modules/nav/navPath.js +45 -10
  290. package/modules/net/index.js +1 -1
  291. package/modules/particles/Particles.js +85 -22
  292. package/modules/particles/effect.js +80 -28
  293. package/modules/particles/shaders.js +17 -0
  294. package/modules/photo/Photo.js +12 -10
  295. package/modules/rigid/RigidBodies.js +200 -57
  296. package/modules/rigid/Vehicles.js +15 -5
  297. package/modules/rigid/collider3d.contract.js +26 -0
  298. package/modules/rigid/ragdoll.js +55 -44
  299. package/modules/rigid/ragdollBones.js +83 -33
  300. package/modules/rigid/refresh.js +10 -0
  301. package/modules/rigid/sync.js +46 -15
  302. package/modules/settings/Settings.js +84 -37
  303. package/modules/settings/apply.js +15 -8
  304. package/modules/settings/sections.js +7 -4
  305. package/modules/settings/strings.js +2 -2
  306. package/modules/sky/skyModule.js +3 -1
  307. package/modules/swarm/Swarm.js +16 -6
  308. package/modules/terrain/ChunkManager.js +10 -16
  309. package/modules/terrain/index.js +17 -11
  310. package/modules/terrain/terrainEdit.js +13 -2
  311. package/modules/terrain/terrainGen.js +5 -3
  312. package/modules/terrain/terrainShape.js +1 -1
  313. package/modules/timeline/Timeline.js +58 -26
  314. package/modules/timeline/Tween.js +19 -13
  315. package/modules/timeline/shots.js +19 -10
  316. package/modules/triggers/index.js +87 -20
  317. package/modules/vegetation/Vegetation.js +4 -3
  318. package/modules/vegetation/draw.js +16 -0
  319. package/modules/vegetation/groundChunks.js +10 -7
  320. package/modules/vegetation/index.js +30 -7
  321. package/modules/water/Water.js +6 -2
  322. package/modules/weather/Weather.js +16 -15
  323. package/modules/weather/weatherDraw.js +7 -6
  324. package/modules/world/World.js +20 -7
  325. package/modules/world/explain.js +1 -1
  326. package/modules/world/index.js +13 -6
  327. package/modules/world/persist.js +23 -8
  328. package/modules/world/pos.js +4 -4
  329. package/modules/world/records.js +13 -7
  330. package/modules/world/sim.js +74 -23
  331. package/modules/world/simFar.js +2 -2
  332. package/modules/world/state.js +31 -6
  333. package/modules/world/thingSource.js +16 -3
  334. package/modules/world/views.js +19 -8
  335. package/package.json +7 -1
  336. package/render/PostFX.js +47 -29
  337. package/render/backend.js +5 -1
  338. package/render/fx/particles.tsl.js +8 -6
  339. package/render/fx/postWebGPU.tsl.js +3 -3
  340. package/render/layers.js +1 -1
  341. package/render/lightmap.js +23 -3
  342. package/render/occlusion.js +43 -12
  343. package/render/patches.js +2 -2
  344. package/render/postWebGL.js +4 -3
  345. package/render/probes.js +25 -0
  346. package/render/shadows.js +2 -2
  347. package/types/core.d.ts +142 -55
  348. package/types/gameplay.d.ts +92 -40
  349. package/types/generated/core/base/I18n.d.ts +2 -2
  350. package/types/generated/core/input/Input.d.ts +16 -2
  351. package/types/generated/core/input/inputSeat.d.ts +26 -0
  352. package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
  353. package/types/generated/core/ops/Ops.d.ts +2 -1
  354. package/types/generated/core/ops/control.d.ts +12 -2
  355. package/types/generated/core/saves/Saves.d.ts +26 -6
  356. package/types/generated/core/saves/session.d.ts +1 -1
  357. package/types/generated/core/scene/Views.d.ts +1 -1
  358. package/types/generated/core/stream/Stream.d.ts +6 -4
  359. package/types/generated/modules/grid/Grid.d.ts +1 -0
  360. package/types/generated/modules/particles/Particles.d.ts +4 -3
  361. package/types/generated/modules/timeline/Timeline.d.ts +5 -4
  362. package/types/generated/modules/weather/Weather.d.ts +1 -7
  363. package/types/generated/modules/world/World.d.ts +6 -4
  364. package/types/generated/render/PostFX.d.ts +6 -14
  365. package/types/nav.d.ts +36 -4
  366. package/types/physics.d.ts +55 -7
  367. package/types/pixel.d.ts +75 -0
  368. package/types/world.d.ts +14 -8
  369. package/ui/Parts.js +9 -2
  370. package/ui/theme.js +2 -2
  371. package/core/scene/engineCamera.js +0 -32
  372. package/modules/camera/projection.js +0 -21
@@ -1,8 +1,10 @@
1
1
  // Gameplay modules: timeline, level, triggers, world changes, particles, settings, music, characters/NPCs, interactions, dialogue, inventory,
2
2
  // quests, photo mode, ambience, debug.
3
3
  import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike, Material } from './common';
4
- import type { Engine } from './core';
4
+ import type { Engine, SaveTurn } from './core';
5
+ import type { LinkCrossing, NavPathPoint } from './nav';
5
6
  import type { Input } from './generated/core/input/Input';
7
+ import type { Seat } from './generated/core/input/inputSeat';
6
8
  import type { Animator, AnimatorOptions, Rideable } from './physics';
7
9
  import type { WorldRecord } from './generated/modules/world/World';
8
10
 
@@ -10,7 +12,7 @@ import type { WorldRecord } from './generated/modules/world/World';
10
12
  // Timeline timeline()
11
13
  // ======================================================================
12
14
 
13
- /** Promise of a tween: await it to wait for the end; finish() jumps to the end now, remove() stops at the current position */
15
+ /** Promise of a tween: await it to wait for the end, it rejects if a write throws; finish() jumps to the end now, remove() stops at the current position */
14
16
  export interface TweenPromise extends Promise<boolean> {
15
17
  finish(): void;
16
18
  remove(): void;
@@ -101,12 +103,20 @@ export interface LevelOptions {
101
103
  sharpEdge?: number;
102
104
  /** Hide the marker placeholder meshes, default true @experimental */
103
105
  hideMarkers?: boolean;
106
+ /** true: do not take the ground slot; compositeGround({ parts: [{ of: 'level' }] }) does and reads level.ground */
107
+ part?: boolean;
104
108
  /** Add the scene to engine.scene, default true @experimental */
105
109
  addToScene?: boolean;
106
110
  }
107
111
  /** Markers in the level (spawn, npc_*, trigger_*, marker_*), in world coordinates */
108
112
  export interface LevelMarker { name: string; position: Vector3; quaternion: Quaternion; scale: Vector3; userData: Record<string, any>; object: Object3D }
109
113
  export interface LevelLoadedEvent { root: Object3D; markers: Record<string, LevelMarker>; spawn: Vector3 }
114
+ /** source: the file or asset name; null for a code-built scene */
115
+ export interface LevelLoadingEvent { source: string | null }
116
+ export interface LevelFailedEvent { source: string | null; error: unknown }
117
+ export interface LevelPlayableEvent { root: Object3D }
118
+ /** A level left: unload(), or a switch just before the new one commits. source: its file or asset name, null for a code-built one */
119
+ export interface LevelUnloadedEvent { source: string | null }
110
120
 
111
121
  /** engine.level */
112
122
  export interface Level {
@@ -118,7 +128,7 @@ export interface Level {
118
128
  spawn: Vector3;
119
129
  /** Heightfield (for debugging) @experimental */
120
130
  heightfield: any;
121
- /** Whether loading is finished */
131
+ /** The level's state is committed and nothing is loading; level:loaded fires at this moment, level:playable once every module and required nearby build settled too. After unload() it is true with no level, since nothing is loading: root says whether a level stands */
122
132
  readonly ready: boolean;
123
133
  /** Get a marker, null if none */
124
134
  marker(name: string): LevelMarker | null;
@@ -127,10 +137,12 @@ export interface Level {
127
137
  /** Unload the level (the scene is fully deleted with engine.remove; collision, ray registrations and things registered with track are removed together) @experimental */
128
138
  unload(): void;
129
139
  /**
130
- * Change level: unload the current one, load the new one (glTF path/asset name, or a THREE object), and emit level:loaded when done. When a load
131
- * changes level, the save system waits for it
140
+ * Change level (glTF path/asset name, or a THREE object). The new level is built first and replaces the old one only when that worked: level:loaded fires
141
+ * then. On failure the old level stays, level:failed fires and the Promise rejects. When a load changes level, the save system waits for it, and a
142
+ * level that fails rolls the save back. A load overtaken by a newer one or an unload resolves without a level.
143
+ * During a save load it waits for that load to end; a part's load() or an afterLoad passes the turn it got, and it goes at once
132
144
  */
133
- load(urlOrScene: string | Object3D): Promise<void>;
145
+ load(urlOrScene: string | Object3D, opts?: { turn?: SaveTurn }): Promise<void>;
134
146
  /**
135
147
  * Register things that belong to the current level and need not be kept (the { remove() } handles of triggers...); they are deleted automatically on
136
148
  * level change / unload; returns the same handle. world data that keeps state (NPCs, pickups, props) needs no registration: with a zone, a level
@@ -181,6 +193,10 @@ export interface TriggerOptions {
181
193
  cooldown?: number;
182
194
  /** Custom data */
183
195
  userData?: Record<string, any>;
196
+ /** 'zone' (default): one enter when the first actor arrives, one exit when the last leaves. 'each': an enter, stay and exit per actor (a door counting entrants); inside is true while anyone is in */
197
+ occupancy?: 'zone' | 'each';
198
+ /** Your own region instead of a shape: the plain volume addWaterBody takes. bounds ({ min, max }) lets the zone be indexed and drawn in the debug view; without it the zone is checked every step */
199
+ volume?: { contains(p: { x: number; y: number; z: number }): boolean; bounds?: { min: { x: number; y: number; z: number }; max: { x: number; y: number; z: number } } };
184
200
  }
185
201
  /** A trigger zone (the return value of add()) */
186
202
  export interface Trigger {
@@ -259,12 +275,12 @@ export interface ParticleOptions {
259
275
  wind?: number;
260
276
  /** Wind direction [x, y, z] */
261
277
  windDir?: number[];
262
- /** Size at birth / at death (meters) */
263
- size?: Range;
264
- /** Color at birth / at death (one color, or [birth, death]; an array, not a tuple, so a plain JS literal [0xffffff, 0xdddddd] type-checks) */
265
- color?: ColorLike | ColorLike[];
266
- /** Opacity at birth / at death, 0–1 */
267
- opacity?: Range;
278
+ /** Size at birth / at death (meters), or stops over life: evenly spaced [a, b, c] or timed [[0, a], [0.2, b], [1, c]] (0 birth, 1 death) */
279
+ size?: Range | number[][];
280
+ /** Color at birth / at death (one color, or [birth, death]; an array, not a tuple, so a plain JS literal [0xffffff, 0xdddddd] type-checks), or stops over life as for size */
281
+ color?: ColorLike | ColorLike[] | ColorLike[][];
282
+ /** Opacity at birth / at death, 0–1, or stops over life as for size: [[0, 0], [0.1, 0.8], [1, 0]] fades in, then out */
283
+ opacity?: Range | number[][];
268
284
  /** Texture (asset name, path or THREE.Texture); a soft round dot if omitted */
269
285
  texture?: string | Texture | null;
270
286
  /** 'normal' | 'additive' (glowing blend, for sparks) */
@@ -277,11 +293,17 @@ export interface ParticleOptions {
277
293
  fog?: boolean;
278
294
  /** Largest on-screen size of one particle in pixels (smoke drifting past the camera stays bounded), default 512 */
279
295
  maxPixels?: number;
296
+ /** Default particles per meter the emitter moves for attach, on top of rate, spread along the path it moved; default 0 @experimental */
297
+ ratePerMeter?: number;
298
+ /** Meters over which a particle fades where it meets what writes depth; default 0, off. Set at define, not in overrides. On WebGLRenderer it costs one depth-only draw of the scene per render while such an effect is on screen @experimental */
299
+ soft?: number;
280
300
  }
281
301
  /** Continuous emitter returned by attach() (a handle) */
282
302
  export interface ParticleEmitter extends Handle {
283
303
  /** Particles per second (can be changed at any time) */
284
304
  rate: number;
305
+ /** Particles per meter the object moves, on top of rate (can be changed at any time) @experimental */
306
+ ratePerMeter: number;
285
307
  /** false pauses */
286
308
  active: boolean;
287
309
  /** Stop and remove (also removed automatically when the object leaves the scene) */
@@ -542,7 +564,7 @@ export interface CharacterOptions {
542
564
  airJumpSpeed?: number;
543
565
  /** How long a jump() pressed early waits for the ground (seconds), default 0.12 */
544
566
  jumpBuffer?: number;
545
- /** Falling out of the level: below belowY (or when belowY(character) is true) character:fall fires and, unless a listener calls preventDefault(), it returns to safeGround. false (default) = off */
567
+ /** Falling out of the level: below belowY (or when belowY(character) is true) character:fall fires and the rule 'fall' decides: back to safeGround by default, engine.mod('fall', { owner, id, set: false }) leaves it to the game. false (default) = off */
546
568
  fall?: false | { belowY: number | ((character: Character) => boolean) };
547
569
  /** Time channel its movement and animation follow when the engine drives it (player default 'player', others 'world') */
548
570
  channel?: string;
@@ -563,7 +585,7 @@ export interface CharacterOptions {
563
585
  /** Skeletal animation state machine config (states, blend trees, one-shot actions), see AnimatorOptions */
564
586
  animation?: AnimatorOptions | null;
565
587
  /** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) | 'manual' the game writes the position, move() only updates grounded / support / safeGround / fall */
566
- mover?: 'simple' | 'rapier' | 'manual';
588
+ mover?: 'simple' | 'rapier' | 'manual' | ((character: any, engine: any) => { name: string; move(x: number, z: number, run: boolean, dt: number, y: number): void; dispose?(): void; leave?(): void });
567
589
  /**
568
590
  * Which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward()) | 'target' (toward faceTarget) | 'manual'
569
591
  * (only face() turns it)
@@ -575,7 +597,7 @@ export interface CharacterOptions {
575
597
  /** Character facing mode, see CharacterOptions.faceMode */
576
598
  export type FaceMode = 'move' | 'camera' | 'target' | 'manual';
577
599
  /** What a player control function returns: world direction (length 0–1 scales the speed), run; null = stand still. Speed changes: engine.mod('move.speed', { owner, id: 'player', ... }) */
578
- export type MoveRequest = { x: number; z: number; run?: boolean } | null | undefined;
600
+ export type MoveRequest = { x: number; y?: number; z: number; run?: boolean } | null | undefined;
579
601
  /**
580
602
  * How the player's input steers it (the base holder of its control slot, owner 'player-input'): 'camera' movement keys relative to the camera |
581
603
  * a function returning the move request. The game moving the player itself takes control: engine.control.take(player, { owner, layer: 'script', step })
@@ -583,6 +605,10 @@ export type MoveRequest = { x: number; z: number; run?: boolean } | null | undef
583
605
  export type PlayerControl = 'camera' | ((player: Character, input: Input, dt: number) => MoveRequest);
584
606
  /** Parameters of createPlayer() */
585
607
  export interface PlayerOptions extends CharacterOptions {
608
+ /** A further local player's id and world record; left out, the one player (engine.player) */
609
+ id?: string;
610
+ /** The seat that drives this player (engine.input.seat); default engine.input */
611
+ input?: Seat;
586
612
  /** Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted */
587
613
  spawn?: PositionLike;
588
614
  /**
@@ -667,8 +693,8 @@ export declare class Character {
667
693
  /** Last spot it stood still on safe ground (where a fall returns it); null until it first stands. Saved with the motion */
668
694
  safeGround: Vector3 | null;
669
695
  /** How it walks now; name is 'simple' | 'rapier' | 'manual', controller is the native Rapier character controller (when rapier). Assign a name to switch: c.mover = 'manual' */
670
- get mover(): { name: 'simple' | 'rapier' | 'manual'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number): void; dispose?(): void };
671
- set mover(name: 'simple' | 'rapier' | 'manual');
696
+ get mover(): { name: string; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number, y?: number): void; dispose?(): void; leave?(): void };
697
+ set mover(v: CharacterOptions['mover']);
672
698
  /** Skeletal animation state machine (when there is a glTF model; null while a model named by asset is still loading) */
673
699
  anim: Animator | null;
674
700
  /** false while a model named by asset is loading (the placeholder body shows); true otherwise, also after a failed load (placeholder kept) */
@@ -723,7 +749,7 @@ export declare class Character {
723
749
  * A character someone controls (engine.control.of(ch)) moves only through its holder: called from anywhere else it is control-bypass in dev;
724
750
  * take control and use handle.move() / step instead
725
751
  */
726
- move(dirX: number, dirZ: number, run: boolean, dt: number): void;
752
+ move(dirX: number, dirZ: number, run: boolean, dt: number, dirY?: number): void;
727
753
  /** Ground type underfoot ('water' while swimming) */
728
754
  groundType(): string;
729
755
  /** Turn at once to a position, or to an angle in radians (0 = +Z) */
@@ -916,7 +942,9 @@ export interface CharactersApi {
916
942
  * The 'camera' player control as a value: keys / stick relative to the camera, the 'run' action if bound, input.autopilot. Reused object; call it
917
943
  * inside your own control function to wrap it
918
944
  */
919
- moveInput(): { x: number; z: number; run: boolean };
945
+ moveInput(seat?: Seat): { x: number; z: number; run: boolean };
946
+ /** Join the vehicles a saved rider can be seated in again, before or after the load */
947
+ addVehicle(vehicle: any): { remove(): void };
920
948
  /**
921
949
  * Something characters stand on and ride (moving platform, lift, raft). Move the object any way (onFixed before or after the player, a timeline,
922
950
  * physics): riders follow how its matrix changed, so the order does not matter. safe: false = never a respawn spot; carry 'position+yaw' turns riders
@@ -929,30 +957,37 @@ export interface CharactersApi {
929
957
  * position and the vehicle; loading an on-foot save exits the vehicle first
930
958
  * @experimental
931
959
  */
932
- removePlayer(): void;
960
+ removePlayer(id?: string): void;
933
961
  /**
934
- * Pathfinding (the single entry point): uses the navmesh when nav is installed and ready, otherwise the A* fallback. Returns a path [{ x, z }...], or
962
+ * Pathfinding (the single entry point): uses the navmesh when nav is installed and ready, otherwise the A* fallback. Returns a path [{ x, y, z }...], or
935
963
  * null if unreachable
936
964
  */
937
- findPath(from: PositionLike, to: PositionLike, opts?: FindPathOptions & { detailed?: false }): XZ[] | null;
965
+ findPath(from: PositionLike, to: PositionLike, opts?: FindPathOptions & { detailed?: false }): NavPathPoint[] | null;
938
966
  /**
939
967
  * Pass detailed: true: returns { status, path }, distinguishing 'ok' found | 'noPath' unreachable | 'notReady' nav is installed but the mesh is not
940
968
  * built yet (path is the A* fallback result and may be inaccurate)
941
969
  */
942
970
  findPath(from: PositionLike, to: PositionLike, opts: FindPathOptions & { detailed: true }): PathResult;
971
+ /** What a game's mover calls to take part in contact, each optional (recipe 57): a mover calling none owns contact itself */
972
+ kit: { beginMove(c: any): boolean; groundAt(c: any, x: number, z: number, y?: number): number; endMove(c: any, dt: number, hit: any, ground?: string): void; ownState(c: any, base: string, speed: number): void };
943
973
  /**
944
974
  * findPath for many callers (NPC crowds, AI squads): solved in engine.threads workers; done(path, status) runs on a fixed step a few steps later (same
945
975
  * paths with threads on or off). Recipe 12 section 4
946
976
  */
947
977
  findPathAsync(
948
- from: PositionLike, to: PositionLike, done: (path: XZ[] | null, status: 'ok' | 'noPath' | 'notReady') => void,
978
+ from: PositionLike, to: PositionLike, done: (path: NavPathPoint[] | null, status: 'ok' | 'noPath' | 'notReady') => void,
949
979
  opts?: { radius?: number; step?: number; maxNodes?: number }
950
980
  ): { remove(): void };
951
981
  /** How many findPathAsync requests leave per fixed step (default 32); the rest wait for the next steps */
952
982
  pathsPerStep: number;
983
+ /**
984
+ * Bends a link crossing away from its straight line: t 0-1, called each step after position is set on the line, write to position. Depends only on its arguments, so a
985
+ * crossing saved halfway resumes on the same curve. null = the straight line @experimental
986
+ */
987
+ linkPose: ((t: number, position: Vector3, crossing: LinkCrossing, character: Character) => void) | null;
953
988
  }
954
989
  /** Return value of findPath(..., { detailed: true }) */
955
- export interface PathResult { status: 'ok' | 'noPath' | 'notReady'; path: XZ[] | null }
990
+ export interface PathResult { status: 'ok' | 'noPath' | 'notReady'; path: NavPathPoint[] | null }
956
991
  /**
957
992
  * Parameters of findSpawn(): minH/maxH height range (meters, default unlimited), maxSlope maximum slope (default 0.3), waterMargin minimum meters above
958
993
  * the water (default 0.5)
@@ -963,6 +998,8 @@ export interface CharactersOptions {
963
998
  npcs?: boolean;
964
999
  /** Near tiers for large NPC crowds, off by default (every near NPC walks every fixed step); same as engine.npcs.tiers(opts) @experimental */
965
1000
  npcTiers?: { fullRadius: number; nearEvery: number };
1001
+ /** The rule 'fall' for everyone: 'rescue' brings what falls out of the world back; left out, the engine rescues nothing. engine.mod('fall', ...) from the game sits above it */
1002
+ fall?: 'rescue' | false | ((facts: any, engine: any) => 'rescue' | false);
966
1003
  /** What every character's Animator starts from, e.g. { fade: 0.15 }; a model's manifest mapping and the character's own animation win over it */
967
1004
  animation?: AnimatorOptions;
968
1005
  }
@@ -970,7 +1007,7 @@ export interface CharactersOptions {
970
1007
  * Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters,
971
1008
  * default engine.movement.radius); for detailed see findPath
972
1009
  */
973
- export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean }
1010
+ export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean; id?: string }
974
1011
 
975
1012
  // ======================================================================
976
1013
  // Interactions interactions()
@@ -1195,7 +1232,7 @@ export interface Dialogue {
1195
1232
  */
1196
1233
  say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; channel?: DialogueChannel; onCancel?: (() => void) | null } & BubbleOptions): SayPromise;
1197
1234
  /** Lines on the bubble channel now */
1198
- bubbles(): { speaker: string; text: string; queued: number }[];
1235
+ bubbles(): { speaker: string; text: string; queued: number; run?: number; choices?: string[] }[];
1199
1236
  /** End the main dialogue */
1200
1237
  end(): void;
1201
1238
  // Advancing and choosing are ops: engine.ops.run('dialogue.advance') / engine.ops.run('dialogue.choose', { index })
@@ -1209,6 +1246,8 @@ export interface DialogueOptions {
1209
1246
  advanceActions?: string[];
1210
1247
  /** A bubble line stays this many seconds plus its reading time (about 15 characters a second) unless say() gives seconds, default 2 */
1211
1248
  holdSeconds?: number;
1249
+ /** A bubble script reaching a node with choices: 'end' (default: warn, the script ends there) or 'ask' (the line stays with its choices until engine.ops.run('dialogue.choose', { index, run }); run is in dialogue.bubbles()) */
1250
+ bubbleChoice?: 'end' | 'ask';
1212
1251
  }
1213
1252
  /**
1214
1253
  * What the 'dialogue' UI part receives in update(view) (show() comes first, hide() when the dialogue ends). Call advance() / choose(i) from your UI:
@@ -1407,7 +1446,7 @@ export interface Container {
1407
1446
  list(): ItemEntry[];
1408
1447
  /** How many more fit (Infinity = no limit), for an item without data, with this data, or like an existing entry key */
1409
1448
  room(x: string, data?: Record<string, any>): number;
1410
- /** Add n (default 1), optionally with data; returns { ok: true, key, added } (added: how many fit), or { ok: false, code: 'full' } when none fit; silent suppresses the toast (only the bag of engine.actor shows one) */
1449
+ /** Add n (default 1), optionally with data; returns { ok: true, key, added } (added: how many fit), or { ok: false, code: 'full' } when none fit; the answer is an object, so read .ok: if (add(...)) is true even when the bag is full; silent suppresses the toast (only the bag of engine.actor shows one) */
1411
1450
  add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): ItemAddResult;
1412
1451
  /** Remove n (default 1) of an item or entry key, returns false if there are not enough */
1413
1452
  remove(x: string, n?: number): boolean;
@@ -1504,6 +1543,8 @@ export interface QuestStep {
1504
1543
  id?: string;
1505
1544
  text: string;
1506
1545
  done: (e: Engine) => boolean;
1546
+ /** The step after this one: a step id, or e => id asked when this step is done (a branch); false finishes the quest here. Default: the next step in the list. steps already passed are in quests.state(id).visited */
1547
+ next?: string | false | ((e: Engine) => string | false | undefined);
1507
1548
  /**
1508
1549
  * Objective: a place name (content.place), object, character, { x, z }, { nearest: itemId } or a function returning an objective; with the hud module
1509
1550
  * the current step shows a marker automatically
@@ -1513,7 +1554,7 @@ export interface QuestStep {
1513
1554
  /** One goal of a parallel step; optional goals do not hold the step back */
1514
1555
  export interface QuestPart { /** Stable id within the step (default: its position) */ id?: string; text: string; done: (e: Engine) => boolean; target?: HudTarget; optional?: boolean }
1515
1556
  /** Parallel goals: done when every non-optional part is done, in any order; text defaults to the required parts joined */
1516
- export interface QuestParallelStep { /** Stable id (default: the step's position) */ id?: string; text?: string; all: QuestPart[] }
1557
+ export interface QuestParallelStep { /** Stable id (default: the step's position) */ id?: string; text?: string; all: QuestPart[]; /** As QuestStep.next */ next?: string | false | ((e: Engine) => string | false | undefined) }
1517
1558
  /** Quest definition */
1518
1559
  export interface QuestDef {
1519
1560
  /** Title */
@@ -1522,8 +1563,10 @@ export interface QuestDef {
1522
1563
  desc?: string;
1523
1564
  /** Steps (completed in order); a step may be parallel goals { all: [...] } */
1524
1565
  steps: (QuestStep | QuestParallelStep)[];
1525
- /** Called on completion (give rewards) */
1526
- reward?: (e: Engine) => void;
1566
+ /** Called on completion (give rewards). Returning a failure ({ ok: false, code }, e.g. what e.content.run or e.inventory.add answer) means it was not paid: see onUnpaid */
1567
+ reward?: (e: Engine) => any;
1568
+ /** The game's decision for a reward not given, with the failure as answer. Without it the items that did not fit stay owed (list().owed, saved) and go into the bag when there is room */
1569
+ onUnpaid?: (e: Engine, answer: { ok: false; code: string; facts: any }) => void;
1527
1570
  /** Checked while active; true fails the quest (quest:fail; start(id) can begin it again). @example fail: e => e.vars.flag('caravanLost') */
1528
1571
  fail?: (e: Engine) => boolean;
1529
1572
  /** Called when the quest fails */
@@ -1538,7 +1581,7 @@ export interface Quests {
1538
1581
  /** Start a quest */
1539
1582
  start(id: string): void;
1540
1583
  /** One quest's progress (a copy): step index, step count, done, failed, active; null before it starts */
1541
- state(id: string): { step: number; steps: number; done: boolean; failed: boolean; active: boolean } | null;
1584
+ state(id: string): { step: number; steps: number; done: boolean; failed: boolean; active: boolean; visited: string[] } | null;
1542
1585
  /** Finish the current step from code (its done() is not asked) and go on; the last step completes the quest. false when not active */
1543
1586
  advance(id: string): boolean;
1544
1587
  /** @experimental */ isDone(id: string): boolean;
@@ -1582,7 +1625,7 @@ export interface QuestsOptions {
1582
1625
  * Messages on quest start / step / done: true a toast with kind 'quest' (default) · false none · a function to show them your way.
1583
1626
  * @example quests({ notify: false }) quests({ notify: ({ type, text }) => type === 'done' && myBanner(text) })
1584
1627
  */
1585
- notify?: boolean | ((msg: { type: 'start' | 'step' | 'done'; id: string; text: string }) => void);
1628
+ notify?: boolean | ((msg: { type: 'start' | 'step' | 'done' | 'unpaid'; id: string; text: string }) => void);
1586
1629
  }
1587
1630
 
1588
1631
  // ======================================================================
@@ -1856,7 +1899,11 @@ export interface ContentConditionDef {
1856
1899
  describe?(value: any): string;
1857
1900
  }
1858
1901
  /** Parameters of content.load(): places is place name -> position. Models are asset names (engine.assets.manifest / an asset pack), not an option */
1859
- export interface ContentLoadOptions { places?: Record<string, PositionLike> }
1902
+ export interface ContentLoadOptions {
1903
+ places?: Record<string, PositionLike>;
1904
+ /** Inside a save part's load() or a module's afterLoad: the turn it got. Without it this load waits for that replacement to end */
1905
+ turn?: SaveTurn;
1906
+ }
1860
1907
  /** A content pack: the object of content/index.js, or a folder / npm package exporting the same tables. Data only: it names assets, never paths or code */
1861
1908
  export type ContentPack = Record<string, any> & { name?: string; audio?: import('./core').ContentAudio };
1862
1909
  /**
@@ -1873,9 +1920,12 @@ export interface PropDef {
1873
1920
  place?: string; x?: number; z?: number;
1874
1921
  /** Height above the ground (meters) */
1875
1922
  y?: number;
1876
- /** Rotation about the Y axis (radians) */
1877
- rot?: number;
1878
- scale?: number;
1923
+ /** Rotation about the Y axis (radians), or [x, y, z] radians to tilt it (a tilted collide needs a collider3d provider) */
1924
+ rot?: number | [number, number, number];
1925
+ /** Uniform scale, or [x, y, z] per axis */
1926
+ scale?: number | [number, number, number];
1927
+ /** false = do not snap to the ground: y is then the height in the world */
1928
+ ground?: boolean;
1879
1929
  /** Collision: 'box' cuboid of the bounds, 'circle' cylinder on the model's base, { circle, occluder } the same with its radius in model meters (scales with the prop) and occluder: false so the follow camera passes it; false none (default) */
1880
1930
  collide?: 'box' | 'circle' | false | { circle: number; occluder?: boolean };
1881
1931
  /** Register for ray acceleration (engine.raycast can hit it), default true */
@@ -1893,16 +1943,18 @@ export interface Content {
1893
1943
  markers: Map<string, HudMarker | undefined>;
1894
1944
  /**
1895
1945
  * Load content (items, pickups, vegetation, NPCs, dialogue, quests, keys, trigger zones, props, the game vocabulary rules): one pack, or a list of packs
1896
- * loaded together in order; an id defined by two packs of one call is an error naming both (a later separate load overrides by name instead)
1897
- * @example engine.content.load([baseContent, forestDlc], { places: { home } })
1946
+ * loaded together in order; an id defined by two packs of one call is an error naming both (a later separate load overrides by name instead).
1947
+ * Bad data throws on the line. The Promise answers for this load: it resolves when the pack committed, and rejects when it failed, after the old level and registrations are
1948
+ * back (err.notRestored lists what could not be). A load nobody awaits is reported all the same
1949
+ * @example await engine.content.load([baseContent, forestDlc], { places: { home } })
1898
1950
  */
1899
- load(data: ContentPack | ContentPack[], opts?: ContentLoadOptions): this;
1951
+ load(data: ContentPack | ContentPack[], opts?: ContentLoadOptions): Promise<void>;
1900
1952
  /** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.calendar.timeOfDay >= t }) */
1901
1953
  condition(name: string, def: ContentConditionDef): this;
1902
1954
  /** Whether a condition holds (object, array or function (e, { actor })); actor = whose bag has / lacks look in (default the running op's actor, else engine.actor) */
1903
1955
  test(cond: any, opts?: { actor?: string }): boolean;
1904
1956
  /** Run an effect (object, array or function (e, { actor })); actor = whose bag give / take change (default the running op's actor, else engine.actor) */
1905
- run(effect: any, opts?: { actor?: string }): any;
1957
+ run(effect: any, opts?: { actor?: string }): { ok: true } | { ok: false; code: string; facts: { failed: { word: string; code: string; facts: any }[] }; nextActions: any[] };
1906
1958
  /** Place name -> position (load's places first, then level markers), null if none */
1907
1959
  place(name: string): XZ | null;
1908
1960
  /** Position form in content { place?, x?, z? } -> world coordinates */
@@ -3,8 +3,8 @@
3
3
  export class I18n {
4
4
  /** Language used when a key is missing in the current one (default 'en') @experimental */
5
5
  fallback: string;
6
- /** Current language, e.g. 'zh-CN' ('zh' and 'zh-Hans' resolve to it, 'en-US' to 'en') @experimental */
7
- locale: any;
6
+ /** Current language, e.g. 'zh-CN' ('zh' and 'zh-Hans' resolve to it, 'en-US' to 'en'). Read-only: setLocale changes it, and tells i18n:change @returns {string} @experimental */
7
+ get locale(): string;
8
8
  /**
9
9
  * Register string tables (never overrides text the game gave)
10
10
  * @param {StringTables} tables
@@ -69,9 +69,12 @@ export class Input {
69
69
  };
70
70
  /**
71
71
  * Touch button (appears only on touch devices); pressing it triggers the action. labelKey is the string-table key of the button text (updates when the
72
- * language changes) @param {string} action @param {string} labelKey
72
+ * language changes). Returns { remove() }: a module tracks it, so the button leaves with the module
73
+ * @param {string} action @param {string} labelKey @returns {{ remove(): void }}
73
74
  */
74
- touchButton(action: string, labelKey: string): void;
75
+ touchButton(action: string, labelKey: string): {
76
+ remove(): void;
77
+ };
75
78
  /**
76
79
  * Press (down true) or release an action from code, through the same path as a real key: tests, AI drivers, replays. Presses the action's first bound key
77
80
  * and holds it until simulate(action, false), so the player walks like with a held key. Takes action names (moveForward, moveLeft, run, interact, ...;
@@ -80,6 +83,16 @@ export class Input {
80
83
  * @example engine.input.simulate('moveForward'); engine.step(1); engine.input.simulate('moveForward', false)
81
84
  */
82
85
  simulate(action: string, down?: boolean): void;
86
+ /**
87
+ * A local player's share of the input on a shared screen: its own keys and gamepad, read like engine.input (axis, down, pressed, released). Pass it to createPlayer({ id, input }).
88
+ * pad: gamepad index; that pad leaves engine.input and answers the game's pad bindings here. keys: { action: keys } for this seat alone. Two seats on one pad or key throw `input-seat`.
89
+ * @example const two = engine.input.seat({ pad: 1, keys: { moveForward: 'KeyI', moveBack: 'KeyK', moveLeft: 'KeyJ', moveRight: 'KeyL', jump: 'KeyU' } });
90
+ * @param {{ pad?: number, keys?: Record<string, string | string[]> }} [opts] @returns {Seat}
91
+ */
92
+ seat(opts?: {
93
+ pad?: number;
94
+ keys?: Record<string, string | string[]>;
95
+ }): Seat;
83
96
  /**
84
97
  * The player's rebinding (the settings menu calls this and saves it): replaces the game's keys on the settings layer of 'input.keys'.
85
98
  * keys null takes the player's choice away (the game's or the default keys show again). Works before the action is declared (a saved binding
@@ -198,3 +211,4 @@ export class Input {
198
211
  }
199
212
  import type { Pointer } from '../../../core';
200
213
  import type { Autopilot } from '../../../core';
214
+ import { Seat } from './inputSeat.js';
@@ -0,0 +1,26 @@
1
+ // Generated by npm run map, do not edit by hand. Source: packages/engine/core/input/inputSeat.js (edit the JSDoc in the source, then run npm run map)
2
+
3
+ export class Seat {
4
+ /** @param {any} input engine.input @param {{ pad?: number, keys?: Record<string, string | string[]> }} opts */
5
+ constructor(input: any, opts: {
6
+ pad?: number;
7
+ keys?: Record<string, string | string[]>;
8
+ });
9
+ /** The gamepad index this seat owns, if any @type {number | undefined} */ pad: number | undefined;
10
+ /** Who this seat acts for, as engine.actor for engine.input: createPlayer sets the player's id; interactions read it. Set it to hand the seat to a vehicle or a squad member @type {string | null} */ actor: string | null;
11
+ /** Same list as engine.input.actions: actions are the game's, a seat only routes them */
12
+ get actions(): any;
13
+ /** Held, as engine.input.down @param {string} action @returns {boolean} */
14
+ down(action: string): boolean;
15
+ /** Just pressed, as engine.input.pressed @param {string} action @returns {boolean} */
16
+ pressed(action: string): boolean;
17
+ /** Just released, as engine.input.released @param {string} action @returns {boolean} */
18
+ released(action: string): boolean;
19
+ /** Movement direction, as engine.input.axis @returns {{ x: number, y: number }} */
20
+ get axis(): {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ /** Give the keys and pad back: the pad goes to engine.input again if no other seat holds it */
25
+ remove(): void;
26
+ }
@@ -60,6 +60,20 @@ export class DebugOverrides {
60
60
  ms: number;
61
61
  partsChanged?: string[];
62
62
  }>;
63
+ /**
64
+ * Watch one value the engine does not watch by default, on the dev server: who writes it (file:line, frame) goes into engine.explain({ value: name }), and two writers fighting
65
+ * over it give a one-line hint. It observes; every write goes through. In a release build it does nothing: watching is false.
66
+ * Only watched values are seen, and a write that leaves the value unchanged is not: a value that shows no conflict may still have one.
67
+ * @example engine.debug.watch('boss.hp', boss, 'hp'); engine.debug.watch('player.pos', player, 'position');
68
+ * @param {string} name what explain and describe('picture').picture.writers call it; a name already in use is refused (watching false)
69
+ * @param {any} object the object, or a Color, Vector or rotation itself
70
+ * @param {string} [key] a plain property; a Color, Vector or rotation held there is watched inside. A property behind a class accessor cannot be hooked (watching false)
71
+ * @returns {{ watching: boolean, remove(): void }} remove() forgets the name; the accessor stays until reload and passes values through
72
+ */
73
+ watch(name: string, object: any, key?: string): {
74
+ watching: boolean;
75
+ remove(): void;
76
+ };
63
77
  /** The active view ({ mode: 'off', owner: null } when none) @returns {{ mode: string, owner: string | null, what?: string }} */
64
78
  viewState(): {
65
79
  mode: string;
@@ -94,7 +108,7 @@ export class DebugOverrides {
94
108
  clear(owner: string): number;
95
109
  /** Active overrides as plain data (describe().scene.overrides) */
96
110
  overrides(): any[];
97
- /** Active overrides on one object, for engine.thing(id).explain() */
111
+ /** Active overrides on one object, for engine.explain({ thing: id }) */
98
112
  overridesOn(obj: any): any[];
99
113
  /** Undo everything, drop / restore what the views put back, re-apply */
100
114
  dispose(): void;
@@ -23,7 +23,7 @@ export class Ops {
23
23
  * run (and can) may fail with { ok: false, code, facts, nextActions } (facts: object or list [{ id, field, actual, expected? }]); nextActions are the game's own suggestions.
24
24
  * owner (optional, checked by net() for peer requests): args => world record id whose `owner` field must equal the requesting actor.
25
25
  * @param {string} name
26
- * targets (optional): the thing ids, kinds or template names this op is for; engine.thing(id).explain().ops lists it ('*' = any thing).
26
+ * targets (optional): the thing ids, kinds or template names this op is for; engine.explain({ thing: id }).ops lists it ('*' = any thing).
27
27
  * @param {{ run: (e: any, args: any, ctx: OpContext) => any, can?: (e: any, args: any, ctx: OpContext) => true | string | { code: string, facts?: object, nextActions?: { op: string, args?: object }[] }, targets?: string | string[], args?: Record<string, string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean }>, offers?: (e: any, ctx: OpContext) => object[], reasons?: Record<string, string>, desc?: string, undo?: (e: any, args: any, value: any) => void, net?: 'peer' | 'local', owner?: (args: any) => string, atomic?: boolean, after?: (e: any, args: any, value: any, ctx: OpContext) => void }} def
28
28
  * @returns {{ remove(): void }}
29
29
  * @example
@@ -104,6 +104,7 @@ export class Ops {
104
104
  };
105
105
  /**
106
106
  * Reverse a finished op with the undo(e, args, value) its definition declared: pass the same args and the value run returned.
107
+ * canUndo(e, args, value) in the definition answers like can (true, a reason, a structured failure) when the world may have moved on so far that it cannot be reversed.
107
108
  * Returns { ok: true }, or { ok: false, code: 'noUndo', facts: { op }, nextActions } when the op did not declare undo. The undo runs as an op write (the dev guard stays quiet).
108
109
  * @example const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value);
109
110
  * @param {string} name
@@ -1,13 +1,22 @@
1
1
  // Generated by npm run map, do not edit by hand. Source: packages/engine/core/ops/control.js (edit the JSDoc in the source, then run npm run map)
2
+ export namespace TASK_ENDS {
3
+ let replaced: string;
4
+ let level: string;
5
+ let placed: string;
6
+ let seated: string;
7
+ let physics: string;
8
+ let gone: string;
9
+ let order: string;
10
+ }
2
11
  /** engine.control (made for every engine in services.js; the characters module tells it how to find a character by id) */
3
12
  export class Control {
4
13
  constructor(engine: any);
5
14
  /**
6
- * Take a character's control. step (optional): (dt, character) => ({ x, z, run? }) | null | false, called each fixed step while this owner is in
15
+ * Take a character's control. step (optional): (dt, character) => ({ x, y?, z, run? }) | null | false, called each fixed step while this owner is in
7
16
  * charge (dt on the character's time channel): a direction moves it, null stands still (gravity and the idle pose go on), false skips the
8
17
  * move this step (you placed it yourself). Without step, move it with handle.move(x, z, run, dt), which does nothing while paused.
9
18
  * @param {any} who a Character, an NPC handle or a character id ('player', an NPC id)
10
- * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'physics' | 'net', step?: (dt: number, ch: any) => ({ x: number, z: number, run?: boolean } | null | false | void) }} o
19
+ * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'physics' | 'net', step?: (dt: number, ch: any) => ({ x: number, y?: number, z: number, run?: boolean } | null | false | void) }} o
11
20
  * @returns {{ owner: string, layer: string, id: string, readonly active: boolean, move(x: number, z: number, run?: boolean, dt?: number): boolean, remove(): void }}
12
21
  * @example const h = engine.control.take(player, { owner: 'tutorial', layer: 'script', step: () => ({ x: 0, z: 1 }) }); ... h.remove();
13
22
  */
@@ -16,6 +25,7 @@ export class Control {
16
25
  layer?: "base" | "script" | "cutscene" | "physics" | "net";
17
26
  step?: (dt: number, ch: any) => ({
18
27
  x: number;
28
+ y?: number;
19
29
  z: number;
20
30
  run?: boolean;
21
31
  } | null | false | void);
@@ -29,18 +29,26 @@ export class Saves {
29
29
  * version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current
30
30
  * shape.
31
31
  * A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept).
32
- * A part registered after a save was loaded (a module installed later) is handed its data from that save at once.
32
+ * load(data, turn): turn is this replacement's identity. Pass it on, level.load(x, { turn }) or content.load(x, { turn }): those wait for a running load to end, except with its turn.
33
+ * A part registered after a save was loaded (a module installed later) is handed its data from that save: at once when idle, else right after the replacement under way.
33
34
  * atomic: true joins this part to atomic ops: it is copied before an atomic op runs and put back if the op fails (plain data only; afterLoad does not run on rollback).
34
35
  * checkNewGame(data): dev only, called once start() finished with this part's data in the new-game state, to warn about what should not be there yet
35
36
  * (world: records placed by code instead of content). The part knows its own format; core only hands the data over.
37
+ * Returns a handle: remove() takes the part out and keeps its data as unattached data (it rides in later saves and goes back to a part registered under
38
+ * the key later), without holding on to the part's closures. remove({ keep: false }) gives back only what the part took over at register: for a part that never ran.
36
39
  * @param {string} key
37
40
  * @param {SaveProvider} provider
41
+ * @returns {{ remove(o?: { keep?: boolean }): void }}
38
42
  * @example
39
43
  * engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) });
40
44
  * // later the format gains beds: version 2, and a step that upgrades version-1 data
41
45
  * engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });
42
46
  */
43
- register(key: string, provider: SaveProvider): void;
47
+ register(key: string, provider: SaveProvider): {
48
+ remove(o?: {
49
+ keep?: boolean;
50
+ }): void;
51
+ };
44
52
  /**
45
53
  * The save versions this build reads, per part: { world: 1, clock: 1, ... }. A save whose part is newer is refused; an older one is migrated.
46
54
  * @returns {Record<string, number>}
@@ -49,6 +57,7 @@ export class Saves {
49
57
  /**
50
58
  * Store a binary attachment outside the world save (a photo, a replay). It rides in the queue of save writes, so flush() waits for it, and exportFile() carries it.
51
59
  * Pass a function to make the bytes when the write runs: flush() then waits for that too. Without IndexedDB it is not kept.
60
+ * Rejects with save-stale, changing nothing, when another tab wrote this id since this tab last saw it; attachments(group) is how a tab looks.
52
61
  * @example await engine.saves.putAttachment('replay', 'run-1', blob, { score: 12 });
53
62
  * @param {string} group what the attachment is for
54
63
  * @param {string} id unique inside the group; the same id replaces
@@ -58,7 +67,7 @@ export class Saves {
58
67
  * @experimental
59
68
  */
60
69
  putAttachment(group: string, id: string, blob: Blob | (() => Promise<Blob>), meta?: any): Promise<void>;
61
- /** Delete an attachment; no such id is fine @param {string} group @param {string} id @returns {Promise<void>} @experimental */
70
+ /** Delete an attachment; no such id is fine. Rejects with save-stale as putAttachment does @param {string} group @param {string} id @returns {Promise<void>} @experimental */
62
71
  removeAttachment(group: string, id: string): Promise<void>;
63
72
  /**
64
73
  * The attachments of a group, once storage is ready. Empty without IndexedDB.
@@ -85,6 +94,7 @@ export class Saves {
85
94
  /**
86
95
  * Collect the data of every part (does not write to the browser): { format, savedAt, versions, parts }.
87
96
  * A part whose save() throws is left out and reported (engine.error in dev); save() instead refuses to write such a save.
97
+ * Throws while a load is under way: what it would return is half of each state. saves.save waits instead.
88
98
  * @returns {{ format: number, savedAt: number, versions: Record<string, number>, parts: Record<string, any> }}
89
99
  */
90
100
  collect(): {
@@ -112,8 +122,13 @@ export class Saves {
112
122
  * The pre-load state is a copy (structuredClone) of every part's save(), so save() may return the live object load() writes into; a part whose
113
123
  * data cannot be copied makes apply refuse (false) before anything changes.
114
124
  * The state changes synchronously unless a part's load is async; only the result is a Promise.
125
+ * One replacement runs at a time: asked for while a load, newGame or quit is under way, this waits its turn, then reads the data and takes its
126
+ * rollback point. On the line after a synchronous apply it is not waiting on anything yet, so it applies at once and takes over the afterLoad.
127
+ * Inside a part's load() or an afterLoad it starts after they return, so do not await it there.
128
+ * On success 'save:loaded' fires with slot, as for saves.load: what the game does not save (a walk) ends on it, and derived state rebuilds.
115
129
  * @param {any} data
116
- * @param {string} [slot] for messages only
130
+ * What goes around it is the same for every door (core/saves/session.js): 'save:loaded' fires with `slot`, the title closes; a rollback fires 'session:failed' { kind: 'quick', slot }.
131
+ * @param {string} [slot] for messages and the event
117
132
  * @returns {Promise<boolean>}
118
133
  */
119
134
  apply(data: any, slot?: string): Promise<boolean>;
@@ -121,7 +136,8 @@ export class Saves {
121
136
  * Save into a slot (default 'auto'). Returns Promise<boolean>
122
137
  * (resolves after the write to IndexedDB: true on success, false with a toast and console error on failure).
123
138
  * The in-memory save updates immediately, so a following load / list / export sees it at once; the 'save:written' event fires only after the write succeeds.
124
- * If any part's save() throws, nothing is written and the slot keeps its previous save (false). A failed write keeps the previous save too.
139
+ * Asked for while a load, newGame or quit is under way, it waits for that to end and saves the result: a save never holds half of each state.
140
+ * If any part's save() throws, or its data holds NaN or Infinity at any depth (the message names the part and the path), nothing is written and the slot keeps its previous save (false). A failed write keeps the previous save too.
125
141
  * Show "saved" only after the result is true.
126
142
  * @param {string} [slot]
127
143
  * @returns {Promise<boolean>}
@@ -144,7 +160,11 @@ export class Saves {
144
160
  slot: string;
145
161
  savedAt: number;
146
162
  }[];
147
- /** Delete a slot. Returns a Promise (disk write done); awaiting is optional @param {string} slot @returns {Promise<void>} */
163
+ /**
164
+ * Delete a slot. Returns a Promise (disk write done); awaiting is optional. A newer save another tab wrote meanwhile is kept: the slot lists again, with a toast (save-stale).
165
+ * A delete the store refused lists the slot again too, with a toast.
166
+ * @param {string} slot @returns {Promise<void>}
167
+ */
148
168
  remove(slot: string): Promise<void>;
149
169
  /** Export as a piece of text (can be copied as a backup; synchronous, without binary attachments) @param {string} [slot] @returns {string} @experimental */
150
170
  export(slot?: string): string;