@jgengine/core 0.11.0 → 0.12.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.
- package/CHANGELOG.md +26 -0
- package/dist/ai/populationDirector.d.ts +103 -0
- package/dist/ai/populationDirector.js +190 -0
- package/dist/ai/pursuit.d.ts +56 -0
- package/dist/ai/pursuit.js +53 -0
- package/dist/authoring.d.ts +1 -1
- package/dist/authoring.js +1 -1
- package/dist/combat.d.ts +1 -0
- package/dist/combat.js +1 -0
- package/dist/devtools/controls.d.ts +38 -0
- package/dist/devtools/controls.js +181 -0
- package/dist/devtools/devtools.d.ts +5 -197
- package/dist/devtools/devtools.js +38 -774
- package/dist/devtools/discover.d.ts +32 -0
- package/dist/devtools/discover.js +240 -0
- package/dist/devtools/fallbackSeams.d.ts +50 -0
- package/dist/devtools/fallbackSeams.js +111 -0
- package/dist/devtools/frame.d.ts +15 -0
- package/dist/devtools/frame.js +247 -0
- package/dist/devtools/logs.d.ts +15 -0
- package/dist/devtools/logs.js +86 -0
- package/dist/devtools/overrides.d.ts +16 -0
- package/dist/devtools/overrides.js +66 -0
- package/dist/devtools/types.d.ts +212 -0
- package/dist/devtools/types.js +1 -0
- package/dist/economy/auctionBook.d.ts +122 -0
- package/dist/economy/auctionBook.js +213 -0
- package/dist/economy/priceHistory.d.ts +44 -0
- package/dist/economy/priceHistory.js +89 -0
- package/dist/economy/unlockPoints.d.ts +92 -0
- package/dist/economy/unlockPoints.js +103 -0
- package/dist/editor/commandApply.d.ts +5 -0
- package/dist/editor/commandApply.js +755 -0
- package/dist/editor/commands.d.ts +48 -3
- package/dist/editor/commands.js +40 -754
- package/dist/editor/directives.d.ts +94 -0
- package/dist/editor/directives.js +206 -0
- package/dist/editor/document.d.ts +37 -2
- package/dist/editor/document.js +422 -6
- package/dist/editor/entityCatalog.d.ts +42 -0
- package/dist/editor/entityCatalog.js +101 -0
- package/dist/editor/environment.d.ts +74 -0
- package/dist/editor/environment.js +169 -0
- package/dist/editor/index.d.ts +26 -1
- package/dist/editor/index.js +8 -1
- package/dist/editor/minimap.d.ts +31 -0
- package/dist/editor/minimap.js +73 -0
- package/dist/editor/streamer.d.ts +66 -0
- package/dist/editor/streamer.js +68 -0
- package/dist/editor/types.d.ts +143 -0
- package/dist/editor/world.d.ts +136 -0
- package/dist/editor/world.js +303 -0
- package/dist/game/breeding.d.ts +161 -0
- package/dist/game/breeding.js +181 -0
- package/dist/game/cameraConfig.d.ts +451 -0
- package/dist/game/cameraConfig.js +1 -0
- package/dist/game/defineGame.d.ts +16 -9
- package/dist/game/defineGame.js +14 -6
- package/dist/game/defineSystem.d.ts +2 -0
- package/dist/game/defineSystem.js +2 -0
- package/dist/game/events.d.ts +28 -0
- package/dist/game/playableGame.d.ts +34 -435
- package/dist/game/playableGame.js +1 -1
- package/dist/game/progression.d.ts +35 -0
- package/dist/game/progression.js +19 -0
- package/dist/game/quest.js +1 -3
- package/dist/game/tribe.d.ts +184 -0
- package/dist/game/tribe.js +432 -0
- package/dist/gameplay.d.ts +3 -1
- package/dist/gameplay.js +3 -1
- package/dist/inventory/encumbrance.d.ts +69 -0
- package/dist/inventory/encumbrance.js +68 -0
- package/dist/item/durability.js +1 -3
- package/dist/meta/changelog.d.ts +1 -1
- package/dist/meta/changelog.js +24 -1
- package/dist/movement/movementModel.d.ts +15 -1
- package/dist/movement/movementModel.js +33 -15
- package/dist/movement/playerMovement.js +102 -2
- package/dist/multiplayer/combatSnapshot.js +13 -8
- package/dist/multiplayer/presenceModel.d.ts +2 -0
- package/dist/multiplayer/presenceModel.js +8 -0
- package/dist/physics/drivableVehicle.d.ts +2 -0
- package/dist/physics/drivableVehicle.js +1 -1
- package/dist/physics/flightDynamics.d.ts +82 -0
- package/dist/physics/flightDynamics.js +165 -0
- package/dist/physics/gravityField.d.ts +25 -0
- package/dist/physics/gravityField.js +41 -0
- package/dist/physics/kinematicVehicle.d.ts +87 -0
- package/dist/physics/kinematicVehicle.js +193 -11
- package/dist/physics/physicsWorld.d.ts +26 -0
- package/dist/physics/physicsWorld.js +109 -117
- package/dist/physics/vehicleObstacles.d.ts +44 -0
- package/dist/physics/vehicleObstacles.js +115 -0
- package/dist/random/rng.d.ts +4 -1
- package/dist/random/rng.js +4 -1
- package/dist/runtime/adapter.d.ts +13 -0
- package/dist/runtime/adapter.js +13 -0
- package/dist/runtime/context/combat.d.ts +51 -0
- package/dist/runtime/context/combat.js +130 -0
- package/dist/runtime/context/deathLoot.d.ts +30 -0
- package/dist/runtime/context/deathLoot.js +39 -0
- package/dist/runtime/context/player.d.ts +48 -0
- package/dist/runtime/context/player.js +125 -0
- package/dist/runtime/context/scene.d.ts +59 -0
- package/dist/runtime/context/scene.js +291 -0
- package/dist/runtime/context/snapshotCodecs.d.ts +12 -0
- package/dist/runtime/context/snapshotCodecs.js +26 -0
- package/dist/runtime/descriptors/baseline.js +26 -3
- package/dist/runtime/descriptors/features.d.ts +5 -0
- package/dist/runtime/descriptors/features.js +20 -2
- package/dist/runtime/gameContext.d.ts +2 -428
- package/dist/runtime/gameContext.js +88 -501
- package/dist/runtime/gameContextTypes.d.ts +467 -0
- package/dist/runtime/gameContextTypes.js +1 -0
- package/dist/runtime/headlessRunner.d.ts +4 -2
- package/dist/runtime/headlessRunner.js +1 -0
- package/dist/runtime/hostPolicy.d.ts +51 -0
- package/dist/runtime/hostPolicy.js +68 -0
- package/dist/runtime/hostedGameRunner.d.ts +3 -1
- package/dist/runtime/hostedGameRunner.js +1 -0
- package/dist/runtime/hostedWorldSession.d.ts +3 -1
- package/dist/runtime/hostedWorldSession.js +1 -0
- package/dist/runtime/worldSnapshot.d.ts +13 -1
- package/dist/runtime/worldSnapshot.js +15 -3
- package/dist/scene/assetCatalog.d.ts +5 -0
- package/dist/scene/assetSpace.js +1 -3
- package/dist/scene/authoredTriggers.d.ts +50 -0
- package/dist/scene/authoredTriggers.js +114 -0
- package/dist/scene/builtinSceneKinds.js +8 -3
- package/dist/scene/colliders.d.ts +58 -0
- package/dist/scene/colliders.js +108 -0
- package/dist/scene/collisionMesh.d.ts +94 -0
- package/dist/scene/collisionMesh.js +699 -0
- package/dist/scene/companion.d.ts +147 -0
- package/dist/scene/companion.js +193 -0
- package/dist/scene/entityStats.d.ts +7 -9
- package/dist/scene/entityStats.js +10 -14
- package/dist/scene/sceneKinds.d.ts +16 -0
- package/dist/scene/sceneKinds.js +4 -0
- package/dist/scene/sceneRaycast.js +15 -0
- package/dist/stats/spawnLevelStats.d.ts +110 -0
- package/dist/stats/spawnLevelStats.js +140 -0
- package/dist/stats/statPool.d.ts +70 -0
- package/dist/stats/statPool.js +59 -0
- package/dist/store/changeSignal.d.ts +3 -0
- package/dist/store/changeSignal.js +2 -0
- package/dist/store/observableKeyedStore.d.ts +2 -0
- package/dist/store/observableKeyedStore.js +1 -0
- package/dist/survival/decayMeter.js +1 -3
- package/dist/survival/regionHealth.js +1 -3
- package/dist/ui/hudLayout.d.ts +5 -0
- package/dist/ui/hudLayout.js +17 -1
- package/dist/world/authoredEntities.d.ts +29 -0
- package/dist/world/authoredEntities.js +29 -0
- package/dist/world/authoredObjects.d.ts +15 -1
- package/dist/world/authoredObjects.js +13 -1
- package/dist/world/authoredSpawn.d.ts +39 -0
- package/dist/world/authoredSpawn.js +37 -0
- package/dist/world/buildSockets.d.ts +152 -0
- package/dist/world/buildSockets.js +188 -0
- package/dist/world/cityBlocks.d.ts +152 -0
- package/dist/world/cityBlocks.js +670 -0
- package/dist/world/cityContent.d.ts +77 -0
- package/dist/world/cityContent.js +261 -0
- package/dist/world/cityGeometry.d.ts +114 -0
- package/dist/world/cityGeometry.js +573 -0
- package/dist/world/cityKind.d.ts +314 -0
- package/dist/world/cityKind.js +1578 -0
- package/dist/world/features.d.ts +18 -3
- package/dist/world/features.js +10 -1
- package/dist/world/grassKind.js +2 -2
- package/dist/world/markers.d.ts +50 -4
- package/dist/world/markers.js +49 -0
- package/dist/world/massing.js +1 -1
- package/dist/world/minimapBake.d.ts +78 -0
- package/dist/world/minimapBake.js +208 -0
- package/dist/world/minimapTrack.d.ts +17 -0
- package/dist/world/minimapTrack.js +22 -0
- package/dist/world/pathNetwork.d.ts +159 -0
- package/dist/world/pathNetwork.js +684 -0
- package/dist/world/place.d.ts +166 -0
- package/dist/world/place.js +96 -0
- package/dist/world/placeAsset.js +3 -1
- package/dist/world/poleLineKind.d.ts +40 -0
- package/dist/world/poleLineKind.js +97 -0
- package/dist/world/polyline.js +9 -2
- package/dist/world/resourceNode.d.ts +109 -0
- package/dist/world/resourceNode.js +140 -0
- package/dist/world/scatter.js +2 -20
- package/dist/world/streets.d.ts +29 -0
- package/dist/world/streets.js +55 -0
- package/dist/world/terraform.js +58 -88
- package/dist/world/terrain.d.ts +45 -0
- package/dist/world/terrain.js +78 -0
- package/dist/world.d.ts +14 -5
- package/dist/world.js +12 -3
- package/package.json +1 -1
- package/skills/game-design/SKILL.md +28 -0
- package/skills/game-design/agents/openai.yaml +4 -0
- package/skills/game-design/references/application-playbook.md +170 -0
- package/skills/game-design/references/field-guide.md +288 -0
- package/skills/jgengine/SKILL.md +7 -4
- package/skills/jgengine/api.md +172 -79
- package/skills/jgengine/capabilities.md +104 -2
- package/skills/jgengine/recipes/minimal-game.md +88 -0
- package/skills/jgengine-combat/SKILL.md +5 -1
- package/skills/jgengine-combat/api.md +36 -0
- package/skills/jgengine-combat/capabilities.md +44 -0
- package/skills/jgengine-combat/recipes/portable-stat-pools.md +122 -0
- package/skills/jgengine-combat/reference.md +12 -2
- package/skills/jgengine-gameplay/api.md +152 -26
- package/skills/jgengine-gameplay/capabilities.md +78 -2
- package/skills/jgengine-gameplay/reference-systems.md +1 -5
- package/skills/jgengine-world/SKILL.md +13 -0
- package/skills/jgengine-world/api.md +419 -15
- package/skills/jgengine-world/capabilities.md +108 -2
- package/skills/jgengine-world/recipes/commanding-entities.md +128 -0
- package/skills/jgengine-world/reference.md +43 -4
- package/skills/jgengine/reference-cartridge.md +0 -72
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
export interface CameraFollowState {
|
|
2
|
+
entityId: string;
|
|
3
|
+
target: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
z: number;
|
|
7
|
+
};
|
|
8
|
+
camera: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
z: number;
|
|
12
|
+
};
|
|
13
|
+
distance: number;
|
|
14
|
+
}
|
|
15
|
+
export interface FirstPersonCameraConfig {
|
|
16
|
+
/** Camera height above the followed entity's origin. Default 1.6. */
|
|
17
|
+
eyeHeight?: number;
|
|
18
|
+
/** Mouse-look radians per pixel of pointer movement. Default 0.0025. */
|
|
19
|
+
sensitivity?: number;
|
|
20
|
+
/** Clamp on look pitch in radians (± from horizon). Default 1.45. */
|
|
21
|
+
maxPitch?: number;
|
|
22
|
+
/** Show the centered crosshair overlay. Default true. */
|
|
23
|
+
reticle?: boolean;
|
|
24
|
+
/** Render a viewmodel in view: the built-in three-mesh gun, or `PlayableGame.viewmodel` when set (#542). `false` renders no viewmodel regardless of `PlayableGame.viewmodel`. Default true. */
|
|
25
|
+
viewmodel?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Which camera rig the shell mounts. Every rig accepts `followEntityId: null`
|
|
29
|
+
* (avatar-less games — city-builders, card games, auto-battlers — still get a
|
|
30
|
+
* camera). Rigs are tuned through their config block below, never by writing
|
|
31
|
+
* camera positions from `onTick`.
|
|
32
|
+
* - `orbit` — third-person chase (the historical default; `perspective: "third"`).
|
|
33
|
+
* - `first` — pointer-lock mouse-look (`perspective: "first"`).
|
|
34
|
+
* - `topDown` — fixed height/pitch/yaw with decoupled follow (ARPG iso, top-down).
|
|
35
|
+
* - `rts` — free-pan / edge-scroll / rotate / zoom, optional follow.
|
|
36
|
+
* - `shoulder` — over-the-shoulder with ADS transition + shoulder swap.
|
|
37
|
+
* - `lockOn` — yaw bound to the player→target vector; move axis becomes strafe.
|
|
38
|
+
* - `chase` — speed-reactive vehicle chase (speed→FOV, spring arm, shake) + cockpit/hood/rear views.
|
|
39
|
+
* - `observer` — detached spectator/photo cam bound to any entity or fixed point; never reads player input.
|
|
40
|
+
* - `turntable` — slow auto-orbit of a fixed point: a rotating display stand for a scene. The friendly, flat spelling of `observer`'s point-orbit mode; providing `camera.turntable` selects it without an explicit `rig`.
|
|
41
|
+
* - `sideScroll` — fixed lateral follow (2.5D platformer/beat-'em-up side view); reads no player input.
|
|
42
|
+
* - `inspection` — model-viewer / editor rig (#207.7, #866): middle-drag pan, right-drag orbit, scroll zoom toward a configurable anchor; orbits a fixed point, reads no player/entity input.
|
|
43
|
+
* - `none` — no camera rig is mounted; use for HUD-only presentations or a game that manages its own camera.
|
|
44
|
+
*/
|
|
45
|
+
export type CameraRigKind = "orbit" | "first" | "topDown" | "rts" | "shoulder" | "lockOn" | "chase" | "observer" | "turntable" | "sideScroll" | "inspection" | "none";
|
|
46
|
+
/** Canvas camera projection. "orthographic" renders a flat 2D-style view (side-scrollers, falling-block puzzles) — pair with `rig: "sideScroll"`; default "perspective". */
|
|
47
|
+
export type CameraProjection = "perspective" | "orthographic";
|
|
48
|
+
/** Fixed lateral 2.5D follow (side-on platformer cam): the camera sits perpendicular to the travel axis, tracks the followed entity, and never reads player look input. */
|
|
49
|
+
export interface SideScrollCameraConfig {
|
|
50
|
+
/** World axis the action travels along; the camera watches from the perpendicular side. Default "x". */
|
|
51
|
+
axis?: "x" | "z";
|
|
52
|
+
/** Camera distance from the followed entity along the perpendicular axis. Default 10. */
|
|
53
|
+
distance?: number;
|
|
54
|
+
/** Camera height above the followed entity. Default 3. */
|
|
55
|
+
height?: number;
|
|
56
|
+
/** Height of the look point above the entity. Default 1. */
|
|
57
|
+
lookHeight?: number;
|
|
58
|
+
/** Per-second smoothing factor for the follow (0 hard-locks). Default 8. */
|
|
59
|
+
followSmoothing?: number;
|
|
60
|
+
fov?: number;
|
|
61
|
+
}
|
|
62
|
+
/** Fixed top-down / isometric rig (#23) — height/pitch/yaw + decoupled follow. */
|
|
63
|
+
export interface TopDownCameraConfig {
|
|
64
|
+
/** Camera height above the follow point. Default 18. */
|
|
65
|
+
height?: number;
|
|
66
|
+
/** Elevation of the camera above the ground plane in radians (PI/2 = straight down, near 0 = grazing; values below 0.05 clamp to 0.05). Default ~1.02 (~58°, ARPG iso). */
|
|
67
|
+
pitch?: number;
|
|
68
|
+
/** Fixed azimuth in radians; ~PI/4 reads as isometric, 0 as straight top-down. Default PI/4. */
|
|
69
|
+
yaw?: number;
|
|
70
|
+
/** Horizontal look offset applied to the follow point. */
|
|
71
|
+
targetOffset?: {
|
|
72
|
+
x?: number;
|
|
73
|
+
y?: number;
|
|
74
|
+
z?: number;
|
|
75
|
+
};
|
|
76
|
+
/** Exponential follow smoothing (higher = snappier, decoupled from any orbit drag). Default 8. */
|
|
77
|
+
followSmoothing?: number;
|
|
78
|
+
/** Scroll zoom bounds as a height multiplier. */
|
|
79
|
+
zoom?: {
|
|
80
|
+
min?: number;
|
|
81
|
+
max?: number;
|
|
82
|
+
speed?: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Free-pan / edge-scroll RTS rig (#24) — pan/rotate/zoom independent of any avatar. */
|
|
86
|
+
export interface RtsCameraConfig extends TopDownCameraConfig {
|
|
87
|
+
/** WASD / arrow pan speed in world units per second. Default 24. */
|
|
88
|
+
panSpeed?: number;
|
|
89
|
+
/** Edge-scroll when the pointer nears a screen edge; number sets the margin fraction. Default true. */
|
|
90
|
+
edgeScroll?: boolean | {
|
|
91
|
+
margin?: number;
|
|
92
|
+
speed?: number;
|
|
93
|
+
};
|
|
94
|
+
/** Yaw rotate speed (radians/sec) for rotate keys / middle-drag. Default 1.4. */
|
|
95
|
+
rotateSpeed?: number;
|
|
96
|
+
/** World-space clamp for the pan center. */
|
|
97
|
+
bounds?: {
|
|
98
|
+
minX?: number;
|
|
99
|
+
maxX?: number;
|
|
100
|
+
minZ?: number;
|
|
101
|
+
maxZ?: number;
|
|
102
|
+
};
|
|
103
|
+
/** Start centered on this world point when there is no follow target. */
|
|
104
|
+
start?: {
|
|
105
|
+
x?: number;
|
|
106
|
+
z?: number;
|
|
107
|
+
};
|
|
108
|
+
/** Read WASD/arrow pan, edge-scroll, Q/E rotate, and wheel zoom. `false` sits static at the start/bounds position — a backdrop camera, no input at all. Default true. */
|
|
109
|
+
pan?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/** Over-the-shoulder combat rig (#25) — offset, ADS, shoulder swap, decoupled reticle. */
|
|
112
|
+
export interface ShoulderCameraConfig {
|
|
113
|
+
/** Lateral shoulder offset (world units, sign flips on swap). Default 0.6. */
|
|
114
|
+
shoulderOffset?: number;
|
|
115
|
+
/** Vertical offset above the follow point. Default 1.6. */
|
|
116
|
+
heightOffset?: number;
|
|
117
|
+
/** Boom distance behind the shoulder. Default 3.2. */
|
|
118
|
+
distance?: number;
|
|
119
|
+
/** Starting shoulder side. Default "right". */
|
|
120
|
+
side?: "left" | "right";
|
|
121
|
+
/** Aim-down-sights framing, blended in while `aim` is held. */
|
|
122
|
+
ads?: {
|
|
123
|
+
distance?: number;
|
|
124
|
+
shoulderOffset?: number;
|
|
125
|
+
fov?: number;
|
|
126
|
+
heightOffset?: number;
|
|
127
|
+
};
|
|
128
|
+
/** ADS blend speed (higher = snappier). Default 10. */
|
|
129
|
+
adsTransitionSpeed?: number;
|
|
130
|
+
/** Screen-space reticle offset (fraction of viewport), decoupled from camera center. */
|
|
131
|
+
reticleOffset?: {
|
|
132
|
+
x?: number;
|
|
133
|
+
y?: number;
|
|
134
|
+
};
|
|
135
|
+
/** Mouse-look sensitivity (radians per pixel). Default 0.0025. */
|
|
136
|
+
sensitivity?: number;
|
|
137
|
+
/** Base field of view. Default 55. */
|
|
138
|
+
fov?: number;
|
|
139
|
+
}
|
|
140
|
+
/** Lock-on / strafe rig (#26) — yaw bound to player→target, move axis becomes strafe. */
|
|
141
|
+
export interface LockOnCameraConfig {
|
|
142
|
+
/** Target instance id; when omitted the rig reads the follower's current `getTarget`. */
|
|
143
|
+
targetEntityId?: string;
|
|
144
|
+
/** Boom distance behind the player, away from the target. Default 5. */
|
|
145
|
+
distance?: number;
|
|
146
|
+
/** Camera height above the follow point. Default 2.4. */
|
|
147
|
+
height?: number;
|
|
148
|
+
/** Height of the framed look point above the midpoint. Default 1.2. */
|
|
149
|
+
lookHeight?: number;
|
|
150
|
+
/** 0 frames the player, 1 frames the target, 0.5 the midpoint. Default 0.5. */
|
|
151
|
+
framingBias?: number;
|
|
152
|
+
/** Exponential yaw smoothing toward the player→target vector. Default 9. */
|
|
153
|
+
yawSmoothing?: number;
|
|
154
|
+
}
|
|
155
|
+
/** Fixed interior view for the chase rig (#27). */
|
|
156
|
+
export type ChaseView = "chase" | "cockpit" | "hood" | "rear";
|
|
157
|
+
/** Speed-reactive vehicle chase rig (#27) — speed→FOV, spring arm, procedural shake, interior views. */
|
|
158
|
+
export interface ChaseCameraConfig {
|
|
159
|
+
/** Boom distance behind the vehicle. Default 6. */
|
|
160
|
+
distance?: number;
|
|
161
|
+
/** Camera height above the follow point. Default 2.6. */
|
|
162
|
+
height?: number;
|
|
163
|
+
/** Height of the look point above the follow point. Default 1.2. */
|
|
164
|
+
lookHeight?: number;
|
|
165
|
+
/** Spring-arm damping (higher = stiffer, less lag). Default 6. */
|
|
166
|
+
springDamping?: number;
|
|
167
|
+
/** Speed→FOV curve: FOV lerps from `base` to `max` as speed climbs to `speedForMax`. */
|
|
168
|
+
fov?: {
|
|
169
|
+
base?: number;
|
|
170
|
+
max?: number;
|
|
171
|
+
speedForMax?: number;
|
|
172
|
+
};
|
|
173
|
+
/** Procedural shake amplitude per unit of speed (adds to the trauma channel). Default 0.0. */
|
|
174
|
+
shakePerSpeed?: number;
|
|
175
|
+
/** Velocity-lead / predictive follow (#286.9): the rig aims `time` seconds ahead of the target along its velocity, clamped to `max` world units (default 4). */
|
|
176
|
+
lead?: {
|
|
177
|
+
time: number;
|
|
178
|
+
max?: number;
|
|
179
|
+
};
|
|
180
|
+
/** Roll into turns (#286.10): radians of camera roll per rad/s of the target's yaw rate, clamped to `max` (default 0.35), exponentially smoothed by `damping` (default 8). */
|
|
181
|
+
bank?: {
|
|
182
|
+
perYawRate: number;
|
|
183
|
+
max?: number;
|
|
184
|
+
damping?: number;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Drift-lag (#1051): when the target slides, rotate the chase anchor partway from
|
|
188
|
+
* its heading toward its travel (velocity) direction so the player sees the car's
|
|
189
|
+
* side while the framing stays stable. Omitting the block keeps the pure-heading
|
|
190
|
+
* behavior. `blend` (default 0.65) is the max fraction of the slip angle to
|
|
191
|
+
* follow, itself scaled by how far the slip has opened so straight-line driving
|
|
192
|
+
* is untouched; below `minSpeed` (default 4) planar speed the feature is off for
|
|
193
|
+
* parking-lot stability; reversing never swings the camera around. `response`
|
|
194
|
+
* (default 6) drives `1-exp(-response*dt)` smoothing toward the blended yaw.
|
|
195
|
+
*/
|
|
196
|
+
velocityYaw?: {
|
|
197
|
+
blend?: number;
|
|
198
|
+
minSpeed?: number;
|
|
199
|
+
response?: number;
|
|
200
|
+
};
|
|
201
|
+
/** Which view to mount. Default "chase". */
|
|
202
|
+
view?: ChaseView;
|
|
203
|
+
/** Local offset for cockpit/hood/rear seats (relative to the vehicle, +z forward). */
|
|
204
|
+
seatOffsets?: {
|
|
205
|
+
cockpit?: {
|
|
206
|
+
x?: number;
|
|
207
|
+
y?: number;
|
|
208
|
+
z?: number;
|
|
209
|
+
};
|
|
210
|
+
hood?: {
|
|
211
|
+
x?: number;
|
|
212
|
+
y?: number;
|
|
213
|
+
z?: number;
|
|
214
|
+
};
|
|
215
|
+
rear?: {
|
|
216
|
+
x?: number;
|
|
217
|
+
y?: number;
|
|
218
|
+
z?: number;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** Detached spectator/photo cam (#120) — binds to any entity or fixed point, never reads player input. */
|
|
223
|
+
export interface ObserverCameraConfig {
|
|
224
|
+
/** What the observer looks at. Omit to stay on a fixed point at the origin (or `point`, if given). */
|
|
225
|
+
bind?: {
|
|
226
|
+
kind: "entity";
|
|
227
|
+
entityId: string;
|
|
228
|
+
} | {
|
|
229
|
+
kind: "point";
|
|
230
|
+
position: {
|
|
231
|
+
x: number;
|
|
232
|
+
y: number;
|
|
233
|
+
z: number;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
/** Orbit distance from the bound subject. Default 8. */
|
|
237
|
+
distance?: number;
|
|
238
|
+
/** Camera height above the bound subject. Default 3. */
|
|
239
|
+
height?: number;
|
|
240
|
+
/** Height of the look point above the subject. Default 1.2. */
|
|
241
|
+
lookHeight?: number;
|
|
242
|
+
/** Radians/second of automatic orbit around the subject (CCTV-style sweep); 0 holds a fixed angle. Default 0.2. */
|
|
243
|
+
orbitSpeed?: number;
|
|
244
|
+
/** Starting orbit angle in radians. Default 0. */
|
|
245
|
+
startAngle?: number;
|
|
246
|
+
fov?: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Turntable / showcase rig — slowly auto-orbits a fixed world point (no player
|
|
250
|
+
* input), the way a museum turntable rotates an object on display. A flat,
|
|
251
|
+
* self-describing spelling of `observer`'s point-orbit mode: `target` names the
|
|
252
|
+
* point directly instead of `bind: { kind: "point", position }`. Set
|
|
253
|
+
* `camera.turntable` and the rig is inferred — you don't also write `rig`.
|
|
254
|
+
*/
|
|
255
|
+
export interface TurntableCameraConfig {
|
|
256
|
+
/** World point the camera circles. Default the world origin. */
|
|
257
|
+
target?: {
|
|
258
|
+
x: number;
|
|
259
|
+
y: number;
|
|
260
|
+
z: number;
|
|
261
|
+
};
|
|
262
|
+
/** Orbit radius from the target. Default 8. */
|
|
263
|
+
distance?: number;
|
|
264
|
+
/** Camera height above the target. Default 3. */
|
|
265
|
+
height?: number;
|
|
266
|
+
/** Height of the look point above the target. Default 1.2. */
|
|
267
|
+
lookHeight?: number;
|
|
268
|
+
/** Radians/second of rotation; 0 holds a fixed angle. Default 0.2. */
|
|
269
|
+
orbitSpeed?: number;
|
|
270
|
+
/** Starting angle in radians. Default 0. */
|
|
271
|
+
startAngle?: number;
|
|
272
|
+
fov?: number;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* How scroll-zoom re-anchors the view for the inspection rig (#207.7):
|
|
276
|
+
* - `target` — dolly toward the orbit target (classic OrbitControls behavior).
|
|
277
|
+
* - `cursor` — dolly toward the point under the pointer.
|
|
278
|
+
* - `center` — dolly toward the viewport center; equivalent to `target` for an
|
|
279
|
+
* OrbitControls-driven rig, since the camera always faces `target` and that
|
|
280
|
+
* point already projects to the exact center of the viewport.
|
|
281
|
+
*/
|
|
282
|
+
export type InspectionZoomAnchor = "target" | "cursor" | "center";
|
|
283
|
+
/** Model-viewer / inspection rig (#207.7) — orbit + pan + anchored zoom around a fixed point, never reads player input. */
|
|
284
|
+
export interface InspectionCameraConfig {
|
|
285
|
+
/** Where scroll-zoom re-anchors the view. Default "target". */
|
|
286
|
+
anchor?: InspectionZoomAnchor;
|
|
287
|
+
/** Orbit target (the point orbited/panned around). Default origin. */
|
|
288
|
+
target?: {
|
|
289
|
+
x?: number;
|
|
290
|
+
y?: number;
|
|
291
|
+
z?: number;
|
|
292
|
+
};
|
|
293
|
+
/** Camera distance from `target` used to seed the initial camera position when `initialPosition` is unset. Default 6. */
|
|
294
|
+
initialDistance?: number;
|
|
295
|
+
/** Explicit starting camera world position; overrides `initialDistance` when set. */
|
|
296
|
+
initialPosition?: {
|
|
297
|
+
x?: number;
|
|
298
|
+
y?: number;
|
|
299
|
+
z?: number;
|
|
300
|
+
};
|
|
301
|
+
minDistance?: number;
|
|
302
|
+
maxDistance?: number;
|
|
303
|
+
/** Vertical orbit clamp (radians). Unset allows a full pole-to-pole orbit, unlike the tighter default on the classic orbit rig. */
|
|
304
|
+
minPolarAngle?: number;
|
|
305
|
+
maxPolarAngle?: number;
|
|
306
|
+
/** Middle-mouse pan. Default true for this rig. */
|
|
307
|
+
pan?: boolean;
|
|
308
|
+
rotateSpeed?: number;
|
|
309
|
+
zoomSpeed?: number;
|
|
310
|
+
dampingFactor?: number;
|
|
311
|
+
}
|
|
312
|
+
/** One stop on a scripted camera path (#29). */
|
|
313
|
+
export interface CameraKeyframe {
|
|
314
|
+
position: {
|
|
315
|
+
x: number;
|
|
316
|
+
y: number;
|
|
317
|
+
z: number;
|
|
318
|
+
};
|
|
319
|
+
lookAt: {
|
|
320
|
+
x: number;
|
|
321
|
+
y: number;
|
|
322
|
+
z: number;
|
|
323
|
+
};
|
|
324
|
+
fov?: number;
|
|
325
|
+
/** Seconds to travel from the previous keyframe to this one. Default 1. */
|
|
326
|
+
duration?: number;
|
|
327
|
+
/** Interpolation into this keyframe. Default "smooth" (smoothstep ease). */
|
|
328
|
+
ease?: "linear" | "smooth";
|
|
329
|
+
}
|
|
330
|
+
/** Scripted keyframe / path player (#29). When set it overrides the active rig. */
|
|
331
|
+
export interface CinematicCameraConfig {
|
|
332
|
+
keyframes: readonly CameraKeyframe[];
|
|
333
|
+
/** Restart from the first keyframe after the last. Default false. */
|
|
334
|
+
loop?: boolean;
|
|
335
|
+
}
|
|
336
|
+
/** Camera-shake / trauma defaults (#28). Any rig reads the trauma channel; game systems feed it via `cameraShake()`. */
|
|
337
|
+
export interface CameraShakeConfig {
|
|
338
|
+
/** Positional shake amplitude at full trauma (world units). Default 0.5. */
|
|
339
|
+
maxOffset?: number;
|
|
340
|
+
/** Rotational shake amplitude at full trauma (radians). Default 0.06. */
|
|
341
|
+
maxRoll?: number;
|
|
342
|
+
/** Trauma decay per second (fraction). Default 1.6. */
|
|
343
|
+
decayPerSecond?: number;
|
|
344
|
+
/** Trauma→shake exponent; 2 = quadratic falloff so small hits are subtle. Default 2. */
|
|
345
|
+
exponent?: number;
|
|
346
|
+
/** Noise frequency (Hz) of the shake oscillation. Default 24. */
|
|
347
|
+
frequency?: number;
|
|
348
|
+
}
|
|
349
|
+
export declare const CAMERA_FRUSTUM_DEFAULTS: {
|
|
350
|
+
readonly fov: 55;
|
|
351
|
+
readonly near: 0.1;
|
|
352
|
+
readonly far: 300;
|
|
353
|
+
readonly zoom: 50;
|
|
354
|
+
};
|
|
355
|
+
/** Player-facing FOV preference applied across every perspective camera rig. Orthographic projections ignore it. */
|
|
356
|
+
export interface PlayerFovConfig {
|
|
357
|
+
/** Inclusive lower bound for the slider and persisted values. Default 40. */
|
|
358
|
+
min?: number;
|
|
359
|
+
/** Inclusive upper bound for the slider and persisted values. Default 120. */
|
|
360
|
+
max?: number;
|
|
361
|
+
/** Initial FOV when nothing is persisted. Defaults to `frustum.fov` or 55. */
|
|
362
|
+
default?: number;
|
|
363
|
+
/** Persist the preference in localStorage across reloads. Default true. */
|
|
364
|
+
persist?: boolean;
|
|
365
|
+
/** Show the shell FOV slider. Default true for perspective cameras; forced off for orthographic. */
|
|
366
|
+
control?: boolean;
|
|
367
|
+
}
|
|
368
|
+
/** Camera tuning for the shell's rig stack: pick the rig via `rig`, then tune it through its matching config block. All fields optional — the default is the third-person orbit rig. */
|
|
369
|
+
export interface GameCameraConfig {
|
|
370
|
+
/** Selects the rig — the one camera-selection knob. Overrides the legacy `perspective` shorthand. */
|
|
371
|
+
rig?: CameraRigKind;
|
|
372
|
+
/** Canvas camera projection. "orthographic" renders a flat 2D-style view (side-scrollers, falling-block puzzles) — pair with `rig: "sideScroll"`; default perspective. */
|
|
373
|
+
projection?: CameraProjection;
|
|
374
|
+
/** Render frustum overrides applied to the canvas camera. `far` defaults to 300 — raise it for worlds whose content spans more than a few hundred units, or distant scenery silently clips. `zoom` is the orthographic zoom in canvas pixels per world unit, read only when `projection` is "orthographic"; default 50. */
|
|
375
|
+
frustum?: {
|
|
376
|
+
fov?: number;
|
|
377
|
+
near?: number;
|
|
378
|
+
far?: number;
|
|
379
|
+
zoom?: number;
|
|
380
|
+
};
|
|
381
|
+
/** Universal player FOV preference (slider + persistence) for perspective rigs. Ignored when `projection` is `"orthographic"`. */
|
|
382
|
+
playerFov?: PlayerFovConfig;
|
|
383
|
+
/** @deprecated Legacy shorthand for `rig: "orbit" | "first"` — set `rig` instead. "third" mounts the orbit camera (default); "first" mounts pointer-lock mouse-look. */
|
|
384
|
+
perspective?: "third" | "first";
|
|
385
|
+
/** First-person tuning; only read when the rig resolves to "first". */
|
|
386
|
+
firstPerson?: FirstPersonCameraConfig;
|
|
387
|
+
/** Top-down / isometric tuning (#23); read when `rig: "topDown"`. */
|
|
388
|
+
topDown?: TopDownCameraConfig;
|
|
389
|
+
/** Free-pan / edge-scroll RTS tuning (#24); read when `rig: "rts"`. */
|
|
390
|
+
rts?: RtsCameraConfig;
|
|
391
|
+
/** Over-the-shoulder tuning (#25); read when `rig: "shoulder"`. */
|
|
392
|
+
shoulder?: ShoulderCameraConfig;
|
|
393
|
+
/** Lock-on / strafe tuning (#26); read when `rig: "lockOn"`. */
|
|
394
|
+
lockOn?: LockOnCameraConfig;
|
|
395
|
+
/** Vehicle chase tuning (#27); read when `rig: "chase"`. */
|
|
396
|
+
chase?: ChaseCameraConfig;
|
|
397
|
+
/** Detached spectator/photo cam tuning (#120); read when `rig: "observer"`. */
|
|
398
|
+
observer?: ObserverCameraConfig;
|
|
399
|
+
/** Turntable / showcase tuning; setting this selects the `turntable` rig on its own. */
|
|
400
|
+
turntable?: TurntableCameraConfig;
|
|
401
|
+
/** Fixed side-on follow tuning; read when `rig: "sideScroll"`. */
|
|
402
|
+
sideScroll?: SideScrollCameraConfig;
|
|
403
|
+
/** Model-viewer / inspection tuning (#207.7); read when `rig: "inspection"`. */
|
|
404
|
+
inspection?: InspectionCameraConfig;
|
|
405
|
+
/** Camera-shake / trauma channel defaults (#28); read by every rig. */
|
|
406
|
+
shake?: CameraShakeConfig;
|
|
407
|
+
/** Scripted keyframe path (#29); when set, plays over the active rig. */
|
|
408
|
+
cinematic?: CinematicCameraConfig;
|
|
409
|
+
/** Seconds to cross-fade the camera when the rig changes (#29). 0 hard-cuts. Default 0.6. */
|
|
410
|
+
transitionSeconds?: number;
|
|
411
|
+
minDistance?: number;
|
|
412
|
+
maxDistance?: number;
|
|
413
|
+
targetHeight?: number;
|
|
414
|
+
/** Extra offset on top of entity position for the orbit target. */
|
|
415
|
+
targetOffset?: {
|
|
416
|
+
x?: number;
|
|
417
|
+
y?: number;
|
|
418
|
+
z?: number;
|
|
419
|
+
};
|
|
420
|
+
initialDistance?: number;
|
|
421
|
+
initialHeight?: number;
|
|
422
|
+
/** Initial horizontal boom facing (radians): 0 = camera behind on -Z, PI = camera on +Z. Seeds the orbit rig; unset keeps the legacy -Z placement. */
|
|
423
|
+
initialYaw?: number;
|
|
424
|
+
/** Initial boom elevation (radians): 0 = level, positive = camera above the target looking down. Seeds the orbit rig; unset derives elevation from `initialHeight`/`initialDistance`. */
|
|
425
|
+
initialPitch?: number;
|
|
426
|
+
/** Lock orbit radius while the follow target moves (default true in shell). */
|
|
427
|
+
followLock?: boolean;
|
|
428
|
+
/** When false, orbit target stays fixed (cinematic / debug). Default true. */
|
|
429
|
+
followEnabled?: boolean;
|
|
430
|
+
/** Instance id to follow, or null for an avatar-less free camera; defaults to local player in the dev shell. */
|
|
431
|
+
followEntityId?: string | null;
|
|
432
|
+
/** Fired each frame after cameraFollow lock is applied. */
|
|
433
|
+
onCameraFollow?: (state: CameraFollowState) => void;
|
|
434
|
+
rotateSpeed?: number;
|
|
435
|
+
zoomSpeed?: number;
|
|
436
|
+
dampingFactor?: number;
|
|
437
|
+
targetSmoothing?: number;
|
|
438
|
+
dragTargetSmoothing?: number;
|
|
439
|
+
distanceSmoothing?: number;
|
|
440
|
+
/** Vertical look clamp (three.js polar angle, radians): 0 = top-down over the head, PI/2 = level, >PI/2 = look up from below. Widen for top-down or vertical aim; unset keeps the standard chase feel. */
|
|
441
|
+
minPolarAngle?: number;
|
|
442
|
+
maxPolarAngle?: number;
|
|
443
|
+
/** Signed boom-elevation clamp `[min, max]` (radians): min < 0 dips the camera below the target, max > 0 rises overhead. Maps onto `minPolarAngle`/`maxPolarAngle` (polar = PI/2 − pitch); explicit polar fields win. */
|
|
444
|
+
pitchClamp?: readonly [number, number];
|
|
445
|
+
/** Spring-arm occlusion for the orbit rig: pull the camera in past walls/terrain so it never clips inside geometry. Off unless `enabled`. */
|
|
446
|
+
collision?: {
|
|
447
|
+
enabled?: boolean;
|
|
448
|
+
padding?: number;
|
|
449
|
+
minTargetDistance?: number;
|
|
450
|
+
};
|
|
451
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CAMERA_FRUSTUM_DEFAULTS = { fov: 55, near: 0.1, far: 300, zoom: 50 };
|
|
@@ -13,7 +13,7 @@ import { type EntityStore } from "../scene/entityStore.js";
|
|
|
13
13
|
import type { StoreHandle } from "../store/defineStore.js";
|
|
14
14
|
import type { TimeConfig } from "../time/simClock.js";
|
|
15
15
|
import type { WorldFeature } from "../world/features.js";
|
|
16
|
-
/** Tunes offline whole-world save (`
|
|
16
|
+
/** Tunes offline whole-world save (`defineGameDefinition({ persist })`). Defaults: continuous `autosave` to `localStorage`, one slot, no version. */
|
|
17
17
|
export interface PersistConfig {
|
|
18
18
|
/** `"autosave"` (default) writes on a debounce after any change; `"manual"` writes only on `ctx.game.save.checkpoint()` (save points / quest triggers). */
|
|
19
19
|
mode?: RuntimeSaveMode;
|
|
@@ -140,7 +140,7 @@ export interface LifecycleConfig<TState = unknown> {
|
|
|
140
140
|
restart?: string;
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
/** Fully-resolved game description produced by {@link
|
|
143
|
+
/** Fully-resolved game description produced by {@link defineGameDefinition} — assets, scene, and opted-in subsystems. */
|
|
144
144
|
export interface GameDefinition<TAssetRef extends ModelAssetRef = ModelAssetRef, TMultiplayer = unknown> {
|
|
145
145
|
name: string;
|
|
146
146
|
assets: AssetCatalog<TAssetRef>;
|
|
@@ -156,7 +156,13 @@ export interface GameDefinition<TAssetRef extends ModelAssetRef = ModelAssetRef,
|
|
|
156
156
|
* Classic `loop` hooks still run for incremental migration (systems tick first, then `loop.onTick`).
|
|
157
157
|
*/
|
|
158
158
|
systems?: readonly SystemDefinition[];
|
|
159
|
+
/**
|
|
160
|
+
* The place this game happens in — preferred shape is `world()` from `@jgengine/core/world/place`
|
|
161
|
+
* (ground + per-place laws; dressing lives in the editor's scene document). Omit entirely for
|
|
162
|
+
* pure UI/rules games that are not a spatial place.
|
|
163
|
+
*/
|
|
159
164
|
world?: WorldFeature;
|
|
165
|
+
/** Game-level default physics laws; a place world's own `physics` resolves over this. */
|
|
160
166
|
physics?: PhysicsConfig;
|
|
161
167
|
/** Simulation clock: real→game time scale, selectable speeds, calendar. Exposed as `ctx.time`; the shell feeds its scaled dt to `loop.onTick`. */
|
|
162
168
|
time?: TimeConfig;
|
|
@@ -165,8 +171,9 @@ export interface GameDefinition<TAssetRef extends ModelAssetRef = ModelAssetRef,
|
|
|
165
171
|
inventories?: Record<string, InventoryDeclaration>;
|
|
166
172
|
input?: ActionCodesMap;
|
|
167
173
|
server?: GameServerConfig;
|
|
174
|
+
/** Hosted per-player save policy, read only by an authoritative multiplayer host. Solo games leave this unset (nothing persists by default) and use `persist` when they want a save at all. */
|
|
168
175
|
save?: SaveConfig;
|
|
169
|
-
/**
|
|
176
|
+
/** The one save knob for solo games: offline whole-world save. `true` autosaves the entire game to `localStorage`; a config object tunes the mode/cadence/target. Binds `ctx.game.save` — the game drives save points and restore. Ignored for multiplayer worlds (the host persists via `save`). */
|
|
170
177
|
persist?: boolean | PersistConfig;
|
|
171
178
|
ui?: unknown;
|
|
172
179
|
loop?: GameLoop<GameContext>;
|
|
@@ -180,14 +187,14 @@ export interface GameDefinition<TAssetRef extends ModelAssetRef = ModelAssetRef,
|
|
|
180
187
|
*/
|
|
181
188
|
replication?: ReplicationPolicy;
|
|
182
189
|
}
|
|
183
|
-
/** Input to {@link
|
|
190
|
+
/** Input to {@link defineGameDefinition} — a `GameDefinition` with `scene` derived and `assets` optional. */
|
|
184
191
|
export type GameDefinitionConfig<TAssetRef extends ModelAssetRef = ModelAssetRef, TMultiplayer = unknown> = Omit<GameDefinition<TAssetRef, TMultiplayer>, "scene" | "assets"> & {
|
|
185
192
|
assets?: AssetCatalog<TAssetRef>;
|
|
186
193
|
};
|
|
187
194
|
/**
|
|
188
|
-
*
|
|
189
|
-
* OR-merges `features` from installed systems, and composes `loop` from `systems` + any classic
|
|
190
|
-
*
|
|
191
|
-
*
|
|
195
|
+
* Host-level constructor for a bare `GameDefinition`: fills in `scene` and default `assets`, validates
|
|
196
|
+
* `name`, OR-merges `features` from installed systems, and composes `loop` from `systems` + any classic
|
|
197
|
+
* hooks. Games author through `defineGame` from `@jgengine/shell/defineGame`, which calls this and adds
|
|
198
|
+
* the presentation layer; call this directly only from headless hosts that mount no shell.
|
|
192
199
|
*/
|
|
193
|
-
export declare function
|
|
200
|
+
export declare function defineGameDefinition<TAssetRef extends ModelAssetRef, TMultiplayer>(config: GameDefinitionConfig<TAssetRef, TMultiplayer>): GameDefinition<TAssetRef, TMultiplayer>;
|
package/dist/game/defineGame.js
CHANGED
|
@@ -2,6 +2,7 @@ import { mergeSystemFeatures } from "./defineSystem.js";
|
|
|
2
2
|
import { composeGameLoop } from "./systemRuntime.js";
|
|
3
3
|
import { createAssetCatalog } from "../scene/assetCatalog.js";
|
|
4
4
|
import { createEntityStore } from "../scene/entityStore.js";
|
|
5
|
+
import { resolveWorldPhysics } from "../world/place.js";
|
|
5
6
|
/** @internal */
|
|
6
7
|
export function createDisposer() {
|
|
7
8
|
const cleanups = [];
|
|
@@ -25,19 +26,26 @@ export function createDisposer() {
|
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
* OR-merges `features` from installed systems, and composes `loop` from `systems` + any classic
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* Host-level constructor for a bare `GameDefinition`: fills in `scene` and default `assets`, validates
|
|
30
|
+
* `name`, OR-merges `features` from installed systems, and composes `loop` from `systems` + any classic
|
|
31
|
+
* hooks. Games author through `defineGame` from `@jgengine/shell/defineGame`, which calls this and adds
|
|
32
|
+
* the presentation layer; call this directly only from headless hosts that mount no shell.
|
|
32
33
|
*/
|
|
33
|
-
export function
|
|
34
|
+
export function defineGameDefinition(config) {
|
|
34
35
|
if (config.name.trim().length === 0) {
|
|
35
|
-
throw new Error("
|
|
36
|
+
throw new Error("defineGameDefinition: name must be non-empty");
|
|
36
37
|
}
|
|
38
|
+
// Boolean `features: { quest: true }` is sugar for the same activation map systems produce via
|
|
39
|
+
// `feature: "quest"`. Both OR-merge here; `createGameContext` only reads this final map through
|
|
40
|
+
// featureDescriptors.enabled — one enable path, no dual checks at install time.
|
|
37
41
|
const features = mergeSystemFeatures(config.features, config.systems);
|
|
38
42
|
const loop = composeGameLoop(config.systems, config.loop);
|
|
43
|
+
// A place world carries the laws of that place: its physics resolves over the game-level default,
|
|
44
|
+
// so every consumer of definition.physics (movement, combat, shell) sees the active world's laws.
|
|
45
|
+
const physics = resolveWorldPhysics(config.world, config.physics);
|
|
39
46
|
return {
|
|
40
47
|
...config,
|
|
48
|
+
...(physics === undefined ? {} : { physics }),
|
|
41
49
|
features,
|
|
42
50
|
loop,
|
|
43
51
|
scene: createEntityStore(),
|
|
@@ -78,6 +78,8 @@ export interface SystemDefinition {
|
|
|
78
78
|
/**
|
|
79
79
|
* Declare a composable game system. Pure data + hooks — the engine compiles the schedule and
|
|
80
80
|
* installs lifecycle when the game boots.
|
|
81
|
+
*
|
|
82
|
+
* @capability define-system composable game behavior — pure data + hooks the engine schedules; pass via `defineGame({ systems })`
|
|
81
83
|
*/
|
|
82
84
|
export declare function defineSystem(definition: SystemDefinition): SystemDefinition;
|
|
83
85
|
/** Collect feature flags implied by a system list (OR-merge; installing a system activates its capability).
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Declare a composable game system. Pure data + hooks — the engine compiles the schedule and
|
|
3
3
|
* installs lifecycle when the game boots.
|
|
4
|
+
*
|
|
5
|
+
* @capability define-system composable game behavior — pure data + hooks the engine schedules; pass via `defineGame({ systems })`
|
|
4
6
|
*/
|
|
5
7
|
export function defineSystem(definition) {
|
|
6
8
|
if (definition.id.trim().length === 0) {
|
package/dist/game/events.d.ts
CHANGED
|
@@ -191,6 +191,31 @@ export interface AudioMusicEvent {
|
|
|
191
191
|
theme: string | null;
|
|
192
192
|
transpose?: number;
|
|
193
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Start (or idempotently keep) the retained, id-keyed audio loop `id` from catalog `sound`, optionally
|
|
196
|
+
* anchored at world `at`. Restarting with the same `sound` does not restart the source (no click); a
|
|
197
|
+
* different `sound` replaces it. Drives RPM-pitched engine loops and slip-scaled tire squeal (#1051).
|
|
198
|
+
*/
|
|
199
|
+
export interface AudioLoopStartEvent {
|
|
200
|
+
id: string;
|
|
201
|
+
sound: string;
|
|
202
|
+
at?: readonly [number, number, number];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Live-update the retained loop `id`: `rate` re-pitches it (1 = authored, the shell clamps to 0.25–4),
|
|
206
|
+
* `gain` rescales its volume (0–1), and `at` repositions its emitter. Emitted every tick to track a
|
|
207
|
+
* live signal (RPM, tire slip); the shell smooths rate/gain and ignores an unknown `id` (#1051).
|
|
208
|
+
*/
|
|
209
|
+
export interface AudioLoopSetEvent {
|
|
210
|
+
id: string;
|
|
211
|
+
rate?: number;
|
|
212
|
+
gain?: number;
|
|
213
|
+
at?: readonly [number, number, number];
|
|
214
|
+
}
|
|
215
|
+
/** Stop and dispose the retained loop `id`; an unknown `id` is ignored (#1051). */
|
|
216
|
+
export interface AudioLoopStopEvent {
|
|
217
|
+
id: string;
|
|
218
|
+
}
|
|
194
219
|
export interface GameEventMap {
|
|
195
220
|
"entity.died": EntityDiedEvent;
|
|
196
221
|
"entity.floatText": EntityFloatTextEvent;
|
|
@@ -221,6 +246,9 @@ export interface GameEventMap {
|
|
|
221
246
|
"audio.play": AudioPlayEvent;
|
|
222
247
|
"audio.music": AudioMusicEvent;
|
|
223
248
|
"audio.resume": AudioResumeEvent;
|
|
249
|
+
"audio.loopStart": AudioLoopStartEvent;
|
|
250
|
+
"audio.loopSet": AudioLoopSetEvent;
|
|
251
|
+
"audio.loopStop": AudioLoopStopEvent;
|
|
224
252
|
"entity.animation": EntityAnimationEvent;
|
|
225
253
|
}
|
|
226
254
|
export type GameEventHandler<TPayload> = (payload: TPayload) => void;
|