threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
package/types/gameplay.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
// Gameplay modules: timeline, level, triggers,
|
|
1
|
+
// Gameplay modules: timeline, level, triggers, world changes, particles, settings, music, characters/NPCs, interactions, dialogue, inventory,
|
|
2
2
|
// quests, photo mode, ambience, debug.
|
|
3
3
|
import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike } from './common';
|
|
4
4
|
import type { Engine } from './core';
|
|
5
5
|
import type { Input } from './generated/core/Input';
|
|
6
|
-
import type { Animator, AnimatorOptions,
|
|
6
|
+
import type { Animator, AnimatorOptions, Rideable } from './physics';
|
|
7
7
|
import type { WorldRecord } from './generated/modules/world/World';
|
|
8
8
|
|
|
9
9
|
// ======================================================================
|
|
10
10
|
// Timeline timeline()
|
|
11
11
|
// ======================================================================
|
|
12
12
|
|
|
13
|
-
/** Promise of a tween: await it to wait for the end; finish() jumps to the end now,
|
|
13
|
+
/** Promise of a tween: await it to wait for the end; finish() jumps to the end now, remove() stops at the current position */
|
|
14
14
|
export interface TweenPromise extends Promise<boolean> {
|
|
15
15
|
finish(): void;
|
|
16
|
-
|
|
16
|
+
remove(): void;
|
|
17
17
|
task: any;
|
|
18
18
|
}
|
|
19
19
|
/** Tween target: 'dotted.path' -> target value. E.g. { 'position.y': 3, 'material.color': 0xffffff, scale: [2, 2, 2] }; a value can also be () => value */
|
|
@@ -60,20 +60,19 @@ export interface TimelinePlayOptions {
|
|
|
60
60
|
skippable?: boolean;
|
|
61
61
|
/** Letterbox bars, default false */
|
|
62
62
|
letterbox?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The characters the cutscene drives (their control slot on layer 'cutscene'; keys / walks / NPC behaviours pause and come back after).
|
|
65
|
+
* Default: [engine.player] when there is a player; [] drives nobody (a bubble scene the player walks through). A path step adds its character
|
|
66
|
+
*/
|
|
67
|
+
actors?: any[];
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
// Timeline (engine.timeline) is generated from the JSDoc in modules/timeline/Timeline.js (npm run map); only the type is re-exported here
|
|
68
71
|
import type { Timeline } from './generated/modules/timeline/Timeline';
|
|
69
72
|
export type { Timeline };
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* do not advance while frozen)
|
|
74
|
-
*/
|
|
75
|
-
skipKeys?: string[];
|
|
76
|
-
}
|
|
73
|
+
/** timeline() takes no options: the basic cancel key skips (the UI focus stack hands it to the topmost cutscene); bind the action 'skip'
|
|
74
|
+
* (context 'cutscene') for another key, e.g. createEngine({ bindings: { ...presets.bindings.cutsceneSkip } }) */
|
|
75
|
+
export interface TimelineOptions {}
|
|
77
76
|
|
|
78
77
|
// ======================================================================
|
|
79
78
|
// Level level()
|
|
@@ -121,8 +120,6 @@ export interface Level {
|
|
|
121
120
|
spawn: Vector3;
|
|
122
121
|
/** Heightfield (for debugging) */
|
|
123
122
|
heightfield: any;
|
|
124
|
-
/** Milliseconds spent building the heightfield */
|
|
125
|
-
buildMs?: number;
|
|
126
123
|
/** Whether loading is finished */
|
|
127
124
|
readonly ready: boolean;
|
|
128
125
|
/** Get a marker, null if none */
|
|
@@ -162,20 +159,26 @@ export interface TriggerOptions {
|
|
|
162
159
|
height?: number;
|
|
163
160
|
/** Box rotation around the Y axis (radians) */
|
|
164
161
|
rotation?: number;
|
|
165
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Called on entering; who is the position that entered, id the world record id of who it is (engine.actor for the default who, an id given in who,
|
|
164
|
+
* object.userData.id, null for a bare position)
|
|
165
|
+
*/
|
|
166
|
+
onEnter?: ((t: Trigger, who: Vector3, id: string | null) => void) | null;
|
|
167
|
+
/** Called on leaving; id = who was inside */
|
|
168
|
+
onExit?: ((t: Trigger, who: Vector3 | null, id: string | null) => void) | null;
|
|
169
169
|
/** Called every fixed step while inside (dt in seconds) */
|
|
170
|
-
onStay?: ((dt: number, t: Trigger, who: Vector3) => void) | null;
|
|
170
|
+
onStay?: ((dt: number, t: Trigger, who: Vector3, id: string | null) => void) | null;
|
|
171
171
|
/** Fire on the first enter only (exit follows at once); the zone stays with used = true, and a new playthrough (engine.session) re-arms it */
|
|
172
172
|
once?: boolean;
|
|
173
173
|
/** false pauses detection */
|
|
174
174
|
enabled?: boolean;
|
|
175
175
|
/** Name (carried in events) */
|
|
176
176
|
tag?: string;
|
|
177
|
-
/**
|
|
178
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Who can trigger it: engine.actor by default; or an actor id, a position, an object (its position is used), or a function returning an array of those
|
|
179
|
+
* (several actors: () => [e.actor, ...e.net.peers.map(p => p.actor)])
|
|
180
|
+
*/
|
|
181
|
+
who?: string | Vector3 | Object3D | { x: number; y: number; z: number } | (() => Array<string | Object3D | { x: number; y: number; z: number }>) | null;
|
|
179
182
|
/** Seconds after leaving during which entering does not fire again, default 0 */
|
|
180
183
|
cooldown?: number;
|
|
181
184
|
/** Custom data */
|
|
@@ -205,22 +208,17 @@ export interface Trigger {
|
|
|
205
208
|
/** Whether a point is inside */
|
|
206
209
|
contains(p: { x: number; y: number; z: number }): boolean;
|
|
207
210
|
}
|
|
208
|
-
|
|
211
|
+
/** id = world record id of who entered / left (null for a bare position) */
|
|
212
|
+
export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null; id: string | null }
|
|
209
213
|
export interface TriggersOptions {
|
|
210
|
-
/**
|
|
211
|
-
debug?: boolean;
|
|
212
|
-
/** Action name that toggles the wireframes, default 'triggersDebug' */
|
|
214
|
+
/** Action name that toggles the debug view 'triggers' (engine.debug.view), default 'triggersDebug' */
|
|
213
215
|
action?: string;
|
|
214
|
-
/** Key that toggles the wireframes: default ['F4'] in dev builds, none in release builds */
|
|
215
|
-
keys?: string[];
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/** engine.triggers */
|
|
219
219
|
export interface Triggers {
|
|
220
220
|
/** All trigger zones (a new array) */
|
|
221
221
|
list(): Trigger[];
|
|
222
|
-
/** Whether wireframes are shown */
|
|
223
|
-
debug: boolean;
|
|
224
222
|
action: string;
|
|
225
223
|
/** Add a trigger zone */
|
|
226
224
|
add(opts?: TriggerOptions): Trigger;
|
|
@@ -230,129 +228,13 @@ export interface Triggers {
|
|
|
230
228
|
byTag(tag: string): Trigger[];
|
|
231
229
|
/** Every trigger_xxx marker in the level becomes a trigger zone with tag xxx; opts is shared by all of them */
|
|
232
230
|
fromMarkers(opts?: TriggerOptions): Trigger[];
|
|
233
|
-
/** Show / hide the wireframes */
|
|
234
|
-
setDebug(on: boolean): void;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// ======================================================================
|
|
238
|
-
// Entities entities()
|
|
239
|
-
// ======================================================================
|
|
240
|
-
|
|
241
|
-
/** Growth stage */
|
|
242
|
-
export interface EntityStage {
|
|
243
|
-
/** Stage name, e.g. 'seed' */
|
|
244
|
-
name: string;
|
|
245
|
-
/** How many game seconds to stay in this stage (leave out on the last one = stay here forever) */
|
|
246
|
-
duration?: number;
|
|
247
|
-
/** Model size multiplier */
|
|
248
|
-
scale?: number;
|
|
249
|
-
/** Swap the model */
|
|
250
|
-
model?: (engine: Engine, ent: Entity) => Object3D;
|
|
251
|
-
}
|
|
252
|
-
/** Entity interaction settings (needs the interactions module) */
|
|
253
|
-
export interface EntityInteract {
|
|
254
|
-
/** Prompt text: an i18n key, plain text, or a function ent => text */
|
|
255
|
-
label?: string | ((ent: Entity, engine: Engine) => string);
|
|
256
|
-
/** Interaction action name, default 'interact' */
|
|
257
|
-
action?: string;
|
|
258
|
-
/** How close you must be to interact (meters), default 2.5 */
|
|
259
|
-
radius?: number;
|
|
260
|
-
/** How high the prompt floats (meters) */
|
|
261
|
-
height?: number;
|
|
262
|
-
/** Whether it can be interacted with */
|
|
263
|
-
enabled?: (ent: Entity, engine: Engine) => boolean;
|
|
264
|
-
/** When the interact key is pressed */
|
|
265
|
-
onUse?: (ent: Entity, engine: Engine) => void;
|
|
266
|
-
}
|
|
267
|
-
/** Entity type definition: engine.entities.define('sapling', {...}) */
|
|
268
|
-
export interface EntityDef<S = Record<string, any>> {
|
|
269
|
-
/** Create the model (required), returns a THREE.Object3D */
|
|
270
|
-
create: (engine: Engine, ent: Entity<S>) => Object3D;
|
|
271
|
-
/** Default state (merged with the state given at spawn) */
|
|
272
|
-
state?: S;
|
|
273
|
-
/** Growth stages */
|
|
274
|
-
stages?: EntityStage[];
|
|
275
|
-
/** Growth stops when this returns false */
|
|
276
|
-
canGrow?: (ent: Entity<S>, engine: Engine) => boolean;
|
|
277
|
-
/** Called every fixed step (dt in seconds); runs only near the player, far away only growth is caught up */
|
|
278
|
-
update?: (dt: number, ent: Entity<S>, engine: Engine) => void;
|
|
279
|
-
/** Interaction */
|
|
280
|
-
interact?: EntityInteract;
|
|
281
|
-
/** Circular collision radius (meters, needs the collision module; follows the model, exists only near the player) */
|
|
282
|
-
collider?: number;
|
|
283
|
-
/** Collision height (meters), default 3 */
|
|
284
|
-
colliderHeight?: number;
|
|
285
|
-
/** Cleanup when the model is torn down (called both when walking away and on deletion; don't clear data while the data still exists) */
|
|
286
|
-
dispose?: (ent: Entity<S>, engine: Engine) => void;
|
|
287
|
-
/** false = not saved (temporary things, cleared on load), default true */
|
|
288
|
-
save?: boolean;
|
|
289
|
-
}
|
|
290
|
-
/** Parameters of spawn() */
|
|
291
|
-
export interface EntitySpawnData {
|
|
292
|
-
/** Specify the id (generated automatically if omitted) */
|
|
293
|
-
id?: string;
|
|
294
|
-
/** Position: Vector3 / object / [x, y, z] / { x, z } ({ x, z } without y snaps to the ground), default origin */
|
|
295
|
-
position?: PositionLike;
|
|
296
|
-
/** Heading (radians) */
|
|
297
|
-
rotation?: number;
|
|
298
|
-
/** Initial state (merged onto the default state) */
|
|
299
|
-
state?: Record<string, any>;
|
|
300
|
-
/** Extra data (ent.data, saved) */
|
|
301
|
-
extra?: Record<string, any>;
|
|
302
|
-
}
|
|
303
|
-
/** An entity: x / y / z / rotation / state / data read engine.world data directly (kind is 'entity:<type>'); object / visual exist only near the player */
|
|
304
|
-
export interface Entity<S = Record<string, any>> {
|
|
305
|
-
id: string;
|
|
306
|
-
type: string;
|
|
307
|
-
def: EntityDef<S>;
|
|
308
|
-
/** Position (meters) */
|
|
309
|
-
readonly x: number; readonly z: number; readonly y: number;
|
|
310
|
-
readonly rotation: number;
|
|
311
|
-
/** State (stage is the current stage index, stageAt the time it was entered); change values with ent.set() so that events fire */
|
|
312
|
-
state: S & { stage?: number; stageAt?: number };
|
|
313
|
-
/** Root node (heading and interactions hang on it); null when there is no model far away, built the frame after spawn */
|
|
314
|
-
readonly object: Object3D | null;
|
|
315
|
-
/** Model (a child of the root node) */
|
|
316
|
-
readonly visual: Object3D | null;
|
|
317
|
-
/** Extra data */
|
|
318
|
-
readonly data: Record<string, any>;
|
|
319
|
-
/** Change one state value (emits the entity:state event) */
|
|
320
|
-
set(key: string, value: any): void;
|
|
321
|
-
/** Delete this entity */
|
|
322
|
-
remove(): boolean;
|
|
323
|
-
/** Current stage name */
|
|
324
|
-
readonly stageName: string | null;
|
|
325
|
-
}
|
|
326
|
-
export interface EntityStateEvent { ent: Entity; key: string; value: any; prev: any }
|
|
327
|
-
export interface EntityStageEvent { ent: Entity; stage: number; name: string }
|
|
328
|
-
|
|
329
|
-
/** engine.entities */
|
|
330
|
-
export interface Entities {
|
|
331
|
-
/** Type definitions */
|
|
332
|
-
types: Map<string, EntityDef>;
|
|
333
|
-
/** Game seconds (= engine.clock.now) */
|
|
334
|
-
readonly now: number;
|
|
335
|
-
/** Define an entity type */
|
|
336
|
-
define<S = Record<string, any>>(type: string, def: EntityDef<S>): this;
|
|
337
|
-
/** Spawn an entity (returns null if the type is not defined) */
|
|
338
|
-
spawn(type: string, data?: EntitySpawnData): Entity | null;
|
|
339
|
-
get(id: string): Entity | null;
|
|
340
|
-
byType(type: string): Entity[];
|
|
341
|
-
list(): Entity[];
|
|
342
|
-
/** The entity nearest to position within radius meters (default 3) (type restricts to one type) */
|
|
343
|
-
nearest(position: PositionLike, opts?: { radius?: number; type?: string | null }): Entity | null;
|
|
344
|
-
remove(id: string): boolean;
|
|
345
|
-
/** Delete all entities */
|
|
346
|
-
clear(): void;
|
|
347
|
-
/** Jump straight to a growth stage */
|
|
348
|
-
setStage(ent: Entity, i: number): void;
|
|
349
231
|
}
|
|
350
232
|
|
|
351
233
|
// ======================================================================
|
|
352
234
|
// Particles particles()
|
|
353
235
|
// ======================================================================
|
|
354
236
|
|
|
355
|
-
/** Particle effect parameters (style.particles[name] of the style
|
|
237
|
+
/** Particle effect parameters (style.particles[name] of the style uses the same format too). All optional */
|
|
356
238
|
export interface ParticleOptions {
|
|
357
239
|
/** Maximum alive at once, default 120 (halved on low-end devices) */
|
|
358
240
|
max?: number;
|
|
@@ -450,10 +332,8 @@ export interface SettingsSection {
|
|
|
450
332
|
order?: number;
|
|
451
333
|
}
|
|
452
334
|
export interface SettingsOptions {
|
|
453
|
-
/** Action
|
|
335
|
+
/** Action that opens the menu, default the basic 'cancel' (Esc / pad B on an empty UI focus stack); another name is declared and the game binds it */
|
|
454
336
|
action?: string;
|
|
455
|
-
/** Key that opens the menu, default ['Escape'] */
|
|
456
|
-
keys?: string[];
|
|
457
337
|
/** Browser storage key */
|
|
458
338
|
storageKey?: string;
|
|
459
339
|
/** Override the graphics presets: { low: {...}, medium: {...}, high: {...} } */
|
|
@@ -489,8 +369,10 @@ export interface Settings {
|
|
|
489
369
|
set(key: string, value: any, opts?: { save?: boolean }): void;
|
|
490
370
|
/** Graphics preset: 'low' | 'medium' | 'high' */
|
|
491
371
|
preset(name: 'low' | 'medium' | 'high' | (string & {})): void;
|
|
492
|
-
/** Game-defined setting: default value + apply function (saved automatically)
|
|
493
|
-
|
|
372
|
+
/** Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row
|
|
373
|
+
* 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),
|
|
374
|
+
* 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 */
|
|
375
|
+
define<T = any>(key: string, def: T, apply?: ((value: T, e: Engine) => void) | { apply?: (value: T, e: Engine) => void; limits?: string | string[] }): this;
|
|
494
376
|
/** Add a tab of your own, or a built-in / optional one by name: addSection('camera') */
|
|
495
377
|
addSection(id: string, section?: SettingsSection): this;
|
|
496
378
|
removeSection(id: string): void;
|
|
@@ -545,18 +427,25 @@ export type { Music };
|
|
|
545
427
|
// Characters characters() -> engine.characters, engine.npcs
|
|
546
428
|
// ======================================================================
|
|
547
429
|
|
|
548
|
-
/**
|
|
430
|
+
/**
|
|
431
|
+
* A ready procedural body ({ rig }): root is the root node, body/head optional, limbs are the swinging limbs. A model asset carries the same shape
|
|
432
|
+
* by object name in root.userData.rig ({ body: 'hips', head: 'head', joints: ['armL'], limbs: [{ joint: 'legL', ... }] }), as an asset pack's humanoid does
|
|
433
|
+
*/
|
|
549
434
|
export interface CharacterRig {
|
|
550
435
|
root: Object3D;
|
|
551
436
|
body?: Object3D;
|
|
552
437
|
head?: Object3D;
|
|
553
|
-
/** Named joints, exposed on the character as properties (
|
|
438
|
+
/** Named joints, exposed on the character as properties (a humanoid rig: armL armR legL legR) */
|
|
554
439
|
joints?: Record<string, Object3D>;
|
|
555
440
|
limbs?: { joint: Object3D; offset: number; amp: number; kind: 'arm' | 'leg'; side?: number }[];
|
|
556
441
|
}
|
|
442
|
+
export type CharacterWater = 'swim' | 'block' | 'wade' | ((character: Character, at: { depth: number; x: number; z: number }) => 'swim' | 'block' | 'wade');
|
|
443
|
+
/** What the states hook sees: base is the state the mover chose (idle / walk / run / jump / fall / swim); water the water mode it is in (null on land) */
|
|
444
|
+
export interface CharacterFacts { base: string; speed: number; grounded: boolean; swimming: boolean; vy: number; water: 'swim' | 'block' | 'wade' | null }
|
|
445
|
+
export type CharacterStates = (character: Character, facts: CharacterFacts) => string | null | undefined;
|
|
557
446
|
/** Character parameters (shared by the player and NPCs) */
|
|
558
447
|
export interface CharacterOptions {
|
|
559
|
-
/**
|
|
448
|
+
/** Per-character part colors: recolor the body's meshes marked userData.part (a humanoid rig: body, skin, legs, hair); the style tints by material role */
|
|
560
449
|
colors?: { body?: ColorLike; skin?: ColorLike; legs?: ColorLike; hair?: ColorLike };
|
|
561
450
|
/** Walking speed (m/s), default 4.5 */
|
|
562
451
|
speed?: number;
|
|
@@ -564,9 +453,18 @@ export interface CharacterOptions {
|
|
|
564
453
|
runSpeed?: number;
|
|
565
454
|
/** Collision radius (meters), default 0.4 */
|
|
566
455
|
radius?: number;
|
|
567
|
-
/**
|
|
568
|
-
|
|
569
|
-
|
|
456
|
+
/**
|
|
457
|
+
* What water deeper than swimDepth does: 'swim' (default: floats, state 'swim') | 'block' (never enters it) | 'wade' (walks the bottom) | a function
|
|
458
|
+
* deciding per spot (a swim skill, a boat, depth). character:water fires on each change
|
|
459
|
+
*/
|
|
460
|
+
water?: CharacterWater;
|
|
461
|
+
/**
|
|
462
|
+
* The game's own states on top of the built-in ones (crouch, climb, glide, dash, roll): run after the mover's state each step, return a state name
|
|
463
|
+
* or null to keep facts.base. The state picks the clip like any other (clips: { crouch: 'Crouch' }); speed changes stay engine.mod('move.speed')
|
|
464
|
+
* @example createPlayer({ ..., clips: { crouch: 'Crouch' }, states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : null })
|
|
465
|
+
*/
|
|
466
|
+
states?: CharacterStates | null;
|
|
467
|
+
/** Water depth (meters) at which water counts as deep, default 1 */
|
|
570
468
|
swimDepth?: number;
|
|
571
469
|
/** Swimming speed multiplier, default 0.45 */
|
|
572
470
|
swimSpeed?: number;
|
|
@@ -584,21 +482,36 @@ export interface CharacterOptions {
|
|
|
584
482
|
airControl?: number;
|
|
585
483
|
/** How long after walking off an edge a jump is still allowed (seconds) */
|
|
586
484
|
coyoteTime?: number;
|
|
587
|
-
/** Whether it can jump, default true */
|
|
485
|
+
/** Whether it can jump, default true (stuns and cutscenes use engine.mod('move.canJump', { owner, id, set: 0 }) instead of writing it) */
|
|
588
486
|
canJump?: boolean;
|
|
487
|
+
/** Jumps before landing again, default 1; 2 = double jump (jump() again in the air) */
|
|
488
|
+
maxJumps?: number;
|
|
489
|
+
/** Takeoff speed of an air jump (m/s), default jumpSpeed */
|
|
490
|
+
airJumpSpeed?: number;
|
|
491
|
+
/** How long a jump() pressed early waits for the ground (seconds), default 0.12 */
|
|
492
|
+
jumpBuffer?: number;
|
|
493
|
+
/** Falling out of the level: below belowY (or when belowY(character) is true) character:fall fires and, unless a listener calls preventDefault(), it returns to safeGround. false (default) = off */
|
|
494
|
+
fall?: false | { belowY: number | ((character: Character) => boolean) };
|
|
495
|
+
/** Time channel its movement and animation follow when the engine drives it (player default 'player', others 'world') */
|
|
496
|
+
channel?: string;
|
|
589
497
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* event 'character:model')
|
|
498
|
+
* The body, one path for every kind: the name of a registered model asset, or what engine.assets.model() returned. A procedural builder name
|
|
499
|
+
* (from an asset pack) is built at once; a file model name shows a gray capsule and swaps in a copy when it loads (Character.ready / whenReady,
|
|
500
|
+
* event 'character:model'). Without model and rig: a gray capsule placeholder (warned once)
|
|
501
|
+
* @example engine.assets.manifest(yourAssets); engine.characters.createPlayer({ model: 'yourBody' }) // a generator or GLB name from an asset pack
|
|
593
502
|
* @example engine.characters.createPlayer({ model: 'hero' }) // after engine.assets.manifest({ models: { hero: '/models/hero.glb' } })
|
|
594
503
|
*/
|
|
595
504
|
model?: Object3D | string | null;
|
|
505
|
+
/** A ready procedural body (CharacterRig), used instead of model (a hand-built guard / pet) */
|
|
506
|
+
rig?: CharacterRig | null;
|
|
507
|
+
/** Id for engine.mod / time.local entries of a character without a world record (read it back as character.id); the player is 'player', an NPC its record id */
|
|
508
|
+
id?: string;
|
|
596
509
|
/** Action name mapping { idle, walk, run, swim, jump, fall } (shorthand for animation) */
|
|
597
510
|
clips?: { idle?: string; walk?: string; run?: string; swim?: string; jump?: string; fall?: string; drive?: string } | null;
|
|
598
511
|
/** Skeletal animation state machine config (states, blend trees, one-shot actions), see AnimatorOptions */
|
|
599
512
|
animation?: AnimatorOptions | null;
|
|
600
|
-
/** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) */
|
|
601
|
-
mover?: 'simple' | 'rapier';
|
|
513
|
+
/** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) | 'manual' the game writes the position, move() only updates grounded / support / safeGround / fall */
|
|
514
|
+
mover?: 'simple' | 'rapier' | 'manual';
|
|
602
515
|
/**
|
|
603
516
|
* Which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward()) | 'target' (toward faceTarget) | 'manual'
|
|
604
517
|
* (only face() turns it)
|
|
@@ -609,50 +522,45 @@ export interface CharacterOptions {
|
|
|
609
522
|
}
|
|
610
523
|
/** Character facing mode, see CharacterOptions.faceMode */
|
|
611
524
|
export type FaceMode = 'move' | 'camera' | 'target' | 'manual';
|
|
612
|
-
/** What a player control function returns: world direction (length 0–1), run
|
|
613
|
-
export type MoveRequest = { x: number; z: number; run?: boolean
|
|
525
|
+
/** What a player control function returns: world direction (length 0–1 scales the speed), run; null = stand still. Speed changes: engine.mod('move.speed', { owner, id: 'player', ... }) */
|
|
526
|
+
export type MoveRequest = { x: number; z: number; run?: boolean } | null | undefined;
|
|
614
527
|
/**
|
|
615
|
-
*
|
|
616
|
-
* the move request
|
|
528
|
+
* How the player's input steers it (the base holder of its control slot, owner 'player-input'): 'camera' movement keys relative to the camera |
|
|
529
|
+
* a function returning the move request. The game moving the player itself takes control: engine.control.take(player, { owner, layer: 'script', step })
|
|
617
530
|
*/
|
|
618
|
-
export type PlayerControl = 'camera' |
|
|
531
|
+
export type PlayerControl = 'camera' | ((player: Character, input: Input, dt: number) => MoveRequest);
|
|
619
532
|
/** Parameters of createPlayer() */
|
|
620
533
|
export interface PlayerOptions extends CharacterOptions {
|
|
621
534
|
/** Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted */
|
|
622
535
|
spawn?: PositionLike;
|
|
623
|
-
/** Keys of the 'jump' action; none bound when omitted (player.jump() still works). presets.player.* use ['Space', 'PadA'] */
|
|
624
|
-
jumpKeys?: string[];
|
|
625
|
-
/** Keys of the 'run' action read by control 'camera' / moveInput(); none bound when omitted. presets.player.* use Shift / gamepad LB */
|
|
626
|
-
runKeys?: string[];
|
|
627
536
|
/**
|
|
628
|
-
* Required, no default: 'camera' (keys relative to the camera) |
|
|
629
|
-
*
|
|
537
|
+
* Required, no default: 'camera' (keys relative to the camera) | (player, input, dt) => ({ x, z, run? }) (null stands still). presets.player.*
|
|
538
|
+
* fill it. Given once: a game that steers the player for a while takes control (engine.control.take(player, { owner, layer: 'script', step }))
|
|
630
539
|
*/
|
|
631
540
|
control: PlayerControl;
|
|
632
541
|
/** true: the camera module follows the player (and back after a vehicle, and on a new session). Omitted with a camera installed warns in dev */
|
|
633
542
|
cameraFollow?: boolean;
|
|
634
543
|
}
|
|
635
|
-
/** Character state */
|
|
636
|
-
export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive';
|
|
544
|
+
/** Character state: the engine's own, or any name the game's `states` hook returns (crouch, climb, sit...) */
|
|
545
|
+
export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive' | (string & {});
|
|
637
546
|
|
|
638
547
|
/** Character (player and NPCs) */
|
|
639
548
|
export declare class Character {
|
|
640
549
|
constructor(engine: Engine, opts?: CharacterOptions);
|
|
641
|
-
engine: Engine;
|
|
642
550
|
/** Root node (this is what gets added to the scene) */
|
|
643
551
|
root: Object3D;
|
|
644
552
|
/** Same as root: add children, change visible and scale on it */
|
|
645
553
|
readonly object: Object3D;
|
|
646
554
|
/** Position (= root.position) */
|
|
647
555
|
readonly position: Vector3;
|
|
648
|
-
/** Horizontal velocity (x, y map to world x, z) */
|
|
556
|
+
/** Horizontal velocity (x, y map to world x, z). Writable: a write is an impulse the mover steers back toward the input (lasting knockback: push(); full control: mover 'manual') */
|
|
649
557
|
velocity: Vector2;
|
|
650
558
|
/**
|
|
651
559
|
* Heading (radians): 0 faces +Z, forward = (sin facing, cos facing); increasing turns toward +X (rotation about the Y axis, consistent with
|
|
652
560
|
* root.rotation.y)
|
|
653
561
|
*/
|
|
654
562
|
facing: number;
|
|
655
|
-
/** Vertical velocity (m/s) */
|
|
563
|
+
/** Vertical velocity (m/s). Writable: setting it is an impulse (launch() does the same and also leaves the ground cleanly) */
|
|
656
564
|
vy: number;
|
|
657
565
|
/** Whether standing on the ground */
|
|
658
566
|
grounded: boolean;
|
|
@@ -666,20 +574,47 @@ export declare class Character {
|
|
|
666
574
|
faceMode: FaceMode;
|
|
667
575
|
/** What faceMode 'target' faces */
|
|
668
576
|
faceTarget: PositionLike | null;
|
|
669
|
-
/** Player only: who moves it each fixed step (see PlayerOptions.control) */
|
|
670
|
-
control?: PlayerControl;
|
|
671
577
|
/** Player only: whether the camera module follows it (see PlayerOptions.cameraFollow) */
|
|
672
578
|
cameraFollow?: boolean;
|
|
673
579
|
/** Move at a fixed velocity (m/s) for seconds, ignoring move()'s direction and without turning (knockback, dodge roll); gravity and collision still apply */
|
|
674
580
|
push(vx: number, vz: number, seconds: number): void;
|
|
675
|
-
speed: number; runSpeed: number; radius: number;
|
|
581
|
+
speed: number; runSpeed: number; radius: number; water: CharacterWater; states: CharacterStates | null; swimDepth: number; swimSpeedFactor: number;
|
|
676
582
|
turnSpeed: number; acceleration: number; gravity: number; jumpSpeed: number; stepHeight: number; airControl: number; coyoteTime: number; canJump: boolean;
|
|
583
|
+
/** Base jump values (the game's; modifiers go through engine.mod('move.jumpSpeed')) */
|
|
584
|
+
maxJumps: number; airJumpSpeed: number | null; jumpBuffer: number;
|
|
585
|
+
/** Fall check (see CharacterOptions.fall); a plain property */
|
|
586
|
+
fall: false | { belowY: number | ((character: Character) => boolean) };
|
|
587
|
+
/** Time channel the engine drives it on (see CharacterOptions.channel) */
|
|
588
|
+
channel: string;
|
|
589
|
+
/** The character's id, the one form engine.mod / time.local take: its world record id ('player', an NPC's record id), else the id option, else a generated one */
|
|
590
|
+
readonly id: string;
|
|
591
|
+
/**
|
|
592
|
+
* A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (canJump reads 1 / 0)
|
|
593
|
+
* @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); player.stat('speed') // 1.2 x player.speed
|
|
594
|
+
*/
|
|
595
|
+
stat(name: 'speed' | 'runSpeed' | 'gravity' | 'jumpSpeed' | 'canJump'): number;
|
|
596
|
+
/** Give back n jumps for this airtime (pickup, wall touch) */
|
|
597
|
+
addJumps(n?: number): this;
|
|
598
|
+
/** All jumps back, as if it had landed */
|
|
599
|
+
resetJumps(): this;
|
|
600
|
+
/**
|
|
601
|
+
* Throw it upward at speed m/s (jump pad, spring): leaves the ground, ends coyote time, the ground jump counts as used (air jumps stay); emits character:launch
|
|
602
|
+
* @example player.launch(19, { owner: 'pad' })
|
|
603
|
+
*/
|
|
604
|
+
launch(speed: number, opts?: { owner?: string }): this;
|
|
605
|
+
/** Jump state now, read-only */
|
|
606
|
+
jumpState(): { grounded: boolean; coyoteLeft: number; bufferLeft: number; jumpsUsed: number; jumpsLeft: number; vy: number };
|
|
607
|
+
/** What it stands on, read-only (reused object); 'platform' = a registered support (characters.support), which carries it */
|
|
608
|
+
readonly support: { kind: 'ground' | 'platform' | 'collider' | 'water' | null; object: any; id: string | null; safe: boolean; velocity: { x: number; y: number; z: number } };
|
|
609
|
+
/** Last spot it stood still on safe ground (where a fall returns it); null until it first stands. Saved with the motion */
|
|
610
|
+
safeGround: Vector3 | null;
|
|
677
611
|
/** Called when a foot lands (the argument is the ground type underfoot) */
|
|
678
612
|
onStep: ((groundType: string) => void) | null;
|
|
679
613
|
/** Called on landing (the argument is the landing speed) */
|
|
680
614
|
onLand: ((impact: number) => void) | null;
|
|
681
|
-
/**
|
|
682
|
-
mover: { name: 'simple' | 'rapier'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number
|
|
615
|
+
/** How it walks now; name is 'simple' | 'rapier' | 'manual', controller is the native Rapier character controller (when rapier). Assign a name to switch: c.mover = 'manual' */
|
|
616
|
+
get mover(): { name: 'simple' | 'rapier' | 'manual'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number): void; dispose?(): void };
|
|
617
|
+
set mover(name: 'simple' | 'rapier' | 'manual');
|
|
683
618
|
/** Skeletal animation state machine (when there is a glTF model; null while a model named by asset is still loading) */
|
|
684
619
|
anim: Animator | null;
|
|
685
620
|
/** false while a model named by asset is loading (the placeholder body shows); true otherwise, also after a failed load (placeholder kept) */
|
|
@@ -690,10 +625,12 @@ export declare class Character {
|
|
|
690
625
|
* npc.playAction('Wave');
|
|
691
626
|
*/
|
|
692
627
|
readonly whenReady: Promise<void>;
|
|
693
|
-
/** The vehicle
|
|
694
|
-
vehicle:
|
|
695
|
-
/**
|
|
696
|
-
|
|
628
|
+
/** The vehicle it sits in (null on foot) */
|
|
629
|
+
vehicle: Rideable | null;
|
|
630
|
+
/** Its seat in the vehicle: 0 drives, others ride; null on foot */
|
|
631
|
+
seat: number | null;
|
|
632
|
+
/** Board a vehicle (rigid.addWheeled's, or any object with the vehicle contract): the driver seat when free, else a free passenger seat; no-op when full */
|
|
633
|
+
enter(vehicle: Rideable): void;
|
|
697
634
|
/** Exit the vehicle */
|
|
698
635
|
exit(): void;
|
|
699
636
|
/** Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip */
|
|
@@ -708,8 +645,11 @@ export declare class Character {
|
|
|
708
645
|
* (used by npcs.remove / removePlayer)
|
|
709
646
|
*/
|
|
710
647
|
dispose(): void;
|
|
711
|
-
/**
|
|
712
|
-
|
|
648
|
+
/**
|
|
649
|
+
* Request a jump (buffered for jumpBuffer s): the ground jump on the ground or in coyote time, else an air jump while maxJumps allows; air: false = ground only
|
|
650
|
+
* @example createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }) // double jump
|
|
651
|
+
*/
|
|
652
|
+
jump(opts?: { air?: boolean }): this;
|
|
713
653
|
/** Add to the scene */
|
|
714
654
|
addTo(scene?: any): this;
|
|
715
655
|
/** Put it on the ground at position (Vector3 / object / [x, y, z] / { x, z }) */
|
|
@@ -721,11 +661,17 @@ export declare class Character {
|
|
|
721
661
|
syncRecord(): this;
|
|
722
662
|
/**
|
|
723
663
|
* Walk to a point along characters.findPath on fixed steps; never rejects. One walk per character: a new walkTo, dispose() or a save load ends the old
|
|
724
|
-
* one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip
|
|
664
|
+
* one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip. Holds the character's control on layer 'script' (owner 'walkTo'):
|
|
665
|
+
* the player's keys / an NPC's schedule pause meanwhile, a cutscene pauses the walk, and another script owner on it is control-conflict
|
|
725
666
|
*/
|
|
726
667
|
walkTo(target: Vector3 | { x: number; z: number } | [number, number, number], opts?: { speed?: number; arrive?: number; turnRate?: number; stuckSeconds?: number; maxRepaths?: number; run?: boolean }): Promise<{ status: 'arrived' | 'noPath' | 'stuck' | 'cancelled' }> & { remove(): void };
|
|
727
|
-
/**
|
|
728
|
-
|
|
668
|
+
/**
|
|
669
|
+
* Move in a direction (called once per fixed step): dirX/dirZ is the world direction (length 0–1 scales the speed), run to run, dt in seconds (used as
|
|
670
|
+
* given). Speed comes from the stats: engine.mod('move.speed', { owner, id: character.id, ... }) (the player: id 'player'), the one way to change speed.
|
|
671
|
+
* A character someone controls (engine.control.of(ch)) moves only through its holder: called from anywhere else it is control-bypass in dev;
|
|
672
|
+
* take control and use handle.move() / step instead
|
|
673
|
+
*/
|
|
674
|
+
move(dirX: number, dirZ: number, run: boolean, dt: number): void;
|
|
729
675
|
/** Ground type underfoot ('water' while swimming) */
|
|
730
676
|
groundType(): string;
|
|
731
677
|
/** Turn at once to a position, or to an angle in radians (0 = +Z) */
|
|
@@ -738,9 +684,14 @@ export declare class Character {
|
|
|
738
684
|
/** Restore the motion state from the plain object of saveMotion */
|
|
739
685
|
loadMotion(m: CharacterMotion | null | undefined): this;
|
|
740
686
|
}
|
|
741
|
-
/** Result of Character.saveMotion (plain values, can be saved) */
|
|
742
|
-
|
|
743
|
-
|
|
687
|
+
/** Result of Character.saveMotion (plain values, can be saved); facing is the same as Character.facing: 0 = +Z, forward (sin f, cos f) */
|
|
688
|
+
export interface CharacterMotion { vx?: number; vz?: number; vy?: number; facing?: number; amount?: number; grounded?: boolean; swimming?: boolean;
|
|
689
|
+
/** Jump state (world part version 4; older saves are migrated from the flat coyote field) */
|
|
690
|
+
jump?: { coyote: number; used: number };
|
|
691
|
+
/** safeGround as [x, y, z] */
|
|
692
|
+
safe?: [number, number, number] | null;
|
|
693
|
+
/** id of the support it rides (characters.support), found again on load */
|
|
694
|
+
support?: string | null }
|
|
744
695
|
|
|
745
696
|
/** One schedule stop (the npcs.add form): at is when to set off, position the destination */
|
|
746
697
|
export interface ScheduleStop {
|
|
@@ -751,6 +702,8 @@ export interface ScheduleStop {
|
|
|
751
702
|
}
|
|
752
703
|
/** One schedule stop (as stored in npc.schedule after install): at has been converted to 0–1, x/z is the destination (meters) */
|
|
753
704
|
export interface ScheduleEntry { at: number; x: number; z: number }
|
|
705
|
+
/** An NPC's interact option: the op the interact key runs near it ({ npc: id, ...args }), its prompt label and reach */
|
|
706
|
+
export interface NpcInteract { op: string; args?: Record<string, any>; label?: string | (() => string); radius?: number }
|
|
754
707
|
/** Parameters of engine.npcs.add({...}) */
|
|
755
708
|
export interface NPCOptions extends CharacterOptions {
|
|
756
709
|
/**
|
|
@@ -779,12 +732,14 @@ export interface NPCOptions extends CharacterOptions {
|
|
|
779
732
|
* the position when wandering started) }
|
|
780
733
|
*/
|
|
781
734
|
mind?: Record<string, any>;
|
|
782
|
-
/**
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
735
|
+
/**
|
|
736
|
+
* What the interact key does near it (needs interactions()): runs the op with { npc: id, ...args }. Dialogue is one such op: { op: 'npc.talk' }
|
|
737
|
+
* (script defaults to the NPC id; args: { script } names another, { channel: 'bubble' } plays it as lines over the NPC while play goes on). label: prompt text (a string is saved, a function stays in memory only);
|
|
738
|
+
* radius meters, default 3.2
|
|
739
|
+
* @example interact: { op: 'npc.talk' }
|
|
740
|
+
* @example interact: { label: 'Trade', op: 'shop.open', args: { shelf: 'tools' } }
|
|
741
|
+
*/
|
|
742
|
+
interact?: NpcInteract | null;
|
|
788
743
|
/** Pathfinding grid size (meters), default 2 */
|
|
789
744
|
pathStep?: number;
|
|
790
745
|
/** Seconds before re-pathfinding after getting stuck, default 2 */
|
|
@@ -811,8 +766,8 @@ export declare class NPC {
|
|
|
811
766
|
readonly schedule: ScheduleEntry[];
|
|
812
767
|
/** Current behavior name */
|
|
813
768
|
readonly behavior: string;
|
|
814
|
-
/**
|
|
815
|
-
readonly
|
|
769
|
+
/** What the interact key does near it ({ label, op, args, radius } as saved), null when nothing */
|
|
770
|
+
readonly interact: { label: string | null; op: string; args: Record<string, any>; radius: number } | null;
|
|
816
771
|
/** Animation state ('idle' / 'walk'...) */
|
|
817
772
|
readonly state: string;
|
|
818
773
|
/** In dialogue (stopped, not walking) */
|
|
@@ -855,6 +810,13 @@ export interface NPCManager {
|
|
|
855
810
|
* seconds); selected through behavior in the data
|
|
856
811
|
*/
|
|
857
812
|
behavior(name: string, impl: { near?: (rec: WorldRecord, dt: number, npc: NPC) => void; far?: (rec: WorldRecord, dt: number) => void }): this;
|
|
813
|
+
/**
|
|
814
|
+
* Near tiers for large crowds, off by default (every near NPC walks every fixed step). With tiers, NPCs within fullRadius m of the focus walk every
|
|
815
|
+
* step; the rest of the near zone takes a turn once every nearEvery seconds with the accumulated dt (deterministic, save-safe). On screen such NPCs
|
|
816
|
+
* move in visible jumps, so only turn this on for crowds of hundreds. tiers(null) turns it off.
|
|
817
|
+
* @example engine.npcs.tiers({ fullRadius: 30, nearEvery: 4 / 60 })
|
|
818
|
+
*/
|
|
819
|
+
tiers(opts: { fullRadius: number; nearEvery: number } | null): this;
|
|
858
820
|
/**
|
|
859
821
|
* Nearby NPCs avoid each other (on by default): pushed apart to no less than the sum of their radii, the player counts as an obstacle (NPCs yield to
|
|
860
822
|
* the player), then constrained back to walkable places by engine.collision; deterministic and cheap, with identical results after loading.
|
|
@@ -895,7 +857,14 @@ export interface CharactersApi {
|
|
|
895
857
|
* The 'camera' player control as a value: keys / stick relative to the camera, the 'run' action if bound, input.autopilot. Reused object; call it
|
|
896
858
|
* inside your own control function to wrap it
|
|
897
859
|
*/
|
|
898
|
-
moveInput(): { x: number; z: number; run: boolean
|
|
860
|
+
moveInput(): { x: number; z: number; run: boolean };
|
|
861
|
+
/**
|
|
862
|
+
* Something characters stand on and ride (moving platform, lift, raft). Move the object any way (onFixed before or after the player, a timeline,
|
|
863
|
+
* physics): riders follow how its matrix changed, so the order does not matter. safe: false = never a respawn spot; carry 'position+yaw' turns riders
|
|
864
|
+
* with it; inherit: false = jumping off keeps none of its speed. With mover 'rapier' give it a collider too.
|
|
865
|
+
* @example const lift = engine.characters.support(liftMesh); engine.onFixed(() => { liftMesh.position.y = 2 + Math.sin(engine.time.now('real')); });
|
|
866
|
+
*/
|
|
867
|
+
support(object: any, opts?: { id?: string; safe?: boolean; carry?: 'position' | 'position+yaw'; inherit?: boolean }): { id: string; remove(): void };
|
|
899
868
|
/**
|
|
900
869
|
* Delete the current player (exits the vehicle first, stops responding to keys, fully deletes the model). The player save (key player) carries the
|
|
901
870
|
* position and the vehicle; loading an on-foot save exits the vehicle first
|
|
@@ -932,14 +901,13 @@ export interface FindSpawnOptions { minH?: number; maxH?: number; maxSlope?: num
|
|
|
932
901
|
export interface CharactersOptions {
|
|
933
902
|
/** Whether to enable NPCs (engine.npcs), default true */
|
|
934
903
|
npcs?: boolean;
|
|
935
|
-
/**
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
/** radius defaults to engine.movement.radius; for detailed see findPath */
|
|
904
|
+
/** Near tiers for large NPC crowds, off by default (every near NPC walks every fixed step); same as engine.npcs.tiers(opts) */
|
|
905
|
+
npcTiers?: { fullRadius: number; nearEvery: number };
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters,
|
|
909
|
+
* default engine.movement.radius); for detailed see findPath
|
|
910
|
+
*/
|
|
943
911
|
export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean }
|
|
944
912
|
|
|
945
913
|
// ======================================================================
|
|
@@ -949,29 +917,39 @@ export interface FindPathOptions { step?: number; maxNodes?: number; radius?: nu
|
|
|
949
917
|
export interface InteractionOptions {
|
|
950
918
|
/** Stable id for the op interaction.use { id } (default: the world record id it was built for, else a running number) */
|
|
951
919
|
id?: string;
|
|
952
|
-
/** Prompt text, or a function returning text */
|
|
953
|
-
label?: string | (() => string);
|
|
920
|
+
/** Prompt text, or a function (object, { actor }) returning text; actor = world record id of who looks at it */
|
|
921
|
+
label?: string | ((object: Object3D, ctx: { actor: string }) => string);
|
|
954
922
|
/** How close the actor must be (meters), default interactions({ radius }) = 2.5 */
|
|
955
923
|
radius?: number;
|
|
956
924
|
/** Key action name, default 'interact' (E key). Give one object a second verb by adding another interaction with another action */
|
|
957
925
|
action?: string;
|
|
958
|
-
/**
|
|
959
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Called when used, with who uses it (ctx.actor of interaction.use: the local user, a net peer, an NPC). Its return value is the op's value; { ok: false,
|
|
928
|
+
* code } fails the op with that code
|
|
929
|
+
*/
|
|
930
|
+
onUse?: (object: Object3D, ctx: { actor: string }) => any;
|
|
960
931
|
/**
|
|
961
932
|
* When this returns false the whole prompt disappears (to show a state such as "growing", don't use enabled: have the label function return different
|
|
962
933
|
* text by state and decide in onUse whether it can be used)
|
|
963
934
|
*/
|
|
964
|
-
enabled?: () => boolean;
|
|
935
|
+
enabled?: (object: Object3D, ctx: { actor: string }) => boolean;
|
|
965
936
|
/** How high the prompt floats above the object (meters) */
|
|
966
937
|
height?: number;
|
|
938
|
+
/**
|
|
939
|
+
* Seconds the key must stay down before onUse runs (0 = a press). The engine counts it and interrupts it on release, leaving reach, enabled() false or
|
|
940
|
+
* locked input (interaction:hold / interaction:interrupt); the prompt gets progress 0-1. The op interaction.use itself is the completed use
|
|
941
|
+
*/
|
|
942
|
+
hold?: number;
|
|
943
|
+
/** Walk the player there first (walkTo, stops 1.2 m away), then use it; with radius: Infinity it can be used from anywhere (point-and-click) */
|
|
944
|
+
approach?: boolean;
|
|
967
945
|
}
|
|
968
946
|
/** engine.interactions */
|
|
969
947
|
export interface Interactions {
|
|
970
948
|
action: string;
|
|
971
949
|
/** How high the prompt floats (meters) */
|
|
972
950
|
promptHeight: number;
|
|
973
|
-
/** All interactions */
|
|
974
|
-
items: any[];
|
|
951
|
+
/** All interactions in the order added (a fresh array each read; get(id) finds one without it) */
|
|
952
|
+
readonly items: any[];
|
|
975
953
|
/** Default reach of add() in meters (2.5) */
|
|
976
954
|
radius: number;
|
|
977
955
|
/** How the one in front of the actor is chosen; can be changed at runtime */
|
|
@@ -980,6 +958,8 @@ export interface Interactions {
|
|
|
980
958
|
current: any;
|
|
981
959
|
/** One best interaction per key action this frame, for a prompt that lists several keys */
|
|
982
960
|
options: { action: string; id: string; label: string }[];
|
|
961
|
+
/** The hold in progress (progress 0-1), null when none */
|
|
962
|
+
holding: { id: string; action: string; seconds: number; progress: number } | null;
|
|
983
963
|
/**
|
|
984
964
|
* Add an interaction: passing an object makes it follow the object, passing a position (Vector3 / [x, y, z] / { x, y, z }) makes a fixed point.
|
|
985
965
|
* Returns a handle { remove() }
|
|
@@ -1008,8 +988,10 @@ export interface PromptView {
|
|
|
1008
988
|
onScreen: boolean;
|
|
1009
989
|
/** Use it (the op interaction.use) */
|
|
1010
990
|
use(): void;
|
|
1011
|
-
/** One best interaction per action this frame, for a prompt that lists several keys ("E ·
|
|
991
|
+
/** One best interaction per action this frame, for a prompt that lists several keys ("E · Open F · Lock") */
|
|
1012
992
|
options: { action: string; id: string; label: string }[];
|
|
993
|
+
/** A hold interaction: how far the hold is (0-1, 0 before it starts); null for a plain press */
|
|
994
|
+
progress: number | null;
|
|
1013
995
|
}
|
|
1014
996
|
/** A candidate handed to a pick function: an enabled interaction within its radius of the actor */
|
|
1015
997
|
export interface InteractionCandidate { id: string; object: Object3D; action: string; label: string | (() => string); distance: number }
|
|
@@ -1031,8 +1013,6 @@ export interface InteractionsOptions {
|
|
|
1031
1013
|
* keys: ['KeyE'], radius: 2 }) // first person
|
|
1032
1014
|
*/
|
|
1033
1015
|
pick: InteractionPick;
|
|
1034
|
-
/** Keys of the action; required unless the game bound the action already (createEngine({ bindings: { interact: [...] } }) or input.define) */
|
|
1035
|
-
keys?: string[];
|
|
1036
1016
|
}
|
|
1037
1017
|
|
|
1038
1018
|
// ======================================================================
|
|
@@ -1075,8 +1055,18 @@ export interface DialogueNode {
|
|
|
1075
1055
|
}
|
|
1076
1056
|
/** Dialogue script: node name -> node, starting from 'start' */
|
|
1077
1057
|
export type DialogueScript = Record<string, DialogueNode>;
|
|
1078
|
-
/** Promise returned by say()
|
|
1079
|
-
export interface SayPromise extends Promise<void> { id: string }
|
|
1058
|
+
/** Promise returned by say(): id is the temporary script name of a main-channel line (null for a plain bubble line); remove() ends the line now (it resolves) */
|
|
1059
|
+
export interface SayPromise extends Promise<void> { id: string | null; remove(): void }
|
|
1060
|
+
/** Which dialogue channel: 'main' the conversation the player reads (locks input, choices) · 'bubble' lines over their speakers while play goes on */
|
|
1061
|
+
export type DialogueChannel = 'main' | 'bubble';
|
|
1062
|
+
/**
|
|
1063
|
+
* Where a bubble line sits: an Object3D (it follows it), a position, an actor / world record id (engine.actorPosition), or null = a screen line (radio, intercom)
|
|
1064
|
+
*/
|
|
1065
|
+
export type BubbleAt = Object3D | PositionLike | string | null;
|
|
1066
|
+
/** Bubble-channel options: seconds on screen (default holdSeconds + about 15 characters a second); queue false = replace this speaker's current line */
|
|
1067
|
+
export interface BubbleOptions { at?: BubbleAt; seconds?: number; queue?: boolean }
|
|
1068
|
+
/** What the 'dialogue.bubble' UI part (one per speaker) receives in update(view) every frame while its line shows */
|
|
1069
|
+
export interface BubbleView { speaker: string; text: string; x: number; y: number; onScreen: boolean; screen: boolean }
|
|
1080
1070
|
|
|
1081
1071
|
/** engine.dialogue */
|
|
1082
1072
|
export interface Dialogue {
|
|
@@ -1084,9 +1074,13 @@ export interface Dialogue {
|
|
|
1084
1074
|
readonly state: DialogueState;
|
|
1085
1075
|
/** All scripts */
|
|
1086
1076
|
scripts: Map<string, DialogueScript>;
|
|
1087
|
-
/**
|
|
1088
|
-
|
|
1089
|
-
|
|
1077
|
+
/**
|
|
1078
|
+
* The dialogue in progress (null when none). speaker: the script name; node: the current node OBJECT (its fields: text, choices, data...);
|
|
1079
|
+
* id: that node's id string ('start', 'ask'); both are set once the first line shows. Read-only: drive it with start / end / the dialogue ops.
|
|
1080
|
+
* @example const atAsk = engine.dialogue.active?.id === 'ask'; // the node id; active.node.data holds the node's own fields
|
|
1081
|
+
*/
|
|
1082
|
+
readonly active: { speaker: string; nodes: DialogueScript; node?: DialogueNode; id?: string; onEnd: (() => void) | null } | null;
|
|
1083
|
+
/** The script the main dialogue is playing */
|
|
1090
1084
|
readonly speaking: string | null;
|
|
1091
1085
|
/** Typing speed (characters/second) */
|
|
1092
1086
|
cps: number;
|
|
@@ -1094,21 +1088,22 @@ export interface Dialogue {
|
|
|
1094
1088
|
define(speaker: string, nodes: DialogueScript): void;
|
|
1095
1089
|
/**
|
|
1096
1090
|
* Start a dialogue: from node nodeId (default 'start'), onEnd is called when it ends.
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
* @example engine.dialogue.start('guard', 'start', null, { lock: false })
|
|
1091
|
+
* Main channel (default): locks game input and takes Esc; its choices take the UI choice cursor. onCancel: what the back key (Esc) does while it is on
|
|
1092
|
+
* top of the UI focus stack (default: nothing). channel: 'bubble' plays the script as bubble lines over at (no lock, no choices; a running
|
|
1093
|
+
* conversation is untouched). Ending the playthrough (engine.session newGame / load / quit) closes it without calling onEnd.
|
|
1094
|
+
* @example engine.dialogue.start('guard', 'start', null, { channel: 'bubble', at: guard.root })
|
|
1102
1095
|
*/
|
|
1103
|
-
start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: {
|
|
1096
|
+
start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { channel?: DialogueChannel; at?: BubbleAt; onCancel?: (() => void) | null }): void;
|
|
1104
1097
|
/**
|
|
1105
|
-
* Say a one-off line (no need to define first); the Promise resolves when it is done.
|
|
1106
|
-
* chatter).
|
|
1098
|
+
* Say a one-off line (no need to define first); the Promise resolves when it is done. channel: 'bubble' = over at while the player keeps playing
|
|
1099
|
+
* (barks, shop chatter, radio); several speakers at once, queued per speaker.
|
|
1107
1100
|
* When the playthrough ends (engine.session) the line is dropped and the Promise never resolves, so code awaiting it does not run in the next playthrough.
|
|
1108
|
-
* @example await engine.dialogue.say('Reloading!', { speaker: 'Mira',
|
|
1101
|
+
* @example await engine.dialogue.say('Reloading!', { speaker: 'Mira', channel: 'bubble', at: mira.root })
|
|
1109
1102
|
*/
|
|
1110
|
-
say(text: string | DialogueScript, opts?: { speaker?: string; node?: string;
|
|
1111
|
-
/**
|
|
1103
|
+
say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; channel?: DialogueChannel; onCancel?: (() => void) | null } & BubbleOptions): SayPromise;
|
|
1104
|
+
/** Lines on the bubble channel now */
|
|
1105
|
+
bubbles(): { speaker: string; text: string; queued: number }[];
|
|
1106
|
+
/** End the main dialogue */
|
|
1112
1107
|
end(): void;
|
|
1113
1108
|
// Advancing and choosing are ops: engine.ops.run('dialogue.advance') / engine.ops.run('dialogue.choose', { index })
|
|
1114
1109
|
// (0-based; while typing it completes the line first)
|
|
@@ -1116,11 +1111,10 @@ export interface Dialogue {
|
|
|
1116
1111
|
export interface DialogueOptions {
|
|
1117
1112
|
/** Typing speed (characters/second, game time: advanced by engine.step), default 40 */
|
|
1118
1113
|
charsPerSecond?: number;
|
|
1119
|
-
/** Actions that advance the dialogue, default ['confirm', 'interact']
|
|
1114
|
+
/** Actions that advance the dialogue, default ['confirm'] (a basic key); e.g. ['confirm', 'interact'] to also advance on the game's interact key.
|
|
1115
|
+
* Choices: the cursor, clicks, and the actions choice1..choice9 (context 'dialog', no keys of their own: presets.bindings.dialogNumbers binds 1-9) */
|
|
1120
1116
|
advanceActions?: string[];
|
|
1121
|
-
/**
|
|
1122
|
-
choiceKeys?: boolean;
|
|
1123
|
-
/** A non-locking line (lock: false) moves on this many seconds after it is fully typed, default 2 */
|
|
1117
|
+
/** A bubble line stays this many seconds plus its reading time (about 15 characters a second) unless say() gives seconds, default 2 */
|
|
1124
1118
|
holdSeconds?: number;
|
|
1125
1119
|
}
|
|
1126
1120
|
/**
|
|
@@ -1158,8 +1152,8 @@ export interface DialogueView {
|
|
|
1158
1152
|
hint: string;
|
|
1159
1153
|
/** The node's data (the game's own fields), {} when none */
|
|
1160
1154
|
data: Record<string, any>;
|
|
1161
|
-
/**
|
|
1162
|
-
|
|
1155
|
+
/** The choice under the UI choice cursor (menu keys / d-pad / stick; confirm picks it), -1 when no choices show */
|
|
1156
|
+
selected: number;
|
|
1163
1157
|
/** Run the op dialogue.advance (finish typing / next line) */
|
|
1164
1158
|
advance(): any;
|
|
1165
1159
|
/** Run the op dialogue.choose { index } (0-based among choices) */
|
|
@@ -1192,24 +1186,37 @@ export interface ItemDef {
|
|
|
1192
1186
|
consume?: boolean;
|
|
1193
1187
|
/** Color of the pickup on the ground */
|
|
1194
1188
|
color?: ColorLike;
|
|
1189
|
+
/** Shape on the ground: a model name from an asset pack (file or generator; default: a model named 'pickup:<item id>', else 'pickup', else a gray box) */
|
|
1190
|
+
model?: string;
|
|
1195
1191
|
[key: string]: any;
|
|
1196
1192
|
}
|
|
1197
|
-
/**
|
|
1198
|
-
|
|
1193
|
+
/**
|
|
1194
|
+
* Every container emits item:add / item:remove. container = which container changed (an actor's bag has the actor's id; the local one is engine.actor),
|
|
1195
|
+
* actor = who did it (the running op's actor, else engine.actor), id = item id, key = entry key ('arrow', or 'sword#3' for a piece with data),
|
|
1196
|
+
* count = change, total = how many of the item that container holds now
|
|
1197
|
+
*/
|
|
1198
|
+
export interface ItemEvent { container: string; actor: string; id: string; key: string; count: number; total: number }
|
|
1199
1199
|
/** inventory.use: who used which entry (data = that piece's data) */
|
|
1200
1200
|
export interface ItemUseEvent { actor: string; item: string; key: string; data?: Record<string, any> }
|
|
1201
1201
|
/** One entry of a container: plain items share one entry per kind (key = item id); items with data have their own key ('sword#3') */
|
|
1202
1202
|
export interface ItemEntry { key: string; id: string; count: number; data?: Readonly<Record<string, any>>; def: ItemDef }
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
export interface
|
|
1203
|
+
export interface PickupEvent { pickup: string; item: string | null; count: number; actor: string; x: number; z: number }
|
|
1204
|
+
/** What a give function gets: who takes it (world record id) and the pickup record */
|
|
1205
|
+
export interface PickupGiveContext { actor: string; pickup: WorldRecord }
|
|
1206
1206
|
/**
|
|
1207
|
-
* Handle returned by
|
|
1207
|
+
* Handle returned by pickups.spawn(): id is the world record id, object is the current model (null when far away);
|
|
1208
1208
|
* remove() deletes the pickup (data and model; a model passed in through opts.mesh is only taken off)
|
|
1209
1209
|
*/
|
|
1210
|
-
export interface PickupHandle extends Handle {
|
|
1211
|
-
/**
|
|
1210
|
+
export interface PickupHandle extends Handle {
|
|
1211
|
+
/** The pickup's world record id (engine.world.get(id)), not the item id (0.2 meaning; the item is `give` when it is a string) */
|
|
1212
|
+
id: string; give: string | ((e: Engine, ctx: PickupGiveContext) => any); readonly object: Object3D | null }
|
|
1213
|
+
/** Parameters of pickups.spawn() */
|
|
1212
1214
|
export interface PickupOptions {
|
|
1215
|
+
/**
|
|
1216
|
+
* What taking it does: an item id goes into the picker's container (inventory.of(actor); needs inventory()); a function (e, { actor, pickup }) => result is an
|
|
1217
|
+
* instant effect (no inventory needed; not saved data, so spawn it again on load). Returning { ok: false, code } leaves it on the ground
|
|
1218
|
+
*/
|
|
1219
|
+
give: string | ((e: Engine, ctx: PickupGiveContext) => any);
|
|
1213
1220
|
/**
|
|
1214
1221
|
* Stable id of this record in world (saves recognize it by this); numbered automatically pickup#1... if omitted, and an existing record with the same
|
|
1215
1222
|
* id is reused
|
|
@@ -1219,11 +1226,17 @@ export interface PickupOptions {
|
|
|
1219
1226
|
count?: number;
|
|
1220
1227
|
/** The piece's own data (a dropped sword keeps its durability) */
|
|
1221
1228
|
data?: Record<string, any>;
|
|
1222
|
-
/**
|
|
1229
|
+
/** Name in the prompt ("Pick up {name}"), default the item's name */
|
|
1230
|
+
name?: string;
|
|
1231
|
+
/** Shape on the ground: a model name from an asset pack (default the item's model, else 'pickup:<item>', else 'pickup', else a gray box) */
|
|
1232
|
+
model?: string;
|
|
1233
|
+
/** Color of the gray placeholder / a geometry-only model (default the item's color, else style.pickup.color) */
|
|
1234
|
+
color?: ColorLike;
|
|
1235
|
+
/** Reach in meters, default pickups({ radius }) (2) */
|
|
1223
1236
|
radius?: number;
|
|
1224
|
-
/** Taken by walking into it (no key press, no prompt) */
|
|
1237
|
+
/** Taken by walking into it (no key press, no prompt), by every actor in pickups.takers */
|
|
1225
1238
|
auto?: boolean;
|
|
1226
|
-
/**
|
|
1239
|
+
/** The game's own three.js object for this one pickup (only detached when it goes; otherwise the model name decides the shape) */
|
|
1227
1240
|
mesh?: Object3D | null;
|
|
1228
1241
|
/** Game seconds until it reappears, 0 = never reappears */
|
|
1229
1242
|
respawnSeconds?: number;
|
|
@@ -1237,9 +1250,32 @@ export interface PickupOptions {
|
|
|
1237
1250
|
/** Which zone it belongs to (a level name, see world.zone): the data stays across level changes (a picked-up one stays picked up) */
|
|
1238
1251
|
zone?: string | null;
|
|
1239
1252
|
}
|
|
1253
|
+
/** engine.pickups: things on the ground that give whoever takes them an item or an instant effect (op pickup.take, net: 'peer') */
|
|
1254
|
+
export interface Pickups {
|
|
1255
|
+
/** Reach of pickups that do not set their own (meters) */
|
|
1256
|
+
radius: number;
|
|
1257
|
+
/** Who walks into auto pickups: default engine.actor plus net peers on a host, none on a client */
|
|
1258
|
+
takers: (e: Engine) => string[];
|
|
1259
|
+
/**
|
|
1260
|
+
* Place a pickup on the ground at position; its y, if any, is the reference height on multi-layer ground (needs the interactions module unless auto):
|
|
1261
|
+
* spawn(v, { give: 'berry', count: 2 }). Returns a handle, remove() deletes it
|
|
1262
|
+
*/
|
|
1263
|
+
spawn(position: PositionLike, opts: PickupOptions): PickupHandle;
|
|
1264
|
+
/** The data of the nearest pickup still on the ground to from (default engine.actorPosition()), of one item id or any; null if none */
|
|
1265
|
+
nearest(item?: string | null, from?: PositionLike): WorldRecord | null;
|
|
1266
|
+
}
|
|
1267
|
+
export interface PickupsOptions {
|
|
1268
|
+
/** Reach of pickups that do not set their own radius (meters), default 2 */
|
|
1269
|
+
radius?: number;
|
|
1270
|
+
/** Pickups have a model, float and spin only within this distance (meters) of the stream sources, default 60 */
|
|
1271
|
+
showDistance?: number;
|
|
1272
|
+
/** Who walks into auto pickups (actor ids); default engine.actor, plus net peers on a host */
|
|
1273
|
+
takers?: (e: Engine) => string[];
|
|
1274
|
+
}
|
|
1240
1275
|
|
|
1241
1276
|
/**
|
|
1242
|
-
* Container (inventory, chest, corpse, shelf): inventory.container(id, opts) gets or creates one;
|
|
1277
|
+
* Container (inventory, chest, corpse, shelf, an actor's bag): inventory.container(id, opts) gets or creates one; an actor's bag has the actor's id
|
|
1278
|
+
* (inventory.of(actor)), the player inventory is the bag of engine.actor.
|
|
1243
1279
|
* Every x is an item id or an entry key
|
|
1244
1280
|
*/
|
|
1245
1281
|
export interface Container {
|
|
@@ -1262,17 +1298,17 @@ export interface Container {
|
|
|
1262
1298
|
list(): ItemEntry[];
|
|
1263
1299
|
/** How many more fit (Infinity = no limit), for an item without data, with this data, or like an existing entry key */
|
|
1264
1300
|
room(x: string, data?: Record<string, any>): number;
|
|
1265
|
-
/** Add n (default 1), optionally with data; returns the entry key, false if none fit; silent suppresses the toast (only the
|
|
1301
|
+
/** Add n (default 1), optionally with data; returns the entry key, false if none fit; silent suppresses the toast (only the bag of engine.actor shows one) */
|
|
1266
1302
|
add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): string | false;
|
|
1267
1303
|
/** Remove n (default 1) of an item or entry key, returns false if there are not enough */
|
|
1268
1304
|
remove(x: string, n?: number): boolean;
|
|
1269
1305
|
/**
|
|
1270
|
-
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step;
|
|
1306
|
+
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; failure code 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
|
|
1271
1307
|
* reverses it
|
|
1272
1308
|
*/
|
|
1273
1309
|
trade(
|
|
1274
1310
|
take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
|
|
1275
|
-
): { ok: boolean;
|
|
1311
|
+
): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
|
|
1276
1312
|
/** Replace an entry's data (null = none) for n pieces (default all); returns the key now holding them */
|
|
1277
1313
|
setData(key: string, data: Record<string, any> | null, n?: number): string;
|
|
1278
1314
|
/** Listen for changes of this container, returns a handle */
|
|
@@ -1287,11 +1323,11 @@ export interface Inventory {
|
|
|
1287
1323
|
defs: Map<string, ItemDef>;
|
|
1288
1324
|
/** Slot limit of the player inventory */
|
|
1289
1325
|
capacity: number;
|
|
1290
|
-
/** Player inventory (=
|
|
1326
|
+
/** Player inventory: the bag of engine.actor (= of()) */
|
|
1291
1327
|
readonly bag: Container;
|
|
1328
|
+
/** The bag of an actor (default engine.actor): the container with the actor's id, created empty on first use; inside an op pass ctx.actor */
|
|
1329
|
+
of(actor?: string): Container;
|
|
1292
1330
|
defaultStack: number;
|
|
1293
|
-
/** Reach of pickups that do not set their own (meters) */
|
|
1294
|
-
pickupRadius: number;
|
|
1295
1331
|
action: string;
|
|
1296
1332
|
/** Define an item (chainable) */
|
|
1297
1333
|
define(id: string, def: ItemDef): this;
|
|
@@ -1312,12 +1348,12 @@ export interface Inventory {
|
|
|
1312
1348
|
/** Remove n (default 1) of an item or entry key, returns false if there are not enough */
|
|
1313
1349
|
remove(x: string, n?: number): boolean;
|
|
1314
1350
|
/**
|
|
1315
|
-
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step;
|
|
1351
|
+
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; failure code 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
|
|
1316
1352
|
* reverses it
|
|
1317
1353
|
*/
|
|
1318
1354
|
trade(
|
|
1319
1355
|
take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
|
|
1320
|
-
): { ok: boolean;
|
|
1356
|
+
): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
|
|
1321
1357
|
/** Replace a player inventory entry's data for n pieces (default all); returns the key now holding them */
|
|
1322
1358
|
setData(key: string, data: Record<string, any> | null, n?: number): string;
|
|
1323
1359
|
/**
|
|
@@ -1332,31 +1368,20 @@ export interface Inventory {
|
|
|
1332
1368
|
transfer(from: Container | string, to: Container | string, item: string, n?: number): number;
|
|
1333
1369
|
/** Delete a container together with its contents ('player' cannot be deleted), returns whether one was deleted */
|
|
1334
1370
|
removeContainer(id: string): boolean;
|
|
1335
|
-
/**
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
spawnPickup(id: string, position: PositionLike, opts?: PickupOptions): PickupHandle;
|
|
1340
|
-
/** The data of the nearest pickup of an item still on the ground to from (default the player) (a world record of kind 'pickup'), null if none */
|
|
1341
|
-
nearestPickup(id: string, from?: PositionLike): WorldRecord | null;
|
|
1371
|
+
/** Every container's items as plain data, the player bag included: { [containerId]: entries } (what setContents takes; net syncs through these two) */
|
|
1372
|
+
contents(): Record<string, any[]>;
|
|
1373
|
+
/** Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too */
|
|
1374
|
+
setContents(data: Record<string, any[] | null>, opts?: { only?: boolean }): void;
|
|
1342
1375
|
}
|
|
1343
1376
|
export interface InventoryOptions {
|
|
1344
1377
|
/** Action name that opens the inventory, default 'inventory' */
|
|
1345
1378
|
action?: string;
|
|
1346
|
-
/** Keys that open the bag: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.inventory has ['KeyI'] */
|
|
1347
|
-
keys?: string[];
|
|
1348
|
-
/** Gamepad button, none by default; presets.keys.inventory has ['PadY'] */
|
|
1349
|
-
pad?: string[];
|
|
1350
1379
|
/** true: gameplay freezes (engine.freeze) while the inventory window is open, default false. Also settable at runtime: engine.inventory.pauseGame */
|
|
1351
1380
|
pauseGame?: boolean;
|
|
1352
|
-
/** Pickups float and spin only within this distance (meters) of the focus, default 60 */
|
|
1353
|
-
bobDistance?: number;
|
|
1354
1381
|
/** Slot limit of the player inventory, default Infinity (no limit) */
|
|
1355
1382
|
capacity?: number;
|
|
1356
1383
|
/** Weight limit of the player inventory, default Infinity */
|
|
1357
1384
|
maxWeight?: number;
|
|
1358
|
-
/** Reach of pickups that do not set their own radius (meters), default 2 */
|
|
1359
|
-
pickupRadius?: number;
|
|
1360
1385
|
/** Default stack limit, default 99 */
|
|
1361
1386
|
defaultStack?: number;
|
|
1362
1387
|
}
|
|
@@ -1402,14 +1427,16 @@ export interface QuestDef {
|
|
|
1402
1427
|
/** engine.quests */
|
|
1403
1428
|
export interface Quests {
|
|
1404
1429
|
defs: Map<string, QuestDef>;
|
|
1405
|
-
/** Quests in progress / completed / failed: id -> { step (current step), done, failed?, parts? } */
|
|
1406
|
-
state: Record<string, { step: number; done: boolean; failed?: boolean; parts?: boolean[] }>;
|
|
1407
1430
|
/** The quest log (UI part 'questLog'): open, toggle(on?), refresh() */
|
|
1408
1431
|
win: { readonly open: boolean; toggle(on?: boolean): void; refresh(): void };
|
|
1409
1432
|
/** Define a quest (chainable) */
|
|
1410
1433
|
define(id: string, def: QuestDef): this;
|
|
1411
1434
|
/** Start a quest */
|
|
1412
1435
|
start(id: string): void;
|
|
1436
|
+
/** One quest's progress (a copy): step index, step count, done, failed, active; null before it starts */
|
|
1437
|
+
state(id: string): { step: number; steps: number; done: boolean; failed: boolean; active: boolean } | null;
|
|
1438
|
+
/** Finish the current step from code (its done() is not asked) and go on; the last step completes the quest. false when not active */
|
|
1439
|
+
advance(id: string): boolean;
|
|
1413
1440
|
isDone(id: string): boolean;
|
|
1414
1441
|
/** Started, not done and not failed */
|
|
1415
1442
|
isActive(id: string): boolean;
|
|
@@ -1445,10 +1472,6 @@ export interface QuestLogView {
|
|
|
1445
1472
|
export interface QuestsOptions {
|
|
1446
1473
|
/** Action name that opens the quest log, default 'quests' */
|
|
1447
1474
|
action?: string;
|
|
1448
|
-
/** Keys that open the quest log: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.quests has ['KeyJ'] */
|
|
1449
|
-
keys?: string[];
|
|
1450
|
-
/** Gamepad button, none by default; presets.keys.quests has ['PadSelect'] */
|
|
1451
|
-
pad?: string[];
|
|
1452
1475
|
/** Check interval (game seconds, checked in the fixed step; not checked while frozen / paused), default 0.5 */
|
|
1453
1476
|
checkInterval?: number;
|
|
1454
1477
|
/**
|
|
@@ -1478,18 +1501,14 @@ export interface PhotoTakeOptions {
|
|
|
1478
1501
|
scale?: number;
|
|
1479
1502
|
/** Shadow resolution (pixels), default 4096 */
|
|
1480
1503
|
shadowMapSize?: number;
|
|
1481
|
-
/**
|
|
1482
|
-
bloom?: boolean;
|
|
1504
|
+
/** Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only */
|
|
1505
|
+
bloom?: boolean | null;
|
|
1483
1506
|
/** Image quality 0–1 */
|
|
1484
1507
|
quality?: number;
|
|
1485
1508
|
/** Image format, e.g. 'image/jpeg' */
|
|
1486
1509
|
format?: string;
|
|
1487
1510
|
}
|
|
1488
1511
|
export interface PhotoOptions extends PhotoTakeOptions {
|
|
1489
|
-
/** Photo key: required unless createEngine({ bindings }) binds 'photo' ([] = no key); presets.keys.photo has ['KeyP'] */
|
|
1490
|
-
keys?: string[];
|
|
1491
|
-
/** Gamepad button for taking a photo, none by default; presets.keys.photo has ['PadRB'] */
|
|
1492
|
-
pad?: string[];
|
|
1493
1512
|
/** How many photos the album keeps at most, default 50 */
|
|
1494
1513
|
maxAlbum?: number;
|
|
1495
1514
|
}
|
|
@@ -1532,10 +1551,12 @@ export interface UIWindow {
|
|
|
1532
1551
|
refresh(): void;
|
|
1533
1552
|
/** Open / close (toggle if no argument is passed) */
|
|
1534
1553
|
toggle(on?: boolean): void;
|
|
1554
|
+
/** Remove the window: closed, its listeners and its element gone (a module passes the window to ctx.track instead) */
|
|
1555
|
+
remove(): void;
|
|
1535
1556
|
}
|
|
1536
1557
|
/** Parameters of makeWindow() */
|
|
1537
1558
|
export interface WindowOptions {
|
|
1538
|
-
/** Window name (also the style
|
|
1559
|
+
/** Window name (also the style's template name) */
|
|
1539
1560
|
id: string;
|
|
1540
1561
|
/** Title */
|
|
1541
1562
|
title: () => string;
|
|
@@ -1555,7 +1576,19 @@ export interface FocusHandle extends Handle {
|
|
|
1555
1576
|
cancel: (() => void) | null;
|
|
1556
1577
|
/** Just pushed this frame (the key press that opened it must not count as its own action) */
|
|
1557
1578
|
readonly fresh: boolean;
|
|
1579
|
+
/** The selected control / choice (null until the cursor first runs) */
|
|
1580
|
+
index: number | null;
|
|
1581
|
+
/** The choice cursor used confirm on this entry this frame (the owner's own confirm handling skips this frame) */
|
|
1582
|
+
readonly consumed: boolean;
|
|
1583
|
+
/** Change the cursor's controls while pushed (the index starts over); null = no cursor */
|
|
1584
|
+
setNav(nav: FocusNav | null): void;
|
|
1558
1585
|
}
|
|
1586
|
+
/**
|
|
1587
|
+
* The UI choice cursor's controls for a focus entry: moved by the menu keys (uiUp / uiDown / uiLeft / uiRight, d-pad, left stick), pressed by confirm.
|
|
1588
|
+
* A function returning an element = the controls inside it (button, input, select, [data-nav]) in screen layout, the selected one gets .is-cursor;
|
|
1589
|
+
* an object = a list the owner draws itself (any direction steps by one).
|
|
1590
|
+
*/
|
|
1591
|
+
export type FocusNav = (() => Element | null) | { count(): number; confirm(index: number): void; moved?(index: number): void };
|
|
1559
1592
|
/**
|
|
1560
1593
|
* UI focus stack: windows, dialogue, cutscenes and the settings menu are pushed in the order they open, and the back key (action cancel) goes only to
|
|
1561
1594
|
* the top; when the stack is empty it goes to the one registered by setRoot (the settings menu)
|
|
@@ -1565,8 +1598,10 @@ export interface UIFocus {
|
|
|
1565
1598
|
readonly top: string | null;
|
|
1566
1599
|
/** Names from bottom to top */
|
|
1567
1600
|
list(): string[];
|
|
1568
|
-
/**
|
|
1569
|
-
|
|
1601
|
+
/** The top entry's choice cursor ({ id, index }) when it has a nav, else null */
|
|
1602
|
+
readonly cursor: { id: string; index: number } | null;
|
|
1603
|
+
/** Push; without cancel = swallow the back key; nav = the choice cursor's controls (see FocusNav) */
|
|
1604
|
+
push(id: string, opts?: { cancel?: (() => void) | null; nav?: FocusNav | null }): FocusHandle;
|
|
1570
1605
|
/** What to do on the back key when the stack is empty (only one, a later registration replaces it) */
|
|
1571
1606
|
setRoot(fn: () => void): Handle;
|
|
1572
1607
|
}
|
|
@@ -1577,24 +1612,112 @@ export interface UIFocus {
|
|
|
1577
1612
|
// ======================================================================
|
|
1578
1613
|
|
|
1579
1614
|
/**
|
|
1580
|
-
* engine.clock:
|
|
1615
|
+
* engine.clock: calendar seconds and "after how long / every how long". Clock-time / season timers are on engine.sky (at / between / daily / onSeason). All
|
|
1581
1616
|
* timers return a handle { remove() }
|
|
1582
1617
|
*/
|
|
1583
1618
|
export interface Clock {
|
|
1584
1619
|
/**
|
|
1585
|
-
*
|
|
1586
|
-
* one
|
|
1620
|
+
* Calendar seconds = world-channel seconds x clock.rate, does not advance while paused / frozen, saved with the game;
|
|
1621
|
+
* one calendar day = calendar.dayLength calendar seconds
|
|
1622
|
+
*/
|
|
1623
|
+
readonly now: number;
|
|
1624
|
+
/**
|
|
1625
|
+
* Calendar seconds per world-channel second (default 1; 0 stops the calendar, sky included). Read-only: change it with
|
|
1626
|
+
* `engine.mod('clock.rate', { owner: 'game', set: 60 })` (a minute per second); the handle's remove() undoes it
|
|
1627
|
+
*/
|
|
1628
|
+
readonly rate: number;
|
|
1629
|
+
/** Calendar seconds per real second right now (rate x the world channel's speed) */
|
|
1630
|
+
readonly speed: number;
|
|
1631
|
+
/**
|
|
1632
|
+
* Call fn after seconds calendar seconds; if an event name is passed, the event is emitted when due (with data, can be saved).
|
|
1633
|
+
* { channel } counts that time channel's seconds instead (a poison tick that slows down in bullet time)
|
|
1634
|
+
*/
|
|
1635
|
+
after(seconds: number, fnOrEvent: (() => void) | string, data?: any, opts?: { channel?: string }): Handle;
|
|
1636
|
+
/** Call once every seconds calendar seconds ({ channel }: 'real' or a time channel's seconds instead) */
|
|
1637
|
+
every(seconds: number, fn: () => void, opts?: { channel?: string }): Handle;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
/** The handle engine.mod / input.gate return: remove() ends only this owner's entry (a stale handle ends nothing) */
|
|
1641
|
+
export interface ModHandle {
|
|
1642
|
+
owner: string; remove(): void;
|
|
1643
|
+
/** Rewrite this entry's value in place (same op / layer): a per-frame contribution takes once and changes every frame. false when the handle is stale */
|
|
1644
|
+
change(value: any): boolean;
|
|
1645
|
+
}
|
|
1646
|
+
/** Shared-point layers, lowest first. Most code never passes one: game code and game modules are 'game'; effects (weather, bullet time) pass 'effect' */
|
|
1647
|
+
export type SharedLayer = 'engine' | 'style' | 'game' | 'effect' | 'system' | 'settings' | 'debug';
|
|
1648
|
+
/**
|
|
1649
|
+
* engine.mod options: exactly one of set / add / mul / clamp on a number point (set on a value point); none on a hold ('freeze') or a slot;
|
|
1650
|
+
* value on a 'top' point. Inside a layer: set, then add, then mul, then clamp; a higher layer's set hides what is below. Two owners setting one
|
|
1651
|
+
* point on one layer throw shared-conflict in development. The settings layer only restricts (clamp / mul; set false on a value point).
|
|
1652
|
+
*/
|
|
1653
|
+
export interface ModOptions {
|
|
1654
|
+
owner: string;
|
|
1655
|
+
set?: any; add?: number; mul?: number; clamp?: { min?: number; max?: number };
|
|
1656
|
+
/** 'top' points (the camera): the holder's value; 'any' ones: optional data kept beside the hold */
|
|
1657
|
+
value?: any;
|
|
1658
|
+
/** Seconds until it ends by itself, on clock ('real' by default: fixed seconds, stop while frozen; or a time channel name) */
|
|
1659
|
+
for?: number; clock?: string;
|
|
1660
|
+
/** The record, for per-record points ('time.local', your own per: true ones) */
|
|
1661
|
+
id?: string;
|
|
1662
|
+
/** Default 'game'. settings / system / debug entries are not saved */
|
|
1663
|
+
layer?: SharedLayer;
|
|
1664
|
+
}
|
|
1665
|
+
/** One entry as describe and holders() show it; at = the code line that took it (development builds) */
|
|
1666
|
+
export interface ModHolder { owner: string; at?: string; op?: 'set' | 'add' | 'mul' | 'clamp'; value?: any; layer?: SharedLayer; left?: number; clock?: string; hidden?: boolean; }
|
|
1667
|
+
/** One describe().shared row: writer = the owner whose value the rest acts on ('default' when nobody set it; 'three (engine yielded)' after a direct three.js write) */
|
|
1668
|
+
export interface SharedRow { value: any; writer: string; layer?: SharedLayer; at?: string; how?: string; also: ModHolder[]; }
|
|
1669
|
+
/** One shared point (engine.stacks.get(name)): read it here; change it with engine.mod(name, { owner, ... }), the one way in. A settings row
|
|
1670
|
+
* restricts one with engine.settings.define(key, def, { limits: name }) */
|
|
1671
|
+
export interface Stack {
|
|
1672
|
+
readonly name: string; readonly kind: 'number' | 'value' | 'any' | 'top' | 'one';
|
|
1673
|
+
/** The describe().shared row */
|
|
1674
|
+
row(id?: string): SharedRow;
|
|
1675
|
+
/** Whoever applies this point to a three.js property saw an outside write: stop applying it (check yielded); describe says writer three */
|
|
1676
|
+
yieldToThree(at?: string | null): void;
|
|
1677
|
+
/** Hand a yielded point back to the layers */
|
|
1678
|
+
reclaim(): void;
|
|
1679
|
+
readonly yielded: boolean;
|
|
1680
|
+
/** The current value, always recomputed from base + the entries now present (a slot: the holder's name or null) */
|
|
1681
|
+
value(id?: string): any;
|
|
1682
|
+
holders(id?: string): ModHolder[];
|
|
1683
|
+
names(id?: string): string[];
|
|
1684
|
+
has(owner: string, id?: string): boolean;
|
|
1685
|
+
size(id?: string): number;
|
|
1686
|
+
/** End owner's entry; false when it held none */
|
|
1687
|
+
release(owner: string, opts?: { id?: string }): boolean;
|
|
1688
|
+
}
|
|
1689
|
+
/** engine.stacks: every shared point by name ('time.<channel>', 'time.local', 'clock.rate', 'freeze', 'pause', 'camera', 'debug.view', slots, your own) */
|
|
1690
|
+
export interface Stacks {
|
|
1691
|
+
/**
|
|
1692
|
+
* Define your own point: kind 'number' (default, base 1), 'value' (any data, set only), 'any' (true while held), 'top' (latest holder wins),
|
|
1693
|
+
* 'one' (exclusive slot); per: true = one value per record id; manual = the takeover call the conflict error offers
|
|
1587
1694
|
*/
|
|
1588
|
-
|
|
1695
|
+
define(name: string, opts?: { kind?: 'number' | 'value' | 'any' | 'top' | 'one'; base?: any; min?: number; max?: number; per?: boolean | 'optional'; save?: boolean; manual?: string }): Stack;
|
|
1696
|
+
get(name: string): Stack;
|
|
1697
|
+
has(name: string): boolean;
|
|
1698
|
+
list(): string[];
|
|
1699
|
+
mod(name: string, opts: ModOptions): ModHandle;
|
|
1700
|
+
/** describe().shared: one row per point with entries */
|
|
1701
|
+
describe(): Record<string, SharedRow>;
|
|
1702
|
+
/** Everything one owner changes now, e.g. ['time.world (mul 0.8, effect)', 'inventory (holds)'] */
|
|
1703
|
+
of(owner: string): string[];
|
|
1704
|
+
}
|
|
1705
|
+
/** engine.time: time channels (world, player, your own). Speeds change only through engine.mod('time.<channel>', ...) */
|
|
1706
|
+
export interface Time {
|
|
1707
|
+
/** Define a channel; parent (default 'world') multiplies its speed */
|
|
1708
|
+
channel(name: string, opts?: { parent?: string | null; stack?: string }): Time;
|
|
1709
|
+
channels(): string[];
|
|
1710
|
+
/** Effective speed: parent x the channel's stack (x the record's 'time.local' stack when id is given) */
|
|
1711
|
+
scale(name: string, id?: string): number;
|
|
1712
|
+
/** Fixed steps run this playthrough: the one time counter (= engine.tick); every other time is a read-only view of it */
|
|
1713
|
+
readonly tick: number;
|
|
1589
1714
|
/**
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1715
|
+
* Seconds on a view: 'real' (tick / 60, no scale, stops while frozen), 'ambient' (= uniforms.uTime, keeps moving while frozen),
|
|
1716
|
+
* 'calendar' (= engine.clock.now) or a channel ('world', 'player', your own)
|
|
1592
1717
|
*/
|
|
1593
|
-
|
|
1594
|
-
/**
|
|
1595
|
-
|
|
1596
|
-
/** Call once every seconds game seconds */
|
|
1597
|
-
every(seconds: number, fn: () => void): Handle;
|
|
1718
|
+
now(name: 'real' | 'ambient' | 'calendar' | 'world' | 'player' | (string & {})): number;
|
|
1719
|
+
/** This fixed step's dt on a channel (1/60 x scale). Change a speed with engine.mod('time.<channel>', { owner, set | mul }); timers: engine.clock.after(s, fn, data, { channel }) */
|
|
1720
|
+
dt(name: string, id?: string): number;
|
|
1598
1721
|
}
|
|
1599
1722
|
/** engine.vars: story flags and counters (autosaved) */
|
|
1600
1723
|
export interface Vars {
|
|
@@ -1624,8 +1747,8 @@ export interface ContentConditionDef {
|
|
|
1624
1747
|
ref?: ContentRef;
|
|
1625
1748
|
/** One-line description */
|
|
1626
1749
|
desc?: string;
|
|
1627
|
-
/** Whether it holds: value is the value converted by ref, raw is the form written in the content */
|
|
1628
|
-
test(e: Engine, value: any, raw?: any): boolean;
|
|
1750
|
+
/** Whether it holds: value is the value converted by ref, raw is the form written in the content, ctx.actor = who is asking (content.test's actor) */
|
|
1751
|
+
test(e: Engine, value: any, raw?: any, ctx?: { actor: string }): boolean;
|
|
1629
1752
|
/** Write the value as human-readable text (for the game map) */
|
|
1630
1753
|
describe?(value: any): string;
|
|
1631
1754
|
}
|
|
@@ -1669,12 +1792,12 @@ export interface Content {
|
|
|
1669
1792
|
* @example engine.content.load([baseContent, forestDlc], { places: { home } })
|
|
1670
1793
|
*/
|
|
1671
1794
|
load(data: ContentPack | ContentPack[], opts?: ContentLoadOptions): this;
|
|
1672
|
-
/** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.
|
|
1795
|
+
/** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.calendar.timeOfDay >= t }) */
|
|
1673
1796
|
condition(name: string, def: ContentConditionDef): this;
|
|
1674
|
-
/** Whether a condition holds (object, array or function) */
|
|
1675
|
-
test(cond: any): boolean;
|
|
1676
|
-
/** Run an effect (object, array or function) */
|
|
1677
|
-
run(effect: any): any;
|
|
1797
|
+
/** Whether a condition holds (object, array or function (e, { actor })); actor = whose bag has / lacks look in (default the running op's actor, else engine.actor) */
|
|
1798
|
+
test(cond: any, opts?: { actor?: string }): boolean;
|
|
1799
|
+
/** Run an effect (object, array or function (e, { actor })); actor = whose bag give / take change (default the running op's actor, else engine.actor) */
|
|
1800
|
+
run(effect: any, opts?: { actor?: string }): any;
|
|
1678
1801
|
/** Place name -> position (load's places first, then level markers), null if none */
|
|
1679
1802
|
place(name: string): XZ | null;
|
|
1680
1803
|
/** Position form in content { place?, x?, z? } -> world coordinates */
|
|
@@ -1684,10 +1807,47 @@ export interface Content {
|
|
|
1684
1807
|
* template('chest').container.capacity
|
|
1685
1808
|
*/
|
|
1686
1809
|
template(name: string): Readonly<ContentTemplate>;
|
|
1810
|
+
/**
|
|
1811
|
+
* The fields one content entry may have (core/params.js spec format): what an editor panel lists and what content-check validates against.
|
|
1812
|
+
* name: a template name (placement fields plus its state fields, default = the value in state), an engine entry shape ('props', 'props.template',
|
|
1813
|
+
* 'props.grid', 'pickups', 'views'), a game kind that declares fields (content/rules.js kinds), or a world record id. Unknown names throw.
|
|
1814
|
+
* @example engine.content.fields('crop').stage // { type: 'int', optional: true, default: 0, min: 0, max: 4 }
|
|
1815
|
+
*/
|
|
1816
|
+
fields(name: string): Record<string, ContentField>;
|
|
1817
|
+
/**
|
|
1818
|
+
* Place a new runtime instance of a content template (inside an op or a fixed step), saved whole; returns the world record (kind = template name,
|
|
1819
|
+
* id `<template>#<n>` unless fields.id is given). fields: id, rot, scale, y (height above ground), items (container start goods), state fields
|
|
1820
|
+
* (stage too, for a template with stages).
|
|
1821
|
+
* @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id })
|
|
1822
|
+
*/
|
|
1823
|
+
spawn(name: string, at: any, fields?: { id?: string; rot?: number; scale?: number; y?: number; items?: Record<string, number>; [stateField: string]: any }): WorldRecord;
|
|
1824
|
+
}
|
|
1825
|
+
/** One stage of a template with stages: a named step it stays in for duration game seconds (clock.now), e.g. seed -> sprout -> ripe, cold -> armed */
|
|
1826
|
+
export interface ContentTemplateStage {
|
|
1827
|
+
name: string;
|
|
1828
|
+
/** Game seconds spent in this stage; only the last stage may leave it out (it stays there) */
|
|
1829
|
+
duration?: number;
|
|
1830
|
+
/** Multiplies the instance's scale while in this stage */
|
|
1831
|
+
scale?: number;
|
|
1832
|
+
/** Model name shown from this stage on (until a later stage names another); default the template's model */
|
|
1833
|
+
model?: string | any[];
|
|
1834
|
+
}
|
|
1835
|
+
/** template:stage event: a template instance entered a new stage by growing (several stages crossed at once give one event) */
|
|
1836
|
+
export interface TemplateStageEvent { id: string; template: string; stage: number; name: string }
|
|
1837
|
+
/** One field of a content entry (engine.content.fields): the core/params.js spec as plain data */
|
|
1838
|
+
export interface ContentField {
|
|
1839
|
+
type: 'string' | 'number' | 'int' | 'bool' | 'position' | 'id' | 'any' | 'object' | 'array' | 'function';
|
|
1840
|
+
optional?: boolean;
|
|
1841
|
+
/** Only for template state fields: the value written in state (never written inside fields) */
|
|
1842
|
+
default?: any;
|
|
1843
|
+
min?: number;
|
|
1844
|
+
max?: number;
|
|
1845
|
+
values?: any[];
|
|
1846
|
+
desc?: string;
|
|
1687
1847
|
}
|
|
1688
1848
|
/** A content template: shared definition of a reusable object (recipes/30-templates.md) */
|
|
1689
1849
|
export interface ContentTemplate {
|
|
1690
|
-
/** Model name (style
|
|
1850
|
+
/** Model name (style generator or assets name); every instance clones one shared prototype */
|
|
1691
1851
|
model: string | any[];
|
|
1692
1852
|
/** Collision box or circle from the model's bounds; omitted = does not block */
|
|
1693
1853
|
collide?: 'box' | 'circle';
|
|
@@ -1703,6 +1863,20 @@ export interface ContentTemplate {
|
|
|
1703
1863
|
animate?: (rec: WorldRecord, obj: Object3D, dt: number) => void;
|
|
1704
1864
|
/** Instance state fields and their defaults, copied onto each record (saved) */
|
|
1705
1865
|
state?: Record<string, any>;
|
|
1866
|
+
/**
|
|
1867
|
+
* Range / allowed values / description of state fields, checked on every placement and engine.content.spawn (dev) and by content-check. No default here:
|
|
1868
|
+
* the default is the value in state. The type is inferred from that value when left out. e.g. { stage: { type: 'int', min: 0, max: 4 } }
|
|
1869
|
+
*/
|
|
1870
|
+
fields?: Record<string, string | Omit<ContentField, 'default'>>;
|
|
1871
|
+
/**
|
|
1872
|
+
* Named stages over game time (a crop growing, a turret warming up, a building under construction). Each instance gets the state field stage
|
|
1873
|
+
* (default 0, int 0..n-1, placeable and saved) and stageAt (clock.now when it entered); it advances near and far, catching up after a load or a skip.
|
|
1874
|
+
*/
|
|
1875
|
+
stages?: ContentTemplateStage[];
|
|
1876
|
+
/** Asked every step, near and far; false holds the current stage and the time blocked does not count (e.g. rec => rec.watered) */
|
|
1877
|
+
canGrow?: (rec: WorldRecord, e: Engine) => boolean;
|
|
1878
|
+
/** Gameplay per fixed step while near (world.simulate near); write record fields directly or with world.set, both are saved */
|
|
1879
|
+
update?: (rec: WorldRecord, dt: number, e: Engine) => void;
|
|
1706
1880
|
}
|
|
1707
1881
|
|
|
1708
1882
|
// ======================================================================
|
|
@@ -1801,17 +1975,19 @@ export interface HudMarker {
|
|
|
1801
1975
|
/** Delete */
|
|
1802
1976
|
remove(): void;
|
|
1803
1977
|
}
|
|
1978
|
+
/** Screen corner / edge a counter or bar column sits at (default 'top-left'); each anchor stacks its own column */
|
|
1979
|
+
export type HudAnchor = 'top-left' | 'top' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right';
|
|
1804
1980
|
/** engine.hud: objective markers, counters, progress bars */
|
|
1805
1981
|
export interface Hud {
|
|
1806
1982
|
/** All markers */
|
|
1807
1983
|
markers: HudMarker[];
|
|
1808
1984
|
/** Add an objective marker: target is an object, position or place name */
|
|
1809
1985
|
marker(target: HudTarget, opts?: HudMarkerOptions): HudMarker;
|
|
1810
|
-
/** Counter (calling again with the same id = update; calling every frame is fine)
|
|
1811
|
-
counter(id: string, opts: { label?: string; icon?: string; value?: number; max?: number }): void;
|
|
1986
|
+
/** Counter or text status (calling again with the same id = update; calling every frame is fine): counter('fish', { label: '鱼', value: 2, max: 5 }), counter('clock', { value: '08:30' }); no value = the label alone */
|
|
1987
|
+
counter(id: string, opts: { label?: string; icon?: string; value?: number | string; max?: number; anchor?: HudAnchor }): void;
|
|
1812
1988
|
/** Progress bar (calling again with the same id = update; calling every frame is fine, the DOM is untouched when the value is unchanged),
|
|
1813
1989
|
* value/max 0–max */
|
|
1814
|
-
bar(id: string, opts: { value: number; max?: number; label?: string }): void;
|
|
1990
|
+
bar(id: string, opts: { value: number; max?: number; label?: string; anchor?: HudAnchor }): void;
|
|
1815
1991
|
/** Delete a counter or progress bar */
|
|
1816
1992
|
remove(id: string): void;
|
|
1817
1993
|
}
|