threedog 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +893 -798
- package/README.md +1 -1
- package/core/assets/Animator.js +41 -3
- package/core/assets/Assets.js +100 -24
- package/core/assets/assetEntry.js +73 -20
- package/core/assets/assetHot.js +68 -16
- package/core/assets/assetLoad.js +6 -6
- package/core/assets/assetLod.js +9 -2
- package/core/assets/assetManifest.js +12 -2
- package/core/assets/assetPart.js +54 -0
- package/core/assets/ik.js +271 -0
- package/core/assets/modelNeeds.js +37 -0
- package/core/assets/namedModel.js +102 -29
- package/core/assets/nodeVisibility.js +15 -0
- package/core/audio/Audio.js +36 -4
- package/core/audio/audioReverb.js +99 -0
- package/core/audio/audioRules.js +1 -1
- package/core/audio/audioVoice.js +1 -1
- package/core/base/Events.js +14 -4
- package/core/base/Random.js +1 -1
- package/core/base/Vars.js +1 -1
- package/core/base/docRef.js +51 -0
- package/core/base/errorCodes.js +187 -126
- package/core/base/errorHints.js +9 -7
- package/core/base/errors.js +25 -10
- package/core/base/events.generated.js +2 -0
- package/core/base/freeParts.js +76 -0
- package/core/base/math.js +28 -0
- package/core/base/sections.js +5 -5
- package/core/base/validate.js +31 -3
- package/core/engine/Engine.js +17 -7
- package/core/engine/Loading.js +5 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +4 -1
- package/core/engine/lifecycle.js +32 -16
- package/core/engine/loop.js +71 -27
- package/core/engine/moduleSlots.js +2 -2
- package/core/engine/moduleTypes.js +3 -3
- package/core/engine/modules.js +65 -39
- package/core/engine/page.js +6 -3
- package/core/engine/services.js +6 -5
- package/core/engine/startup.js +8 -7
- package/core/input/Input.js +28 -14
- package/core/input/inputContext.js +28 -16
- package/core/input/inputKeyboard.js +31 -3
- package/core/input/inputPad.js +4 -0
- package/core/input/inputPointer.js +2 -1
- package/core/input/inputSeat.js +1 -1
- package/core/inspect/Budget.js +109 -19
- package/core/inspect/DebugOverrides.js +28 -4
- package/core/inspect/Describe.js +17 -9
- package/core/inspect/Inspect.js +4 -2
- package/core/inspect/InspectMaterials.js +3 -1
- package/core/inspect/InspectPerf.js +19 -9
- package/core/inspect/InspectScene.js +32 -7
- package/core/inspect/MaterialInfo.js +19 -2
- package/core/inspect/UrlState.js +50 -28
- package/core/inspect/catalog.js +28 -9
- package/core/inspect/debugView.js +2 -1
- package/core/inspect/describeRender.js +25 -13
- package/core/inspect/describeText.js +14 -6
- package/core/inspect/lightWatch.js +1 -1
- package/core/inspect/metadata.generated.js +35 -17
- package/core/inspect/pictureChecks.js +148 -0
- package/core/inspect/pictureMenu.js +84 -0
- package/core/inspect/pictureWriters.js +26 -6
- package/core/inspect/textureBytes.js +12 -2
- package/core/inspect/toolDoor.js +2 -4
- package/core/ops/Ops.js +11 -4
- package/core/ops/holds.js +27 -10
- package/core/ops/opsAtomic.js +15 -7
- package/core/ops/opsGuard.js +2 -2
- package/core/ops/opsRun.js +8 -7
- package/core/ops/sharedPoint.js +72 -21
- package/core/ops/stacks.js +56 -16
- package/core/saves/SaveStore.js +9 -3
- package/core/saves/Saves.js +32 -23
- package/core/saves/saveApply.js +96 -44
- package/core/saves/saveIds.js +1 -1
- package/core/saves/saveVersions.js +7 -5
- package/core/saves/session.js +17 -8
- package/core/saves/stateReplace.js +34 -15
- package/core/scene/Rays.js +52 -10
- package/core/scene/Views.js +36 -15
- package/core/scene/adaptive.js +144 -21
- package/core/scene/drawOnly.js +17 -0
- package/core/scene/gameLights.js +47 -4
- package/core/scene/sceneMethods.js +13 -11
- package/core/scene/stepPoses.js +11 -3
- package/core/scene/targeting.js +5 -3
- package/core/scene/thingOps.js +1 -1
- package/core/scene/tier.js +15 -0
- package/core/stream/Batching.js +30 -7
- package/core/stream/Stream.js +26 -7
- package/core/stream/batchGroups.js +2 -2
- package/core/stream/chunkStream.js +7 -5
- package/core/stream/prepare.js +77 -0
- package/core/time/skip.js +3 -1
- package/core/time/time.js +4 -2
- package/docs/AI.md +82 -83
- package/docs/API.md +16 -16
- package/docs/CODEMAP.md +17 -11
- package/docs/COMMANDS.md +139 -142
- package/docs/CONVENTIONS.md +37 -49
- package/docs/MIGRATING-0.8.md +2 -2
- package/docs/MIGRATING-1.0.md +2 -2
- package/docs/THREE.md +30 -35
- package/docs/api/assets.md +3 -1
- package/docs/api/audio.md +4 -2
- package/docs/api/budget.md +5 -0
- package/docs/api/characters.md +10 -8
- package/docs/api/collision.md +6 -4
- package/docs/api/engine.md +16 -16
- package/docs/api/events.md +3 -2
- package/docs/api/ground.md +6 -5
- package/docs/api/hud.md +4 -2
- package/docs/api/input.md +5 -5
- package/docs/api/particles.md +2 -1
- package/docs/api/photo.md +3 -0
- package/docs/api/post.md +7 -4
- package/docs/api/quests.md +2 -2
- package/docs/api/rays.md +1 -2
- package/docs/api/saves.md +7 -7
- package/docs/api/settings.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -2
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +16 -17
- package/docs/recipes/02-npc.md +22 -18
- package/docs/recipes/03-items-pickups.md +37 -35
- package/docs/recipes/04-quests.md +15 -10
- package/docs/recipes/05-props-bake.md +101 -95
- package/docs/recipes/06-clock-events.md +28 -28
- package/docs/recipes/07-flow-scenes-pause.md +29 -26
- package/docs/recipes/08-weather-sky.md +52 -64
- package/docs/recipes/09-materials-lights-models.md +26 -17
- package/docs/recipes/10-blender-level.md +15 -10
- package/docs/recipes/11-vehicles.md +12 -7
- package/docs/recipes/12-navmesh.md +44 -26
- package/docs/recipes/13-animation.md +56 -45
- package/docs/recipes/14-custom-module.md +21 -18
- package/docs/recipes/15-perf.md +61 -55
- package/docs/recipes/16-dev-bridge.md +24 -33
- package/docs/recipes/18-world.md +36 -42
- package/docs/recipes/19-shooting-picking.md +20 -15
- package/docs/recipes/20-content-actions-save.md +48 -56
- package/docs/recipes/21-camera.md +45 -54
- package/docs/recipes/22-shop-gold.md +12 -7
- package/docs/recipes/23-ops.md +25 -23
- package/docs/recipes/26-ui-parts.md +67 -47
- package/docs/recipes/27-net.md +12 -7
- package/docs/recipes/28-terrain.md +24 -21
- package/docs/recipes/29-grid.md +32 -27
- package/docs/recipes/30-templates.md +21 -20
- package/docs/recipes/31-audio.md +39 -22
- package/docs/recipes/32-action-game.md +19 -14
- package/docs/recipes/33-stream-sources.md +15 -11
- package/docs/recipes/34-environment-lighting.md +126 -70
- package/docs/recipes/35-picture-from-reference.md +8 -8
- package/docs/recipes/36-ground-plants.md +27 -21
- package/docs/recipes/40-scene.md +19 -28
- package/docs/recipes/43-shader-patches-surfaces.md +15 -12
- package/docs/recipes/44-water-weather-hooks.md +34 -31
- package/docs/recipes/45-cascaded-shadows.md +35 -26
- package/docs/recipes/46-blender-art-route.md +7 -2
- package/docs/recipes/49-game-module-contract.md +13 -8
- package/docs/recipes/50-own-renderer.md +6 -2
- package/docs/recipes/51-capability-catalog.md +15 -8
- package/docs/recipes/52-around-the-picture.md +34 -32
- package/docs/recipes/53-ground-up-close.md +6 -1
- package/docs/recipes/55-mods-time-wrap.md +27 -19
- package/docs/recipes/56-webgpu-tsl.md +75 -43
- package/docs/recipes/57-control.md +18 -13
- package/docs/recipes/58-input.md +26 -16
- package/docs/recipes/59-depth-post-effects.md +8 -3
- package/docs/recipes/60-judge-the-picture.md +10 -9
- package/docs/recipes/61-deploy.md +5 -0
- package/docs/recipes/62-picture-code.md +72 -79
- package/docs/recipes/63-third-person-start.md +48 -45
- package/docs/recipes/64-particles.md +22 -10
- package/docs/recipes/65-swarm.md +18 -13
- package/docs/recipes/66-common-tasks.md +38 -35
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -3
- package/examples/action/main.js +3 -3
- package/examples/action/picture/lights.js +3 -1
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/picture/lights.js +2 -1
- package/examples/plain-picture/GAMEMAP.md +1 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/main.js +1 -1
- package/examples/techniques/interior-light/README.md +3 -3
- package/examples/techniques/interior-light/interiorLight.js +2 -4
- package/examples/techniques/interior-light/picture/lights.js +2 -1
- package/examples/techniques/modular-building/picture/lights.js +3 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/main.js +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +2 -3
- package/examples/world/art/humanoid.js +1 -1
- package/examples/world/main.js +6 -3
- package/index.d.ts +2 -2
- package/llms.txt +101 -0
- package/modules/ambience/Ambience.js +21 -5
- package/modules/calendar/index.js +9 -5
- package/modules/calendar/schedule.js +23 -8
- package/modules/camera/FirstPersonCamera.js +3 -1
- package/modules/camera/FollowCamera.js +10 -5
- package/modules/camera/RtsCamera.js +4 -3
- package/modules/camera/common.js +70 -8
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +16 -10
- package/modules/characters/NPC.js +31 -19
- package/modules/characters/assetModel.js +14 -9
- package/modules/characters/astar.js +6 -1
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +34 -22
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +17 -2
- package/modules/characters/movers/simple.js +1 -1
- package/modules/characters/movers/support.js +16 -7
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/npcSim.js +3 -2
- package/modules/characters/pathAsync.js +24 -8
- package/modules/characters/pathJob.js +1 -1
- package/modules/characters/player.js +10 -9
- package/modules/characters/playerStrings.js +5 -5
- package/modules/characters/proceduralRig.js +5 -5
- package/modules/characters/useModel.js +6 -0
- package/modules/characters/walkTo.js +1 -1
- package/modules/collision/Collision.js +29 -18
- package/modules/collision/grid.js +22 -4
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +1 -1
- package/modules/content/models.js +82 -33
- package/modules/content/props.js +2 -1
- package/modules/content/rules.js +11 -5
- package/modules/content/templates.js +3 -3
- package/modules/content/words.js +2 -2
- package/modules/debug/DebugPanel.js +9 -9
- package/modules/flow/index.js +9 -6
- package/modules/gameplay/Dialogue.js +34 -20
- package/modules/gameplay/Interactions.js +19 -15
- package/modules/gameplay/Inventory.js +9 -4
- package/modules/gameplay/Quests.js +12 -10
- package/modules/gameplay/pickups.js +23 -11
- package/modules/grid/index.js +1 -1
- package/modules/grid/preview.js +2 -2
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +4 -1
- package/modules/hud/index.js +47 -10
- package/modules/hud/parts.js +28 -9
- package/modules/level/geometry.js +8 -3
- package/modules/level/index.js +10 -5
- package/modules/level/load.js +4 -2
- package/modules/lights/sources.js +1 -1
- package/modules/music/Music.js +22 -4
- package/modules/nav/index.js +20 -10
- package/modules/particles/Particles.js +31 -14
- package/modules/particles/effect.js +20 -5
- package/modules/particles/lit.js +72 -0
- package/modules/photo/Photo.js +72 -28
- package/modules/photo/pathTrace.js +106 -0
- package/modules/rigid/RigidBodies.js +23 -14
- package/modules/rigid/Vehicles.js +3 -13
- package/modules/rigid/sync.js +2 -1
- package/modules/settings/Settings.js +52 -20
- package/modules/settings/apply.js +23 -9
- package/modules/settings/sections.js +39 -6
- package/modules/settings/strings.js +2 -0
- package/modules/settings/view.js +19 -3
- package/modules/sky/dome.js +15 -3
- package/modules/sky/environment.js +28 -12
- package/modules/sky/fog.js +1 -1
- package/modules/sky/frame.js +6 -1
- package/modules/sky/shader.js +4 -3
- package/modules/sky/skyModule.js +8 -4
- package/modules/swarm/Swarm.js +1 -1
- package/modules/terrain/ChunkManager.js +61 -15
- package/modules/terrain/chunkJob.js +2 -2
- package/modules/terrain/index.js +20 -5
- package/modules/terrain/terrainEdit.js +8 -4
- package/modules/terrain/terrainTexture.js +4 -2
- package/modules/timeline/Timeline.js +4 -3
- package/modules/timeline/Tween.js +3 -0
- package/modules/timeline/letterbox.js +1 -0
- package/modules/triggers/index.js +36 -17
- package/modules/vegetation/Vegetation.js +81 -19
- package/modules/vegetation/densityMap.js +13 -8
- package/modules/vegetation/draw.js +147 -24
- package/modules/vegetation/groundChunks.js +20 -5
- package/modules/vegetation/index.js +3 -3
- package/modules/vegetation/modelGeometry.js +9 -4
- package/modules/water/Water.js +11 -8
- package/modules/weather/Weather.js +7 -2
- package/modules/weather/shaders.js +25 -5
- package/modules/weather/weatherDraw.js +20 -6
- package/modules/world/World.js +2 -1
- package/modules/world/index.js +2 -2
- package/modules/world/persist.js +6 -2
- package/modules/world/views.js +15 -2
- package/package.json +5 -1
- package/presets.js +5 -5
- package/render/PostFX.js +102 -42
- package/render/backend.js +142 -16
- package/render/bindingLimits.js +59 -0
- package/render/cascades.js +3 -1
- package/render/cascades.tsl.js +2 -0
- package/render/daylight.js +7 -1
- package/render/detail.js +7 -4
- package/render/effects.js +27 -8
- package/render/fogLook.js +24 -0
- package/render/fuse.js +5 -2
- package/render/fx/compareLevel.tsl.js +23 -0
- package/render/fx/detail.tsl.js +9 -7
- package/render/fx/index.js +9 -2
- package/render/fx/library.tsl.js +1 -0
- package/render/fx/lightShaft.tsl.js +114 -0
- package/render/fx/noise.tsl.js +25 -8
- package/render/fx/objectOrigin.tsl.js +39 -10
- package/render/fx/particles.tsl.js +23 -6
- package/render/fx/patchNodes.tsl.js +17 -12
- package/render/fx/pcss.tsl.js +51 -0
- package/render/fx/postWebGPU.tsl.js +104 -29
- package/render/fx/sky.tsl.js +3 -9
- package/render/fxNumbers.js +10 -4
- package/render/impostor.tsl.js +107 -0
- package/render/lighting.js +33 -1
- package/render/lightmap.js +42 -28
- package/render/lights.js +19 -3
- package/render/materials.js +6 -4
- package/render/mergeCommon.js +4 -1
- package/render/occlusion.js +14 -4
- package/render/patches.js +79 -41
- package/render/postRuns.js +32 -0
- package/render/postWebGL.js +97 -10
- package/render/probes.js +10 -14
- package/render/shaderErrors.js +44 -7
- package/render/shadowCache.tsl.js +33 -5
- package/render/shadows.js +42 -16
- package/render/slots.js +8 -5
- package/render/vertexInputs.js +52 -0
- package/types/core.d.ts +115 -47
- package/types/gameplay.d.ts +56 -23
- package/types/generated/core/audio/Audio.d.ts +27 -1
- package/types/generated/core/base/Random.d.ts +1 -1
- package/types/generated/core/input/Input.d.ts +6 -8
- package/types/generated/core/input/inputSeat.d.ts +1 -1
- package/types/generated/core/inspect/Budget.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
- package/types/generated/core/saves/Saves.d.ts +10 -7
- package/types/generated/core/saves/session.d.ts +8 -2
- package/types/generated/core/scene/Rays.d.ts +1 -3
- package/types/generated/core/scene/Views.d.ts +17 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/world/World.d.ts +2 -1
- package/types/generated/render/PostFX.d.ts +35 -9
- package/types/physics.d.ts +796 -764
- package/types/pixel.d.ts +1 -1
- package/types/tsl.d.ts +62 -1
- package/types/world.d.ts +12 -3
- package/ui/Focus.js +7 -5
- package/ui/Parts.js +1 -1
- package/ui/touchPart.js +6 -3
package/docs/api/settings.md
CHANGED
|
@@ -13,7 +13,7 @@ Settings menu (settings() module)
|
|
|
13
13
|
- `settings.get(key: string) → any` — Read a setting, e.g. get('vol.music')
|
|
14
14
|
- `settings.set(key: string, value: any, opts?: { save?: boolean })` — Change a setting (takes effect immediately + saved)
|
|
15
15
|
- `settings.preset(name: 'low' | 'medium' | 'high' | (string & {}))` — (experimental) Graphics preset: 'low' / 'medium' / 'high'
|
|
16
|
-
- `settings.define(key: string, def: T, apply?: ((value, e) => void) | { apply?, limits
|
|
16
|
+
- `settings.define(key: string, def: T, apply?: ((value, e) => void) | { apply?, limits?, menu?, label?, options?, min?, … } | …)` — Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row restricts on the settings layer, like the built-in shadows row: off holds it off (the scene, weather or a cutscene cannot turn it back on), on allows what the scene chose; a number row from 0 to 1 is a factor on a number value. Define it after the effect exists. The menu draws the row itself in the tab menu names (default 'options', shown while it has a row): a switch for true/false, a slider for a number (min/max; a limits row has 0..1), buttons for options. label: an i18n key or text, else the key. menu: false when your own tab draws it; a row the menu cannot draw, a missing tab or a row drawn twice warns once
|
|
17
17
|
- `settings.addSection(id: string, section?: SettingsSection)` — Add a tab of your own, or a built-in / optional one by name: addSection('camera')
|
|
18
18
|
- `settings.reset(key?: string)` — Put one setting (or all, with no key) back to its default: the engine's start value, or the default the game gave define(). Keys: resetBindings
|
|
19
19
|
- `settings.resetBindings()` — (experimental) Restore all keys to defaults
|
|
@@ -25,7 +25,7 @@ Settings menu (settings() module)
|
|
|
25
25
|
- `values: Record<string, any>` All current setting values, read only (set() changes one). pixelRatio is the renderer's real ratio
|
|
26
26
|
- `presets: Record<string, QualityPreset>` Graphics presets
|
|
27
27
|
- `sections: Map<string, any>` (experimental) Tabs
|
|
28
|
-
- `isOpen: boolean`
|
|
28
|
+
- `isOpen: boolean` Whether the menu is open
|
|
29
29
|
|
|
30
30
|
## Data structures
|
|
31
31
|
- **SettingsSection** One settings tab
|
package/docs/api/tools.md
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
- `season(color: Node, kind: Node | 0 | 1) → Node` — (experimental) GLSL vec3 threedogSeason(vec3 color, int kind): kind 0 foliage, 1 ground; tints by uFoliageTint / uGroundTint (mix mode when uFoliageMix / uGroundMix > 0). A vec4 color is read as its rgb.
|
|
66
66
|
- `objectOrigin() → Node` — (experimental) World position of the drawn object's origin (an InstancedMesh: of each instance), vec3. Works for any Mesh / InstancedMesh sharing the material; BatchedMesh throws [tsl-misuse].
|
|
67
67
|
- `instanceOffset(offset: Node) → Node` — (experimental) An object-space offset carried through the drawn instance's rotation and scale (a plain Mesh: the offset as it is). A positionNode runs after the instance transform, so an offset meant for before it, like wind()'s, goes through this. BatchedMesh throws [tsl-misuse].
|
|
68
|
-
- `hash(p: Node) → Node` — (experimental) GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position.
|
|
68
|
+
- `hash(p: Node) → Node` — (experimental) GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position (an integer hash of its bits: the same on WebGL and WebGPU).
|
|
69
69
|
- `noise(p: Node) → Node` — (experimental) GLSL float threedogNoise(vec2 p): smooth value noise 0-1, the one behind the engine's clouds and cloud shadows. No uniforms.
|
|
70
70
|
- `uniforms(engine: { uniforms: object }) → Record<string, Node>` — (experimental) engine.uniforms as TSL uniform nodes (uTime, uWind, uWeatherCloud, uFoliageTint, uSunDir, uDaylight ...), cached per engine. They read the same { value } objects, so engine.uniforms.uWind.value = 2 changes GLSL and TSL materials alike.
|
|
71
71
|
- `detailNoise(p: Node, kind: Node | 0 | 1 | 2 | 3, octaves: Node | number) → Node` — (experimental) GLSL vec4 threedogDetailNoise(vec2 p, int kind, float octaves): kind 0 grain, 1 paper, 2 stroke, 3 dabs; returns (gray rgb, height 0-1). No uniforms: p is any 2D pattern position you choose (world xz times a scale, a uv...). octaves: up to 4 (dabs: 3).
|
|
@@ -74,7 +74,9 @@
|
|
|
74
74
|
- `shadowTint(ambient: Node, tint: Node, strength: Node | number, soft: Node | number, nl: Node, shadow: Node | number) → Node` — (experimental) GLSL vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow): the ambient with the shaded side's hue moved toward tint (brightness kept). shadow: 1 lit / 0 shadowed (the sun's lightNode.shadowNode); soft: terminator width in n.l.
|
|
75
75
|
- `rim(normal: Node, viewDir: Node, color: Node, strength: Node | number, power: Node | number, shadowSide: Node | number, nl: Node) → Node` — (experimental) GLSL vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl): edge light to add (viewDir from the surface to the eye, e.g. normalView and positionViewDirection); shadowSide 1 = only on the side facing away from the sun.
|
|
76
76
|
- `celLighting() → import('three/webgpu').LightingMo…` — (experimental) The lighting model for cel bands with colored ramps: assign it to a MeshToonNodeMaterial, whose gradientMap holds the ramp (rampTexture). A shadowed pixel reads the dark end of the ramp, so a cast shadow takes the same flat band and color as the side turned away. Without a gradientMap: two levels, as three's toon.
|
|
77
|
+
- `pcss(o?: { lightSize?, samples?, maxDistance? }) → any` — (experimental) A shadow filter for a DirectionalLight whose edge softens with the distance from caster to receiver (PCSS). The game assigns it before the first frame; it reaches the engine's cascades too. lightSize: edge width per world unit of that distance; samples: filter taps; maxDistance: where the edge stops growing. A spot or point light throws by name.
|
|
77
78
|
- `waterWave(p: Node, t: Node | number) → Node` — (experimental) GLSL float threedogWaterWave(vec3 p, float t): the built-in wave sum (height before waveHeight). p = world position * waveScale, t = time * waveSpeed.
|
|
78
79
|
- `waterSurface(spec?: { depth?, foam?, waveMax? }) → (base, wave, facing, worldPos, time) => Node` — (experimental) The built-in water surface as TSL: returns a function with the GLSL signature threedogWaterSurface(base, wave, facing, worldPos, time) -> vec4 (rgb, opacity). Only the parts given exist (depth: shallow / deep by viewing angle or wave height; foam on crests); values are numbers / colors or nodes. wave is waterWave's height, facing = 1 looking straight down.
|
|
79
80
|
- `waterFresnel(color: Node, normal: Node, viewDir: Node, strength: Node | number, towards: Node) → Node` — (experimental) The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - /viewDir . normal/, 3) * strength, view space
|
|
81
|
+
- `lightShaft(engine: { renderer, uniforms, tier }, opts?: LightShaftOptions) → LightShaft` — (experimental) A cheap visible light beam (ceiling hole, window, stage light): an additive open cone, top at the mesh origin pointing down -Y, sides softened by view angle, faded where it meets geometry and near the camera, dimmed (not tinted) by scene fog. Occluders do not cut it (for that: sunShafts / lightVolumes). WebGPURenderer only (both backends); WebGLRenderer throws by name. Add / move / remove it like any mesh; engine.remove frees it.
|
|
80
82
|
- `serve(handler: (msg: any) => any)` — Start answering lane messages in a worker. handler is the same function the lane's local() returns on the main thread.
|
package/docs/api/vars.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# engine.vars (Vars) — engine.vars: story flags and counters (autosaved)
|
|
2
2
|
|
|
3
3
|
- `vars.flag(key: string) → any` — Read a flag
|
|
4
|
-
- `vars.setFlag(key: string, value?: any)` —
|
|
4
|
+
- `vars.setFlag(key: string, value?: any)` — Set a flag (default true)
|
|
5
5
|
- `vars.counter(key: string) → number` — Read a counter (0 if none)
|
|
6
6
|
- `vars.bump(key: string, n?: number) → number` — Counter +n (default 1), returns the new value
|
|
7
7
|
- Properties:
|
package/docs/api/vegetation.md
CHANGED
|
@@ -16,10 +16,11 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
|
|
|
16
16
|
- `vegetation.rebuild()` — Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is followed automatically
|
|
17
17
|
- `vegetation.setShadowRing(name: string, ring: number)` — Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default, larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones. Example: `engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk`
|
|
18
18
|
- `vegetation.define(name: string, opts: VegetationOptions) → Species | Promise<Species>` — Define a kind of vegetation (a model name in model / lodGeometry: resolves first, so the result is a Promise of the species)
|
|
19
|
-
- `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean` — (
|
|
19
|
+
- `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean` — Was this instance removed (removeInstance) and not restored
|
|
20
20
|
- `vegetation.removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }) → string` — Remove one (chop a tree). regrowSeconds: grows back after this many calendar seconds, 0 = permanent. The record is saved with the save (save key 'vegetation'). Returns the entry name
|
|
21
|
-
- `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` —
|
|
21
|
+
- `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — Restore one removed instance
|
|
22
22
|
- `vegetation.instanceAt(position: PositionLike, opts?: { radius?, species? }) → VegetationHit | null` — The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none
|
|
23
|
+
- `vegetation.plantOf(hit: { object?, instanceId? } | null | undefined) → VegetationHit | null` — The plant a ray hit, read from the hit itself (no spatial guess): the same VegetationHit instanceAt returns (goes to removeInstance), null if not vegetation or a far impostor card
|
|
23
24
|
- Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`
|
|
24
25
|
- Properties:
|
|
25
26
|
- `material: Material | null` The shared default material: species with no material or model of their own draw it, as given, planted ones too; null gives the neutral default back. Until set, reading gives the neutral source of each species' own copy (only .color written there reaches them all). Throws when a game module drew the plants instead (replaces: 'vegetation-draw').
|
|
@@ -38,6 +39,7 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
|
|
|
38
39
|
- `maxRing?: number` No longer drawn beyond this many rings
|
|
39
40
|
- `fade?: false | { start?: number; end?: number }` Distance fade of a near-only species (grass, flowers, pebbles, debris ...): instances shrink out over a band in metres from the player instead of popping per chunk at the ring edge. Default for nearOnly: end = maxRing x chunk size, start = 65% of it. `false` keeps the hard ring edge (also the default for species that are not nearOnly).
|
|
40
41
|
- `lodRing?: number` Switch to the low-detail model beyond this many rings, default 1
|
|
42
|
+
- `impostor?: boolean | { views?: number; size?: number }` Beyond lodRing, draw camera-facing cards baked from this species' own model and materials: one draw for all far chunks, lit through baked normals, no shadow there. views around the plant (default 8), size in pixels per view (default 128). Not with lodGeometry. WebGPU only (WebGL draws the mesh and warns)
|
|
41
43
|
- `castShadow?: boolean` Cast shadows
|
|
42
44
|
- `shadowRing?: number` Cast shadows within this many rings
|
|
43
45
|
- `receiveShadow?: boolean` Receive shadows, default true
|
package/docs/api/world.md
CHANGED
|
@@ -13,7 +13,7 @@ World data (world() module): things that must be saved, survive level changes an
|
|
|
13
13
|
- `world.remove(id: string)` — Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved, so it stays gone after loading
|
|
14
14
|
- `world.query(opts?: { kind?, near?, radius?, where?, zone? }) → WorldRecord[]` — Query records; returns an array. With near only nearby cells are scanned and results are sorted nearest first (radius defaults to 30 m); where filters further. For neighbor queries every step use forEachNear. Example: `engine.world.query({ kind: 'zombie', near: engine.player, radius: 30, where: z => !z.dead })`
|
|
15
15
|
- `world.forEachNear(center: any, radius: number, fn: (rec, d2) => void)` — Call fn(rec, d2) for each record within radius meters (horizontal distance) of center; d2 is the squared distance. Unsorted, no allocation: use it for per-step neighbor queries (hundreds of zombies avoiding each other). Don't add / remove / move in the callback (moving into a cell not yet visited visits it again): record the change and apply it after the loop. Example: `engine.world.forEachNear(rec.position, 5, (o, d2) => { if (o !== rec && o.kind === 'zombie') n++; })`
|
|
16
|
-
- `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj).
|
|
16
|
+
- `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. Only the position is world's: rec.rot / rec.scale are the build's to apply (rotate the root or a child, in its own units) and update's to follow. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
|
|
17
17
|
- `world.view(id: string) → any` — The current model of this record (only exists nearby; null if not built yet or far away)
|
|
18
18
|
- `world.refresh()` — Build / tear down models for the stream sources right now (normally automatic every frame, with a per-frame limit). Use it right after add when you need the model: sync builds are available via view(id) after the call, for async ones also await world.whenReady. Example: `engine.world.add({ id: 'gate', kind: 'gate', position: p }); engine.world.refresh(); engine.world.view('gate')`
|
|
19
19
|
- `world.simulate(kind: string, opts: { near?, far?, farEvery?, radius?, fullRadius?, nearEvery?, … }) → { remove(): void }` — Register how a kind of thing changes (gameplay logic goes here, runs in the fixed step); near / far is split by distance from world.anchor (default: the player): near(rec, dt, obj): within radius, once per fixed step (obj is the model, may be null if not built yet; gameplay must not depend on it); far(rec, dt): farther away, once every farEvery seconds; dt is the seconds accumulated since the last simulation (can catch up a long time at once); on the far → near step, far runs first to pay back the owed time. With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up. Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now and compare. Example: `engine.world.simulate('zombie', { near: (rec, dt) => chase(rec, dt), far: (rec, dt) => wander(rec, dt), farEvery: 2 })`
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Starting a new game
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
> **Covers:** a new game folder: page, modules, content data, tests.
|
|
4
|
+
> **Use when:** starting any game.
|
|
5
|
+
> **Shortest:** `npm run new-game -- my-game` (`npx threedog init` outside the repo).
|
|
6
|
+
> **Sections:** 0 One-command setup preferred) · 1 Creating the files · 2 Verify · 3 Feel presets opt-in) · 4 Canvas size full
|
|
4
7
|
|
|
5
8
|
Goal: a game with its own page, modules, content data and tests. The engine's own example is `examples/world/` in the package.
|
|
6
9
|
|
|
@@ -63,7 +66,7 @@ The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib
|
|
|
63
66
|
// The opening stays as in recipe 63 §1: createEngine({ canvas, lights: false, ui, saveKey, bindings }), engine.use(createPicture()) after engine.use,
|
|
64
67
|
// Object.assign(window, { engine, picture }) (tests, screenshots and the console rely on it), await engine.start().
|
|
65
68
|
import { presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
|
|
66
|
-
import { terrainPreset } from '@threedog/terrain-noise';
|
|
69
|
+
import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
|
|
67
70
|
import data from './content/index.js';
|
|
68
71
|
|
|
69
72
|
// keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps); this goes in createEngine({ bindings })
|
|
@@ -75,8 +78,8 @@ engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), tim
|
|
|
75
78
|
content());
|
|
76
79
|
// the terrain is generated: find flat ground as "home" at the start (give your own height range to avoid beach and peaks)
|
|
77
80
|
const home = engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 });
|
|
78
|
-
engine.characters.
|
|
79
|
-
engine.content.load(data, { places: { home } });
|
|
81
|
+
engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: home });
|
|
82
|
+
engine.content.load(data, { places: { home } }); // on top of the names in content/places.js; content uses { place: 'home', x, z }, quests target: 'home'
|
|
80
83
|
```
|
|
81
84
|
Every `openWorld` part takes `false` (leave it out) or its module's own options object, so you never have to drop the preset for one setting:
|
|
82
85
|
`openWorld({ seed: 42, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience:
|
|
@@ -87,9 +90,9 @@ false, debug: false })`;
|
|
|
87
90
|
With `terrain: false` the game supplies its ground. Until it does, characters, props and pickups stand on an invisible flat plane at y = 0 (no
|
|
88
91
|
warning): they look like they float over nothing. Draw the ground yourself, and if it is not flat at y = 0 tell the engine its height:
|
|
89
92
|
```js
|
|
90
|
-
const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c }));
|
|
93
|
+
const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c })); // what you see
|
|
91
94
|
floor.receiveShadow = true; engine.add(floor);
|
|
92
|
-
engine.setGround({ height: (x, z) => 0 });
|
|
95
|
+
engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the camera read (a ramp, a raised floor: return its y here)
|
|
93
96
|
```
|
|
94
97
|
Walls and obstacles are `engine.collision.addBox(obj, { halfWidth, halfDepth })`; a Blender level brings its own ground (`level()`, next paragraph).
|
|
95
98
|
`saveKey` must differ per game, otherwise saves overwrite each other. The UI language follows the player's browser (Chinese browser -> Chinese,
|
|
@@ -109,23 +112,19 @@ export default { items, startItems, places };
|
|
|
109
112
|
1. `npm run map` -> generates `games/my-game/GAMEMAP.md`; check the "engine modules" and "page /" sections.
|
|
110
113
|
2. `npm run check` -> content validation points out wrong file names, ids and clock-time formats; `npm run types` finds misused engine APIs.
|
|
111
114
|
3. `npm run shot -- -w my-game / --describe-only` -> the text has a `player` line with its position, the module list, and no "still loading".
|
|
112
|
-
4. `npm test -w games/my-game` -> without `tests/specs/`
|
|
113
|
-
|
|
114
|
-
5. To see the picture: `npm run shot -- -w my-game /` (one image in `games/my-game/.threedog/shots/`); while developing run `npm run dev -w games/my-game` (or
|
|
115
|
-
`npm run dev -- my-game`) and open the printed address; read errors in `games/my-game/.threedog/errors.log`.
|
|
115
|
+
4. `npm test -w games/my-game` -> without `tests/specs/` a smoke test runs; gameplay specs: `COMMANDS.md` §"Running one game only" (a minimal example).
|
|
116
|
+
5. To see the picture: `npm run shot -- -w my-game /`; while developing `npm run dev -- my-game` and read errors in `games/my-game/.threedog/errors.log`.
|
|
116
117
|
|
|
117
118
|
|
|
118
119
|
## 3. Feel presets (opt-in)
|
|
119
|
-
The engine applies no gameplay feel by itself: `weather()` alone has only a calm `clear`, `sky()`
|
|
120
|
-
|
|
121
|
-
`
|
|
122
|
-
keys come from the game. `presets` holds named option objects a game picks on purpose; each only bundles options you could write yourself, so spread
|
|
123
|
-
and override:
|
|
120
|
+
The engine applies no gameplay feel by itself: `weather()` alone has only a calm `clear`, `sky()` no seasons, and calls that need a feel refuse to guess
|
|
121
|
+
(`addPlayer()` throws `[player-control]` without `control`, `interactions()` `[interaction-setup]` without `pick`, `openWorld()` `[open-world-camera]` without `camera`).
|
|
122
|
+
`presets` holds named option objects a game picks on purpose, bundling options you could write yourself, so spread and override:
|
|
124
123
|
```js fragment
|
|
125
124
|
import { presets, weather, calendar, sky, followCamera, interactions } from 'threedog';
|
|
126
125
|
engine.use(calendar(presets.calendar.fourSeasons), sky(), weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] }), followCamera(presets.camera.overShoulder));
|
|
127
|
-
engine.use(interactions({ ...presets.interactions.facing }));
|
|
128
|
-
const player = engine.characters.
|
|
126
|
+
engine.use(interactions({ ...presets.interactions.facing })); // nearest / facing / aim, each with E
|
|
127
|
+
const player = engine.characters.addPlayer({ ...presets.player.lockOn, faceTarget: boss }); // none / thirdPerson / lockOn / aim / sideScroller
|
|
129
128
|
```
|
|
130
129
|
The run / jump keys are `presets.bindings.walk`. No module or preset takes keys: every key comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
|
|
131
130
|
|
package/docs/recipes/02-npc.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Adding an NPC (schedule + dialogue)
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
> **Covers:** people with schedules, dialogue, avoidance and behavior of your own.
|
|
4
|
+
> **Use when:** a character the player meets or talks to.
|
|
5
|
+
> **Shortest:** an entry in content data plus `characters()`, `interactions()`, `dialogue()` (§1).
|
|
6
|
+
> **Sections:** 1 Write data recommended) · 2 Add in code · NPC data and model · Changing behavior / custom · Avoidance NPCs don't clump · A guard you build · Pick a dialogue choice · 3 Verify · Talking in a bubble
|
|
4
7
|
|
|
5
8
|
Modules needed: `characters()` (NPCs on by default), `interactions({ ...presets.interactions.nearest })`, `dialogue()`; clock-time schedules need
|
|
6
9
|
`calendar()` with a day cycle (`dayLength`, e.g. `presets.calendar.cycle`: without one the clock never moves and the NPC keeps to one stop). `openWorld()`
|
|
@@ -13,16 +16,16 @@ interactions({ ...presets.interactions.nearest }), dialogue(), content())`.
|
|
|
13
16
|
export default {
|
|
14
17
|
guard: {
|
|
15
18
|
name: 'Gate guard',
|
|
16
|
-
colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a },
|
|
17
|
-
start: { place: 'home', x: 6, z: -3 },
|
|
18
|
-
schedule: [
|
|
19
|
+
colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the default colors
|
|
20
|
+
start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
|
|
21
|
+
schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
|
|
19
22
|
{ at: '07:00', place: 'home', x: 6, z: -3 },
|
|
20
23
|
{ at: '13:00', place: 'tower' },
|
|
21
24
|
{ at: '18:30', place: 'home', x: 2, z: 4 },
|
|
22
25
|
],
|
|
23
|
-
interact: { op: 'npc.talk' },
|
|
26
|
+
interact: { op: 'npc.talk' }, // the interact key nearby talks: dialogue 'guard' (the NPC id) in dialogues.js
|
|
24
27
|
},
|
|
25
|
-
cat: { name: 'Cat', start: { place: 'home' }, behavior: 'wander', mind: { radius: 6 } },
|
|
28
|
+
cat: { name: 'Cat', start: { place: 'home' }, behavior: 'wander', mind: { radius: 6 } }, // no schedule: write behavior + start, omit schedule
|
|
26
29
|
};
|
|
27
30
|
```
|
|
28
31
|
A content NPC takes every `npcs.add` option (`speed`, `interact`, `arriveDistance`, `pathStep`, `repath`, `model`...) written as a
|
|
@@ -37,7 +40,7 @@ export default {
|
|
|
37
40
|
speaker: 'Gate guard',
|
|
38
41
|
nodes: {
|
|
39
42
|
start: {
|
|
40
|
-
text: [
|
|
43
|
+
text: [ // several variants: the first whose condition holds is used
|
|
41
44
|
{ if: { flag: 'metGuard' }, text: 'Back again?' },
|
|
42
45
|
{ text: 'Halt. First time here?' },
|
|
43
46
|
],
|
|
@@ -46,7 +49,7 @@ export default {
|
|
|
46
49
|
},
|
|
47
50
|
ask: { text: 'A pass costs one coin.', choices: [
|
|
48
51
|
{ text: 'Buy one', next: 'buy', if: { has: { coin: 1 } } },
|
|
49
|
-
{ text: 'No thanks' },
|
|
52
|
+
{ text: 'No thanks' }, // a choice with no next = the dialogue ends; a plain node with no next waits for one more interact press, then ends
|
|
50
53
|
] },
|
|
51
54
|
buy: { text: 'Move along.', do: [{ take: { coin: 1 } }, { give: { pass: 1 } }], next: 'end' },
|
|
52
55
|
},
|
|
@@ -62,8 +65,8 @@ from a level marker (such as `npc_guard`). Add a new content file to `content/in
|
|
|
62
65
|
## 2. Add in code (temporary NPCs, dynamic schedules)
|
|
63
66
|
```js
|
|
64
67
|
engine.dialogue.define('passerby', { start: { text: 'Nice day.', speaker: 'Passerby' } });
|
|
65
|
-
const npc = engine.npcs.add({ id: 'passerby', name: 'Passerby', position: [10, 0, 5], schedule: [{ at: '08:00', position: [20, 0, 5] }], interact: { op: 'npc.talk' } });
|
|
66
|
-
engine.npcs.remove('passerby');
|
|
68
|
+
const npc = engine.npcs.add({ id: 'passerby', name: 'Passerby', position: [10, 0, 5], schedule: [{ at: '08:00', position: [20, 0, 5] }], interact: { op: 'npc.talk' } }); // at: 'HH:MM' or 0-1; without id the name is used
|
|
69
|
+
engine.npcs.remove('passerby'); // remove by id, name or handle
|
|
67
70
|
```
|
|
68
71
|
|
|
69
72
|
**An NPC that stands still** (a quest giver): give `start` and omit both `schedule` and `behavior`; the default `schedule` behavior with no stops
|
|
@@ -82,6 +85,7 @@ you come near; changing level only removes the model, and it is rebuilt automati
|
|
|
82
85
|
the model is built at the computed position; nearby it paths around obstacles as usual.
|
|
83
86
|
- Add things to the model (a hat, a name tag) after every model build; don't call `npc.root.add(...)` right after add (the first model is built in the
|
|
84
87
|
next fixed step; for one immediately use `engine.world.refresh()`).
|
|
88
|
+
- Looking at the player: `npc.character.anim.addAim({ bones: ['Neck', 'Head'], target: engine.player.root })`, added with the rest of its model ([13 §3e](13-animation.md)).
|
|
85
89
|
- When two NPCs share a name, give each an `id` (without an id the name is the id, and in development a duplicate name throws). NPCs in content are
|
|
86
90
|
the world's **initial data**: the save records only changes such as position and state; schedule and name follow the content.
|
|
87
91
|
- Change data with `engine.world.set(npc.id, { mood: 'happy' })` (emits the world:change event); only plain values go in the data, models and
|
|
@@ -91,9 +95,9 @@ you come near; changing level only removes the model, and it is rebuilt automati
|
|
|
91
95
|
What an NPC "does" is a swappable **behavior**: the `behavior` field in the data picks it, and the schedule (`'schedule'`, the default) is just one of
|
|
92
96
|
them. Built in there is also `'wander'` (random wandering near home, using `engine.random`, same seed same result).
|
|
93
97
|
```js
|
|
94
|
-
npc.setBehavior('wander', { radius: 12 });
|
|
95
|
-
npc.setBehavior('schedule');
|
|
96
|
-
engine.npcs.add({ id: 'dog', name: 'Dog', position: [5, 0, 5], behavior: 'wander', mind: { radius: 8 } });
|
|
98
|
+
npc.setBehavior('wander', { radius: 12 }); // home = current position, wander within 12 meters (pause: [2, 6] pause seconds, home: { x, z } sets the center)
|
|
99
|
+
npc.setBehavior('schedule'); // back to the schedule
|
|
100
|
+
engine.npcs.add({ id: 'dog', name: 'Dog', position: [5, 0, 5], behavior: 'wander', mind: { radius: 8 } }); // wanders from the start
|
|
97
101
|
```
|
|
98
102
|
The behavior name and `mind` (the behavior's parameters and memory) are in the NPC data and are saved; after changing behavior or loading, the NPC
|
|
99
103
|
carries on with the new behavior. A wrong behavior name throws and lists the registered ones. NPCs in content can also write `behavior` + `mind`
|
|
@@ -112,8 +116,8 @@ or after loading.
|
|
|
112
116
|
engine.npcs.behavior('chase', {
|
|
113
117
|
near(rec, dt, npc) {
|
|
114
118
|
const p = npc.position, t = engine.player.position, dx = t.x - p.x, dz = t.z - p.z, d = Math.hypot(dx, dz) || 1;
|
|
115
|
-
npc.character?.move(d > 2 ? dx / d : 0, d > 2 ? dz / d : 0, false, dt);
|
|
116
|
-
engine.world.move(rec.id, npc.position);
|
|
119
|
+
npc.character?.move(d > 2 ? dx / d : 0, d > 2 ? dz / d : 0, false, dt); // no model: don't move
|
|
120
|
+
engine.world.move(rec.id, npc.position); // write the position back to the data
|
|
117
121
|
},
|
|
118
122
|
});
|
|
119
123
|
npc.setBehavior('chase');
|
|
@@ -130,8 +134,8 @@ into walls. The built-in `schedule` and `wander` both avoid.
|
|
|
130
134
|
`frameEvery` gives identical positions.
|
|
131
135
|
- Tune or turn off:
|
|
132
136
|
```js
|
|
133
|
-
engine.npcs.avoid.set({ radius: 0.6, strength: 2 });
|
|
134
|
-
engine.npcs.avoid.set(false);
|
|
137
|
+
engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // stand sparser (radius in meters), push slower (strength in meters/second)
|
|
138
|
+
engine.npcs.avoid.set(false); // turn off (ghosts, crowds passing through); set(true) turns it on again
|
|
135
139
|
```
|
|
136
140
|
- Far away (no model) NPCs are simulated from data without per-NPC avoidance; a few steps after a model is built on approach they get pushed apart.
|
|
137
141
|
- `nav({ crowd: true })` replaces this push with Recast crowd agents: they route around obstacles along the navmesh but do not guarantee identical
|
|
@@ -157,7 +161,7 @@ const guard = new Character(engine, { rig: { root: myGuardMesh } });
|
|
|
157
161
|
engine.add(guard.root);
|
|
158
162
|
guard.placeAt(post);
|
|
159
163
|
const walk = guard.walkTo(player.position, { arrive: 1.5 });
|
|
160
|
-
if ((await walk).status === 'noPath') guard.face(player);
|
|
164
|
+
if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
|
|
161
165
|
```
|
|
162
166
|
|
|
163
167
|
## Pick a dialogue choice, advance, close a dialogue
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# Adding items and pickups
|
|
2
2
|
|
|
3
|
-
**
|
|
4
|
-
|
|
3
|
+
> **Covers:** items, pickups, the inventory, single pieces, containers and shelves.
|
|
4
|
+
> **Use when:** things the player picks up, carries, uses or stores.
|
|
5
|
+
> **Shortest:** `engine.interactions.add(mesh, { id, label })` on your own mesh, or items as data (§1).
|
|
6
|
+
> **Sections:** Pick and count meshes · Items and pickups · 1 Write data recommended) · 2 In code dynamic · Single pieces durability, upgrade · Limits all optional, none · Using and dropping ops) · The inventory window UI · Chests / corpses / · 3 Verify
|
|
5
7
|
|
|
6
8
|
## Pick and count: meshes you built, no bag
|
|
7
9
|
Shells on a beach, four kinds of flowers, letters to collect: things the player takes and a number goes up. `interactions()`, `hud()` and a key (`createEngine({ bindings: presets.bindings.interact })`: E) are enough:
|
|
8
10
|
```js fragment
|
|
9
|
-
engine.hud.
|
|
11
|
+
engine.hud.addCounter('shells', { label: 'Shells', value: 0, max: 4 }); // at setup, not on session:start
|
|
10
12
|
shells.forEach((shell, i) => engine.interactions.add(shell, { id: `shell-${i}`, label: 'Pick up', once: true, counter: 'shells', onUse: () => engine.audio.sfx('pick') }));
|
|
11
13
|
```
|
|
12
14
|
`once` hides the mesh after a use (`onUse` returning `{ ok: false }` leaves it; an async `onUse` is judged when it settles, and a throw leaves it too); `counter` adds 1 through `engine.hud.bump(name, n)`, and does nothing without
|
|
@@ -34,16 +36,16 @@ their own bag; inside an op use `inventory.of(ctx.actor)`, never a fixed `'playe
|
|
|
34
36
|
// Items: id -> name, icon, description. stack = how many fit in one slot (default 99; more spill into further slots), weight (optional), color = color when dropped on the ground
|
|
35
37
|
export default {
|
|
36
38
|
mushroom: { name: 'Mushroom', icon: '🍄', desc: 'Found in the woods', color: 0xc0504d },
|
|
37
|
-
coin: { name: 'Coin', icon: '🪙', stack: 99999 },
|
|
39
|
+
coin: { name: 'Coin', icon: '🪙', stack: 99999 }, // currency: one slot however much you carry; full buying/selling in recipe 22
|
|
38
40
|
};
|
|
39
|
-
export const startItems = { coin: 3 };
|
|
41
|
+
export const startItems = { coin: 3 }; // what the inventory holds at the start (optional)
|
|
40
42
|
```
|
|
41
43
|
`content/pickups.js` (a list):
|
|
42
44
|
```js
|
|
43
45
|
export default [
|
|
44
|
-
{ item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 },
|
|
45
|
-
{ item: 'coin', x: 40, z: -12, count: 5, auto: true },
|
|
46
|
-
{ item: 'sword', x: 12, z: 4, data: { durability: 60 } },
|
|
46
|
+
{ item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 }, // respawn: after how many calendar seconds it grows back (omitted = never again)
|
|
47
|
+
{ item: 'coin', x: 40, z: -12, count: 5, auto: true }, // without place it is a world coordinate; count = how many at once; auto = taken by walking into it
|
|
48
|
+
{ item: 'sword', x: 12, z: 4, data: { durability: 60 } }, // data = this piece's own data (see "Single pieces"); radius = reach in meters (default 2)
|
|
47
49
|
];
|
|
48
50
|
```
|
|
49
51
|
Remember to `import items, { startItems } from './items.js'` and `import pickups from './pickups.js'` in `content/index.js` and put them in the exported object.
|
|
@@ -57,13 +59,13 @@ and at that time (also when far away with no model) it returns to the ground. Pi
|
|
|
57
59
|
|
|
58
60
|
## 2. In code (dynamic drops, custom models, instant effects)
|
|
59
61
|
```js fragment
|
|
60
|
-
engine.inventory.define('gem', { name: 'Gem', icon: '💎', color: 0x66ccff });
|
|
61
|
-
const gem = engine.pickups.spawn(engine.player.position, { give: 'gem', count: 1 });
|
|
62
|
+
engine.inventory.define('gem', { name: 'Gem', icon: '💎', color: 0x66ccff }); // shape: model: 'gemModel' (an asset name), else an asset named 'pickup:gem' / 'pickup', else a gray box (spawn { mesh } puts one object of the game's own down instead)
|
|
63
|
+
const gem = engine.pickups.spawn(engine.player.position, { give: 'gem', count: 1 }); // returns a handle; gem.remove() deletes data and model together
|
|
62
64
|
// opts.id writes a stable id (spawning again with the same id reuses the existing one)
|
|
63
|
-
engine.inventory.add('coin', 2);
|
|
64
|
-
engine.pickups.spawn([8, 0, 2], { give: 'ammo', count: 30, auto: true, radius: 1.2 });
|
|
65
|
-
engine.pickups.spawn(p, { give: (e, { actor }) => e.ops.run('hp.heal', { n: 25 }, { actor }), name: 'Medkit', model: 'medkit', auto: true });
|
|
66
|
-
engine.events.on('pickup:take', ({ actor, x, z }) => engine.particles?.emit('dust', { x, y: engine.surface(x, z), z }, { count: 10 }));
|
|
65
|
+
engine.inventory.add('coin', 2); // the local bag; { ok: true, key: 'coin', added: 2 }, or { ok: false, code: 'full' } if none fit
|
|
66
|
+
engine.pickups.spawn([8, 0, 2], { give: 'ammo', count: 30, auto: true, radius: 1.2 }); // taken on touch by whoever touches it (pickups.takers), no key, no prompt
|
|
67
|
+
engine.pickups.spawn(p, { give: (e, { actor }) => e.ops.run('hp.heal', { n: 25 }, { actor }), name: 'Medkit', model: 'medkit', auto: true }); // instant effect, no inventory needed
|
|
68
|
+
engine.events.on('pickup:take', ({ actor, x, z }) => engine.particles?.emit('dust', { x, y: engine.surface(x, z), z }, { count: 10 })); // also item:add / item:remove (with container, actor) / item:use
|
|
67
69
|
```
|
|
68
70
|
The default reach is `pickups({ radius: 2 })`; each pickup can set its own `radius`. Reach is a sphere around the pickup, so a coin on a ledge less than `radius` above the player is taken from under it: give it a smaller `radius`. Taking one is the op `pickup.take { id }` (net: `'peer'`): the
|
|
69
71
|
interact key, auto pickups, a net client's press (sent to the host, which puts the item into that peer's bag) and tests all run it as `ctx.actor`.
|
|
@@ -77,15 +79,15 @@ also takes a key.
|
|
|
77
79
|
```js
|
|
78
80
|
const I = engine.inventory;
|
|
79
81
|
I.define('sword', { name: 'Sword', stack: 1 });
|
|
80
|
-
const { key } = I.add('sword', 1, { data: { durability: 80, level: 3 } });
|
|
82
|
+
const { key } = I.add('sword', 1, { data: { durability: 80, level: 3 } }); // 'sword#7' (add returns { ok: false, code: 'full' } when it does not fit)
|
|
81
83
|
// change it inside an op or fixed step (data objects are frozen: always pass a new one; the key stays the same)
|
|
82
84
|
const s = I.get(key); I.setData(key, { ...s.data, durability: s.data.durability - 1 });
|
|
83
85
|
I.container('chest-1', { capacity: 8 });
|
|
84
|
-
I.transfer('player', 'chest-1', key);
|
|
85
|
-
I.container('chest-1').remove(key);
|
|
86
|
+
I.transfer('player', 'chest-1', key); // exactly this sword; it keeps its data and key
|
|
87
|
+
I.container('chest-1').remove(key); // exactly this one; I.remove('sword') takes plain ones first, then the oldest
|
|
86
88
|
I.define('tomato', { name: 'Tomato' });
|
|
87
|
-
const t = I.add('tomato', 5, { data: { quality: 2 } });
|
|
88
|
-
I.setData(t.key, { quality: 1 }, 2);
|
|
89
|
+
const t = I.add('tomato', 5, { data: { quality: 2 } }); // stackable: equal data joins the same entry
|
|
90
|
+
I.setData(t.key, { quality: 1 }, 2); // only 2 of that stack change: they split off under a new key (returned)
|
|
89
91
|
```
|
|
90
92
|
Data and keys are saved with the container. Which piece a player means is chosen by key (a click on a row of `list()`), so ops take `item` as an id or a key.
|
|
91
93
|
|
|
@@ -96,18 +98,18 @@ Data and keys are saved with the container. Which piece a player means is chosen
|
|
|
96
98
|
## Using and dropping (ops)
|
|
97
99
|
```js
|
|
98
100
|
I.define('potion', { name: 'Potion', consume: true, use: (e, { actor, key, data }) => heal(actor, 30), canUse: (e, { actor }) => hp(actor) < 100 || 'full' });
|
|
99
|
-
engine.ops.run('inventory.use', { item: 'potion' });
|
|
100
|
-
engine.ops.run('inventory.drop', { item: 'sword#7' });
|
|
101
|
+
engine.ops.run('inventory.use', { item: 'potion' }); // runs canUse / use; consume removes one first; emits item:use
|
|
102
|
+
engine.ops.run('inventory.drop', { item: 'sword#7' }); // a pickup at the actor's feet, keeps its data
|
|
101
103
|
```
|
|
102
104
|
Both act on `ctx.actor`'s container (`'player'` by default).
|
|
103
105
|
|
|
104
106
|
**Replace an item when the bag is full**: `inventory.trade` takes A and gives B as one all-or-nothing step (it checks that B fits once A is gone), and
|
|
105
107
|
can be undone.
|
|
106
108
|
```js fragment
|
|
107
|
-
const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' });
|
|
108
|
-
if (!r.ok) say(r.code);
|
|
109
|
-
engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value);
|
|
110
|
-
engine.inventory.trade('rusty_key', 'gold_key');
|
|
109
|
+
const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); // also takeN / giveN; take may be an entry key ('sword#3')
|
|
110
|
+
if (!r.ok) say(r.code); // 'notEnough' (A missing) | 'full' (B does not fit even after A leaves)
|
|
111
|
+
engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value); // gives A back (with its data), takes B away
|
|
112
|
+
engine.inventory.trade('rusty_key', 'gold_key'); // the same from code; a container has .trade() too
|
|
111
113
|
```
|
|
112
114
|
**Why a pickup failed**: a pickup that does not fit fails `interaction.use` with code `full` (the item stays on the ground):
|
|
113
115
|
`const r = engine.ops.run('interaction.use'); if (!r.ok) say(r.code); // 'full'`.
|
|
@@ -119,22 +121,22 @@ is open; default `false` (the world keeps running behind the window). Switchable
|
|
|
119
121
|
The window is a UI part (recipe 26): the engine opens and closes it (the bound `inventory` key, Esc, input lock), the part only draws
|
|
120
122
|
`{ title, hint, items: list(), capacity, used, weight, maxWeight }`.
|
|
121
123
|
```js
|
|
122
|
-
engine.ui.set('inventory', false);
|
|
123
|
-
engine.ui.set('inventory', { drop: true });
|
|
124
|
-
engine.ui.set('inventory', (engine) => {
|
|
124
|
+
engine.ui.set('inventory', false); // no window at all (the key does nothing, no DOM)
|
|
125
|
+
engine.ui.set('inventory', { drop: true }); // default window plus a Drop button per row (Use appears for items with use)
|
|
126
|
+
engine.ui.set('inventory', (engine) => { // your own: grid, drag and drop, anything; buttons run ops with an entry's key
|
|
125
127
|
const el = document.createElement('div'); engine.uiRoot.appendChild(el);
|
|
126
128
|
el.onclick = ev => { const key = ev.target.dataset.key; if (key) engine.ops.run('inventory.use', { item: key }); };
|
|
127
129
|
const draw = d => { el.innerHTML = d.items.map(i => `<button data-key="${i.key}">${i.def.name} ×${i.count}</button>`).join(''); };
|
|
128
130
|
return { show: d => { el.hidden = false; draw(d); }, update: draw, hide: () => { el.hidden = true; }, dispose: () => el.remove() };
|
|
129
131
|
});
|
|
130
|
-
engine.ui.open('inventory'); engine.ui.close('inventory');
|
|
132
|
+
engine.ui.open('inventory'); engine.ui.close('inventory'); // open / close from code
|
|
131
133
|
```
|
|
132
134
|
The shape of an item on the ground is a model name from an asset pack, built through the same path as content props (recipe 05 §1): the item's `model`,
|
|
133
135
|
else a model named `pickup:<item id>`, else one named `pickup`, else a neutral gray box. A generator that returns bare geometry is drawn with
|
|
134
136
|
`engine.pickups.material` in the item's own `color`.
|
|
135
137
|
```js
|
|
136
|
-
engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 }));
|
|
137
|
-
engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 });
|
|
138
|
+
engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
|
|
139
|
+
engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
|
|
138
140
|
```
|
|
139
141
|
A pickup or item with its own `color`, and a vertex-colored geometry, draw with a copy of that material carrying the color. For one object of the game's own pass
|
|
140
142
|
`{ mesh }` (a three.js object cannot go into a save, so after loading it falls back to the item's model).
|
|
@@ -147,10 +149,10 @@ to get or create one (the same id returns the same one); it has the inventory's
|
|
|
147
149
|
```js
|
|
148
150
|
const I = engine.inventory;
|
|
149
151
|
const chest = I.container('chest-1', { capacity: 8 });
|
|
150
|
-
chest.add('bandage', 2);
|
|
151
|
-
I.transfer(chest, 'player', 'bandage', 1);
|
|
152
|
-
I.transfer('player', chest, 'coin', 5);
|
|
153
|
-
chest.on('remove', ({ id, count, actor }) => console.log(actor, 'took', id, count));
|
|
152
|
+
chest.add('bandage', 2); // { ok: false, code: 'full' } if none fit; if part fits, that part goes in and `added` says how many
|
|
153
|
+
I.transfer(chest, 'player', 'bandage', 1); // a container or a container id both work; returns how many were actually moved (fewer / 0 if the inventory is full)
|
|
154
|
+
I.transfer('player', chest, 'coin', 5); // shelves and money boxes work the same way
|
|
155
|
+
chest.on('remove', ({ id, count, actor }) => console.log(actor, 'took', id, count)); // every container emits item:add / item:remove with { container, actor, id, key, count, total }
|
|
154
156
|
```
|
|
155
157
|
- **Relation to world**: a container id can be a world record's id directly (for example `'prop:chest:3'`, a zombie's id). Containers do not depend on
|
|
156
158
|
models: a far-away chest has no model but its contents still exist; contents are saved (containers that hold something, and those that were given
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Adding quests (with HUD objective markers)
|
|
2
2
|
|
|
3
|
+
> **Covers:** quests as data or code, progress, objective markers.
|
|
4
|
+
> **Use when:** goals the player follows and checks off.
|
|
5
|
+
> **Shortest:** a quest entry in content data with `quests()` installed (§1).
|
|
6
|
+
> **Sections:** 1 Write data recommended) · 2 In code complex · 3 Verify · Reading and moving progress
|
|
7
|
+
|
|
3
8
|
Modules needed: `quests()` (quest log; the game binds its `quests` action: `presets.bindings.quests` is J / gamepad Select, `quests: []` for
|
|
4
9
|
none); objective markers need `hud()` (neither is in openWorld, add them yourself:
|
|
5
10
|
`engine.use(openWorld({ camera: 'follow', ...}), quests(), hud())`).
|
|
@@ -13,10 +18,10 @@ export default {
|
|
|
13
18
|
'restore-power': {
|
|
14
19
|
title: 'Restore power',
|
|
15
20
|
desc: 'The engineer needs three fuses to restart the relay.',
|
|
16
|
-
startOn: 'engine:ready',
|
|
21
|
+
startOn: 'engine:ready', // the event that starts it automatically (or use { startQuest: 'restore-power' } in a dialogue)
|
|
17
22
|
steps: [
|
|
18
|
-
{ id: 'talk', text: 'Talk to the engineer', done: { flag: 'metEngineer' }, target: { npc: 'engineer' } },
|
|
19
|
-
{ id: 'gather', text: 'Find 3 fuses', done: { has: { fuse: 3 } }, target: 'storage' },
|
|
23
|
+
{ id: 'talk', text: 'Talk to the engineer', done: { flag: 'metEngineer' }, target: { npc: 'engineer' } }, // the marker follows the NPC
|
|
24
|
+
{ id: 'gather', text: 'Find 3 fuses', done: { has: { fuse: 3 } }, target: 'storage' }, // a place name
|
|
20
25
|
{ id: 'return', text: 'Fit them at the relay', done: { flag: 'relayOn' }, target: { place: 'home', x: 0, z: 3 } },
|
|
21
26
|
],
|
|
22
27
|
reward: [{ take: { fuse: 3 } }, { give: { coin: 5 } }, { toast: 'Power restored!' }],
|
|
@@ -43,13 +48,13 @@ Not every quest is a straight line. A step can hold several goals done in any or
|
|
|
43
48
|
startOn: 'engine:ready',
|
|
44
49
|
steps: [
|
|
45
50
|
{ text: 'Reach the camp', done: { flag: 'atCamp' }, target: 'camp' },
|
|
46
|
-
{ all: [
|
|
51
|
+
{ all: [ // text defaults to the required goals: "Hold the north gate / Hold the south gate"
|
|
47
52
|
{ text: 'Hold the north gate', done: { counter: { northWaves: 3 } }, target: 'northGate' },
|
|
48
53
|
{ text: 'Hold the south gate', done: { counter: { southWaves: 3 } }, target: 'southGate' },
|
|
49
|
-
{ text: 'No ally hurt', done: { notFlag: 'allyHurt' }, optional: true },
|
|
54
|
+
{ text: 'No ally hurt', done: { notFlag: 'allyHurt' }, optional: true }, // a bonus: never blocks, shown done if met in time
|
|
50
55
|
] },
|
|
51
56
|
],
|
|
52
|
-
fail: { flag: 'campBurned' },
|
|
57
|
+
fail: { flag: 'campBurned' }, // checked while the quest is active
|
|
53
58
|
onFail: [{ toast: 'The camp has fallen' }, { setFlag: 'mayRetryCamp' }],
|
|
54
59
|
reward: { give: { coin: 20 } },
|
|
55
60
|
},
|
|
@@ -62,18 +67,18 @@ Not every quest is a straight line. A step can hold several goals done in any or
|
|
|
62
67
|
```js
|
|
63
68
|
engine.quests.define('slimes3', {
|
|
64
69
|
title: 'Clear the cellar',
|
|
65
|
-
steps: [{ text: 'Defeat 3 slimes', done: e => e.vars.counter('slimes') >= 3, target: () => engine.npcs.get('engineer')?.position }],
|
|
70
|
+
steps: [{ text: 'Defeat 3 slimes', done: e => e.vars.counter('slimes') >= 3, target: () => engine.npcs.get('engineer')?.position }], // the function returns a position every frame: when the NPC is far away and has no model, root is null, so read position from the data
|
|
66
71
|
reward: e => e.inventory.add('coin', 3),
|
|
67
72
|
});
|
|
68
73
|
engine.quests.start('slimes3');
|
|
69
|
-
engine.vars.bump('slimes');
|
|
70
|
-
engine.events.on('quest:done', ({ id }) => { /* quest completed */ });
|
|
74
|
+
engine.vars.bump('slimes'); // each time one is defeated
|
|
75
|
+
engine.events.on('quest:done', ({ id }) => { /* quest completed */ }); // there are also quest:start, quest:step, quest:part and quest:fail
|
|
71
76
|
```
|
|
72
77
|
A failed reward (full bag, refused `{ op }`, a function returning `{ ok: false, code }`) still finishes the quest and fires `quest:unpaid`. Items that did not fit stay owed (`quests.list()`, saved) until there is room, unless the game decides itself with `onUnpaid` (effect words, or `(e, answer) => ...`).
|
|
73
78
|
|
|
74
79
|
To turn off automatic markers: `hud({ questMarkers: false })`. To add a marker by hand: `const m = engine.hud.marker('gate', { label: 'Gate' }); m.remove();`;
|
|
75
80
|
content effects can add them too: `{ marker: 'gate' }` / `{ clearMarker: 'gate' }`. A counter in the screen corner:
|
|
76
|
-
`engine.hud.
|
|
81
|
+
`engine.hud.addCounter('slimes', { label: 'Slimes', value: 2, max: 3 })`; `anchor: 'top-right'` (or `top`, `bottom`, `bottom-left`...) puts a counter
|
|
77
82
|
or bar in that screen column.
|
|
78
83
|
|
|
79
84
|
## 3. Verify
|