threedog 0.7.0 → 0.8.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{tier.js → scene/tier.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Performance panel + time/weather debugging
|
|
2
|
-
import {
|
|
1
|
+
// Performance panel + time/weather debugging. Collapsed by default; the action 'debugPanel' shows/hides it (presets.bindings.debug binds F3; debug({ open: true }) shows it at start). Quality, view distance and density are in the settings menu. Do not install this module in a release.
|
|
2
|
+
import { Vector2 } from 'three';
|
|
3
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
3
4
|
import { esc } from '../../ui/UI.js';
|
|
4
5
|
import { stats } from '../../render/backend.js';
|
|
5
6
|
/** @import { ModuleDef } from '../../types/core' */
|
|
@@ -11,9 +12,6 @@ export class DebugPanel {
|
|
|
11
12
|
/** @internal */
|
|
12
13
|
constructor(engine, { open = false } = {}) {
|
|
13
14
|
/** @internal */ this.engine = engine;
|
|
14
|
-
/** @internal */ this.bench = null;
|
|
15
|
-
/** Stress test running (player auto-runs fast) @type {boolean} */
|
|
16
|
-
this.benchmarking = false;
|
|
17
15
|
/** Panel root element @type {HTMLElement} */
|
|
18
16
|
this.el = document.createElement('div');
|
|
19
17
|
const el = this.el;
|
|
@@ -50,18 +48,16 @@ export class DebugPanel {
|
|
|
50
48
|
</div>
|
|
51
49
|
<div class="res k" data-k="budget" hidden></div>
|
|
52
50
|
<div class="res k" data-k="startup" hidden></div>
|
|
53
|
-
<details ${engine.renderer.getSize(new
|
|
51
|
+
<details ${engine.renderer.getSize(new Vector2()).x > 600 ? 'open' : ''}><summary>Debug</summary><div class="c">
|
|
54
52
|
<div class="r"><label>Time scale</label><input data-i="ts" type="range" min="0" max="60" step="1"><output data-o="ts"></output></div>
|
|
55
53
|
<div class="r"><label>Time</label><input data-i="tod" type="range" min="0" max="1" step="0.005"><output data-o="tod"></output></div>
|
|
56
54
|
<div class="r"><label>Weather</label><select data-s="weather" style="grid-column:span 2;font:inherit;background:#222;color:#eee;border:1px solid #444;border-radius:6px;padding:3px">
|
|
57
55
|
</select></div>
|
|
58
|
-
<button type="button" data-b="bench">20 s stress test</button>
|
|
59
|
-
<div class="res" data-k="bench"></div>
|
|
60
56
|
</div></details>`;
|
|
61
57
|
this.engine.uiRoot.appendChild(el);
|
|
62
58
|
const q = s => el.querySelector(s);
|
|
63
59
|
/** @internal */ this.out = {}; el.querySelectorAll('[data-k]').forEach(n => this.out[n.dataset.k] = n);
|
|
64
|
-
const e = engine
|
|
60
|
+
const e = engine;
|
|
65
61
|
// controls for modules that are not installed are hidden
|
|
66
62
|
const hideRow = k => { const i = q(`[data-i="${k}"]`); if (i) i.closest('.r').hidden = true; };
|
|
67
63
|
// time rows follow the calendar, not the sky: an indoor game without a sky still scrubs its clock
|
|
@@ -70,8 +66,7 @@ export class DebugPanel {
|
|
|
70
66
|
const bind = (k, get, set, fmt) => {
|
|
71
67
|
const i = q(`[data-i="${k}"]`), o = q(`[data-o="${k}"]`);
|
|
72
68
|
i.value = get(); o.textContent = fmt(get());
|
|
73
|
-
i.addEventListener('input', () => { o.textContent = fmt(+i.value);
|
|
74
|
-
if (k === 'dens') i.addEventListener('change', () => set(+i.value));
|
|
69
|
+
i.addEventListener('input', () => { o.textContent = fmt(+i.value); set(+i.value); });
|
|
75
70
|
return i;
|
|
76
71
|
};
|
|
77
72
|
if (e.calendar) {
|
|
@@ -85,36 +80,9 @@ export class DebugPanel {
|
|
|
85
80
|
ws.value = e.weather.name;
|
|
86
81
|
}
|
|
87
82
|
ws.onchange = () => { if (ws.value === 'auto') e.weather.setAuto(true); else { e.weather.setAuto(false); e.weather.set(ws.value, { seconds: 8 }); } };
|
|
88
|
-
q('[data-b="bench"]').onclick = () => this.startBench();
|
|
89
83
|
engine.i18n.add({ 'zh-CN': { 'debug.toggle': '调试面板' }, en: { 'debug.toggle': 'Debug panel' } }); // the settings menu's rebind page shows this name
|
|
90
84
|
}
|
|
91
85
|
|
|
92
|
-
/**
|
|
93
|
-
* Start the stress test (seconds, default 20): the character auto-runs fast, continuously loading new chunks, and a report is shown in the panel at the end
|
|
94
|
-
* @param {number} [seconds]
|
|
95
|
-
* @returns {void}
|
|
96
|
-
*/
|
|
97
|
-
startBench(seconds = 20) {
|
|
98
|
-
if (this.bench) return;
|
|
99
|
-
this.bench = { t: 0, dur: seconds, dts: [], built: 0 };
|
|
100
|
-
this.out.bench.textContent = 'Testing: character runs straight at 32 m/s, continuously loading new chunks...';
|
|
101
|
-
this.benchmarking = true; this.engine.input.autopilot = { x: 0, y: 1, speed: 32 }; this.engine.adaptive.paused = true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @internal */
|
|
105
|
-
frame(dt, built) {
|
|
106
|
-
if (!this.bench) return;
|
|
107
|
-
const b = this.bench; b.t += dt; b.dts.push(dt); b.built += built;
|
|
108
|
-
if (b.t < b.dur) return;
|
|
109
|
-
this.benchmarking = false; this.bench = null; this.engine.input.autopilot = null; this.engine.adaptive.paused = false;
|
|
110
|
-
const d = b.dts.slice().sort((x, y) => y - x), sum = b.dts.reduce((x, y) => x + y, 0);
|
|
111
|
-
const n1 = Math.max(1, Math.floor(d.length * 0.01)), worst = d.slice(0, n1).reduce((x, y) => x + y, 0) / n1;
|
|
112
|
-
const avg = b.dts.length / sum, low = 1 / worst, L = this.limits();
|
|
113
|
-
const cls = (v, lim) => lim == null ? '' : v >= lim ? 'ok' : v >= lim * 0.6 ? 'mid' : 'bad';
|
|
114
|
-
const w = this.engine.terrain;
|
|
115
|
-
this.out.bench.innerHTML = `${w ? `View distance ${w.viewChunks * w.CHUNK}m · Density ${w.density}×` : ''}\nAvg FPS <b class="${cls(avg, L.fps)}">${avg.toFixed(1)}</b>\n1% low FPS <b class="${cls(low, L.low1)}">${low.toFixed(1)}</b>\nLongest frame ${(d[0] * 1000).toFixed(1)} ms\nChunks built: ${b.built}`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
86
|
/** Budget limits (empty object if budget is off: numbers are not colored) @internal */
|
|
119
87
|
limits() { const b = this.engine.budget; return b.enabled ? { ...Object.fromEntries([...b.metrics].map(([k, m]) => [k, m.limit])), ...b.limits } : {}; }
|
|
120
88
|
|
|
@@ -150,7 +118,7 @@ export class DebugPanel {
|
|
|
150
118
|
const DEBUG_PANEL_PARAMS = keysSchema(['open']);
|
|
151
119
|
|
|
152
120
|
/**
|
|
153
|
-
* Debug panel -> engine.debug.panel: performance panel,
|
|
121
|
+
* Debug panel -> engine.debug.panel: performance panel, time and weather debugging. Collapsed by default; the action 'debugPanel' shows/hides it (presets.bindings.debug: F3); open: true shows it at start. Just do not install it in a release
|
|
154
122
|
* @param {{ open?: boolean }} [opts]
|
|
155
123
|
* @returns {ModuleDef<DebugPanel>}
|
|
156
124
|
*/
|
|
@@ -167,11 +135,10 @@ export function debug(opts = {}) {
|
|
|
167
135
|
},
|
|
168
136
|
dispose(e) { if (e.debug.panel === d) e.debug.panel = null; d?.el.remove(); },
|
|
169
137
|
frame(dt, e) { if (e.input.pressedRaw('debugPanel')) d.el.hidden = !d.el.hidden; },
|
|
170
|
-
// open matters to a screenshot (the panel covers a corner)
|
|
171
|
-
describe() { return { open: !d.el.hidden
|
|
138
|
+
// open matters to a screenshot (the panel covers a corner)
|
|
139
|
+
describe() { return { open: !d.el.hidden }; },
|
|
172
140
|
afterRender(dt, e) {
|
|
173
|
-
|
|
174
|
-
prof.n++; prof.t += dt; prof.cpu += e.cpuMs || 0;
|
|
141
|
+
prof.n++; prof.t += dt; prof.cpu += e._cpuMs || 0;
|
|
175
142
|
if (prof.t < 0.5) return;
|
|
176
143
|
const s = e.terrain?.stats || {}, info = stats(e.renderer);
|
|
177
144
|
d.stats({ fps: prof.n / prof.t, cpu: prof.cpu / prof.n, calls: info.drawCalls, tris: info.triangles, visible: s.visible ?? 0, loaded: s.loaded ?? 0, instances: s.instances ?? 0, apply: s.applyMs ?? 0, queued: s.queued ?? 0 });
|
package/modules/flow/contract.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// What any game-flow module must provide (fields: see gameplay/inventory.contract.js; shared check: @threedog/tools/contract).
|
|
2
|
-
// A state that stops the game holds engine.freeze('flow') (not engine.
|
|
2
|
+
// A state that stops the game holds engine.freeze('flow') (not engine.haltLoop), so describe().holds and the settings menu see who holds it.
|
|
3
3
|
export default {
|
|
4
4
|
name: 'flow',
|
|
5
5
|
api: ['define', 'go', 'transition'],
|
package/modules/flow/index.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
// engine.flow.go('paused'); engine.flow.state // 'paused'
|
|
6
6
|
// await engine.flow.transition(async () => engine.level.load('/models/town2.glb')); // lock input, fade out, load level, wait for ready, fade in
|
|
7
7
|
// Pause has one entry point: flow's 'paused' (internally engine.freeze('flow'); rendering continues); settings({ freezeWorld: true }) switches to it when the menu opens.
|
|
8
|
-
//
|
|
8
|
+
// engine.haltLoop() is another thing: it stops rendering too, for tests only. While frozen: fixed step, module fixed hooks, game clock, quest checks, timeline wait/tween all stop.
|
|
9
9
|
// engine.session.newGame / load / quit move flow too: back to the start state when a playthrough ends, then 'playing' when the next starts.
|
|
10
10
|
// Esc is not handled here: back goes through the UI focus stack (ui/Focus.js), and opens the settings menu when the stack is empty. Events: flow:change { from, to }, flow:transition { phase: 'start' | 'end' }.
|
|
11
|
-
import { warnMissing } from '../../core/validate.js';
|
|
12
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
|
+
import { warnMissing } from '../../core/base/validate.js';
|
|
12
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
13
13
|
import { fadeScreen } from '../../ui/UI.js';
|
|
14
|
+
import { unsettled } from '../../core/engine/headlessLoad.js';
|
|
14
15
|
/** @import { ModuleDef } from '../../types/core' */
|
|
15
16
|
/** @import { Flow, FlowOptions } from '../../types/gameplay' */
|
|
16
17
|
|
|
@@ -32,9 +33,9 @@ export function flow(opts = {}) {
|
|
|
32
33
|
if (def.freeze) { if (on) frozen ??= e.freeze('flow'); else { frozen?.remove(); frozen = null; } }
|
|
33
34
|
if (def.lockInput) { if (on) held ??= e.input.push('flow'); else { held?.remove(); held = null; } }
|
|
34
35
|
};
|
|
35
|
-
// wait until
|
|
36
|
-
const
|
|
37
|
-
const waitReady = () =>
|
|
36
|
+
// wait until the modules and the required nearby builds are ready (checked per engine frame, so step() advances it too)
|
|
37
|
+
const settled = () => !unsettled(e).length;
|
|
38
|
+
const waitReady = () => settled() ? Promise.resolve() : new Promise(res => { const h = e.onFrame(() => { if (settled()) { h.remove(); res(); } }); });
|
|
38
39
|
|
|
39
40
|
const api = {
|
|
40
41
|
/** Current state name */
|
|
@@ -87,7 +88,7 @@ export function flow(opts = {}) {
|
|
|
87
88
|
},
|
|
88
89
|
};
|
|
89
90
|
return {
|
|
90
|
-
name: 'flow', type: 'rules', params: FLOW_PARAMS, options: opts, label: 'Game flow', optional: ['music'],
|
|
91
|
+
name: 'flow', type: 'rules', provides: ['flow'], params: FLOW_PARAMS, options: opts, label: 'Game flow', optional: ['music'],
|
|
91
92
|
install(engine, ctx) { engine.i18n.add({ 'zh-CN': { 'module.flow': '游戏流程' }, en: { 'module.flow': 'game flow' } });
|
|
92
93
|
e = engine;
|
|
93
94
|
// initial state (title screen etc.): entered once the world is ready, so the game can define it after use()
|
|
@@ -100,7 +101,10 @@ export function flow(opts = {}) {
|
|
|
100
101
|
ctx.track(e.events.on('session:failed', () => { if (before) api.go(before); }));
|
|
101
102
|
return api;
|
|
102
103
|
},
|
|
104
|
+
// unloaded (unuse, replaces) in a state that stops the game: nothing else would ever end its freeze or input lock
|
|
105
|
+
dispose() { frozen?.remove(); held?.remove(); frozen = held = null; },
|
|
103
106
|
// ?play / applyState({ play }): leave the start state (a title) the way its Start button does; session:start then goes to 'playing'
|
|
107
|
+
stateKeys: ['play'],
|
|
104
108
|
applyState(e, { play }) { if (play != null && opts.start && opts.start !== 'playing' && api.state === opts.start) return e.session.newGame(); },
|
|
105
109
|
describe() { return { state: api.state, transitioning: api.transitioning }; },
|
|
106
110
|
};
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
// stackable ones with equal data share an entry, a stack-1 item is one entry per piece. Keys are unique across containers and kept when moved.
|
|
7
7
|
// Every method that takes an item also takes a key: count('sword') counts all swords, count('sword#3') only that one.
|
|
8
8
|
// Limits are optional: capacity (slots; an entry uses ceil(count / stack) slots) and maxWeight (sum of item weight × count). Locks and prices stay game rules.
|
|
9
|
-
import { fmt, DEV } from '../../core/validate.js';
|
|
10
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
|
-
import { failure } from '../../core/opsFail.js';
|
|
9
|
+
import { fmt, DEV } from '../../core/base/validate.js';
|
|
10
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
11
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
12
12
|
import { sig, freeze, canTrade, acceptsFrom, putIn, loadEntries } from './boxOps.js';
|
|
13
|
-
import { codedError } from '../../core/errorHints.js';
|
|
13
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
14
14
|
|
|
15
15
|
// Developer messages (warned once in DEV): add doesn't throw when full, which an AI would hardly notice
|
|
16
16
|
const STRINGS = {
|
|
@@ -41,8 +41,8 @@ export class Container {
|
|
|
41
41
|
count(x) { let n = 0; for (const e of this._entries) if (e.key === x || e.id === x) n += e.count; return n; }
|
|
42
42
|
/** At least n (default 1) of an item or key? @param {string} x @param {number} [n] @returns {boolean} */
|
|
43
43
|
has(x, n = 1) { return this.count(x) >= n; }
|
|
44
|
-
/** One entry by key: { key, id, count, data, def }, or
|
|
45
|
-
get(key) { const e = this._find(key); return e ? this._view(e) :
|
|
44
|
+
/** One entry by key: { key, id, count, data, def }, or undefined. @param {string} key */
|
|
45
|
+
get(key) { const e = this._find(key); return e ? this._view(e) : undefined; }
|
|
46
46
|
/** Every entry: [{ key, id, count, data, def }] (data is undefined for plain items; for custom UI). */
|
|
47
47
|
list() { return this._entries.map(e => this._view(e)); }
|
|
48
48
|
/** Slots used (an entry of 150 arrows with stack 99 uses 2). */
|
|
@@ -66,21 +66,22 @@ export class Container {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Add n (default 1) of an item, optionally with data for these pieces. Partial fit places what fits.
|
|
69
|
-
* Returns
|
|
70
|
-
* engine.actor, the local user's bag, toasts).
|
|
69
|
+
* Returns { ok: true, key, added }: key is the entry they went into ('arrow', or 'sword#3' for an item with data), added how many fit. None fit: { ok: false, code: 'full', facts: { id, n } }.
|
|
70
|
+
* silent suppresses the toast (only the container of engine.actor, the local user's bag, toasts).
|
|
71
71
|
* @example engine.inventory.container('chest-1').add('bandage', 2)
|
|
72
|
-
* @example const
|
|
72
|
+
* @example const r = engine.inventory.add('sword', 1, { data: { durability: 80, level: 3 } }); if (r.ok) equip(r.key); // r.key: 'sword#7'
|
|
73
73
|
* @param {string} id
|
|
74
74
|
* @param {number} [n]
|
|
75
75
|
* @param {{ data?: Record<string, any>, silent?: boolean }} [opts]
|
|
76
|
-
* @returns {string
|
|
76
|
+
* @returns {{ ok: boolean, key?: string, added?: number, code?: string, facts?: object, nextActions?: any[] }}
|
|
77
77
|
*/
|
|
78
78
|
add(id, n = 1, opts = {}) {
|
|
79
79
|
DEV && this.inv.engine.ops.guard(this._local ? 'inventory.add' : 'container.add');
|
|
80
80
|
readParams(`add('${id}')`, keysSchema(['data', 'silent']), opts);
|
|
81
81
|
if (isKey(id)) throw codedError('container', fmt(STRINGS.keyToAdd, { key: id }));
|
|
82
82
|
this.inv._known(id);
|
|
83
|
-
|
|
83
|
+
const before = this.count(id), key = this._put(id, n, copyData('add', id, opts?.data), null, !!opts?.silent);
|
|
84
|
+
return key === false ? failure({ code: 'full', facts: { id, n } }) : { ok: true, key, added: this.count(id) - before };
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Container table: implementation of inventory.container() / transfer() and the containers save part.
|
|
2
|
-
import { DEV } from '../../core/validate.js';
|
|
3
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
2
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
3
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
4
4
|
import { Container } from './Container.js';
|
|
5
|
-
import { codedError } from '../../core/errorHints.js';
|
|
5
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
6
6
|
|
|
7
7
|
/** Container table: implementation of inventory.container() / transfer(); bag is the home bag 'player' (saved as its own part, never removed). @internal */
|
|
8
8
|
export class Containers {
|
|
@@ -32,7 +32,8 @@ export class Containers {
|
|
|
32
32
|
this.map.set(id, c = new Container(this.inv, id, opts));
|
|
33
33
|
// place goods only on first creation; seeding is setup, so the ops guard lets it through
|
|
34
34
|
if (opts?.items) { c._start = { ...opts.items }; this._seed(c); }
|
|
35
|
-
} else { // container created first by a load, game code sets the limits afterwards; if it already exists, goods are not placed again
|
|
35
|
+
} else { // container created first by a load, game code sets the limits afterwards; if it already exists, goods are not placed again, but a later load of an older save needs them
|
|
36
|
+
if (opts?.items) c._start ??= { ...opts.items };
|
|
36
37
|
if (opts?.capacity != null) c.capacity = opts.capacity;
|
|
37
38
|
if (opts?.maxWeight != null) c.maxWeight = opts.maxWeight;
|
|
38
39
|
}
|
|
@@ -77,7 +78,15 @@ export class Containers {
|
|
|
77
78
|
/** @internal place a container's starting goods (content setup: the ops guard lets it through) */
|
|
78
79
|
_seed(c) {
|
|
79
80
|
c._entries = [];
|
|
80
|
-
this.inv.engine.ops.allow(() => {
|
|
81
|
+
this.inv.engine.ops.allow(() => {
|
|
82
|
+
for (const [item, n] of Object.entries(c._start)) {
|
|
83
|
+
const before = c.count(item);
|
|
84
|
+
c.add(item, n, { silent: true });
|
|
85
|
+
// a start list longer than the room is allowed (a game may start a shelf overfull on purpose), but the goods that did not fit are gone: say so once
|
|
86
|
+
const lost = n - (c.count(item) - before);
|
|
87
|
+
if (lost > 0) warnOnce(`inventory.container('${c.id}'): ${lost} of ${n} '${item}' in its starting items did not fit (capacity ${c.capacity}, maxWeight ${c.maxWeight}) and were not placed. Raise capacity or shorten items if they should all be there`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
81
90
|
c.seeded = true;
|
|
82
91
|
}
|
|
83
92
|
/** Save: non-player containers that have contents or ever had starting contents placed (an emptied one is still recorded, or a load would treat it as new and place them again) */
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
// Advancing and picking a choice are the ops dialogue.advance and dialogue.choose { index } (recipes/23-ops.md): keys, the cursor, clicks, the dev bridge and
|
|
21
21
|
// tests all run them, so a choice's do (which may change gameplay state) always runs inside a logged op.
|
|
22
22
|
import { uiFocus } from '../../ui/UI.js';
|
|
23
|
-
import { warnMissing, warnOnce } from '../../core/validate.js';
|
|
24
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
23
|
+
import { warnMissing, warnOnce, fmt } from '../../core/base/validate.js';
|
|
24
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
25
25
|
import { dialogueBox } from './dialogueBox.js';
|
|
26
|
-
import { codedError } from '../../core/errorHints.js';
|
|
26
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
27
27
|
import { Bubbles, bubblePart } from './dialogueBubbles.js';
|
|
28
28
|
// 'data' is the one slot for game-specific fields: other unknown keys stay typos (a misspelled next would silently end the dialogue)
|
|
29
29
|
const NODE_KEYS = ['text', 'next', 'choices', 'do', 'speaker', 'data'], CHOICE_KEYS = ['text', 'next', 'if', 'do', 'data'];
|
|
@@ -34,9 +34,8 @@ const STR = {
|
|
|
34
34
|
channel: "dialogue: channel '{got}' is not one of 'main' (the conversation the player reads, locks input) | 'bubble' (a line over its speaker while play goes on)",
|
|
35
35
|
bubbleChoices: "[dialogue] '{name}' node '{id}' has choices: choices need the main channel (the player picks them), so on the bubble channel the script ends there",
|
|
36
36
|
};
|
|
37
|
-
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', STR.channel
|
|
37
|
+
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', fmt(STR.channel, { got: String(c) })); };
|
|
38
38
|
const SAY_KEYS = ['speaker', 'node', 'channel', 'at', 'seconds', 'queue', 'onCancel'], START_KEYS = ['channel', 'at', 'onCancel'];
|
|
39
|
-
// 0.2 lock: false is now channel: 'bubble'; if not caught, old code would silently take the main channel and lock input (the opposite behavior), so name the new form first, then run the generic unknown-key check
|
|
40
39
|
const readLine = (fn, keys, o) => readParams(`dialogue.${fn}`, keysSchema(keys), o ?? {});
|
|
41
40
|
|
|
42
41
|
export class Dialogue {
|
|
@@ -44,7 +43,7 @@ export class Dialogue {
|
|
|
44
43
|
this.engine = engine;
|
|
45
44
|
this.scripts = new Map();
|
|
46
45
|
this.state = { get flags() { return engine.vars.flags; } }; // story flags = engine.vars.flags (autosaved)
|
|
47
|
-
this.
|
|
46
|
+
this.charsPerSecond = charsPerSecond;
|
|
48
47
|
// default: confirm only (a basic key). Other actions advance only when the game names them: advanceActions: ['confirm', 'interact']
|
|
49
48
|
this.advanceActions = advanceActions;
|
|
50
49
|
this.holdSeconds = holdSeconds;
|
|
@@ -95,7 +94,7 @@ export class Dialogue {
|
|
|
95
94
|
const step = id => {
|
|
96
95
|
const node = id && id !== 'end' && nodes[id];
|
|
97
96
|
if (!node || stopped) { finish(); return; }
|
|
98
|
-
if (node.choices?.length) { warnOnce(STR.bubbleChoices
|
|
97
|
+
if (node.choices?.length) { warnOnce(fmt(STR.bubbleChoices, { name, id })); finish(); return; }
|
|
99
98
|
const text = typeof node.text === 'function' ? node.text(this.state, this.engine) : node.text;
|
|
100
99
|
node.do?.(this.state, this.engine);
|
|
101
100
|
cur = this._bubbles.say(at, text, { speaker: node.speaker || (name.startsWith('__say_') ? '' : name), seconds, queue });
|
|
@@ -145,7 +144,9 @@ export class Dialogue {
|
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
_show(id) {
|
|
148
|
-
const a = this.active
|
|
147
|
+
const a = this.active;
|
|
148
|
+
if (!a) return; // a dialogue:start listener ended it
|
|
149
|
+
const node = id && a.nodes[id];
|
|
149
150
|
if (!node && id && id !== 'end') warnMissing('node', id, Object.keys(a.nodes)); // next points at a node that doesn't exist
|
|
150
151
|
if (!node || id === 'end') { this.end(); return; }
|
|
151
152
|
a.node = node; a.id = id;
|
|
@@ -156,7 +157,8 @@ export class Dialogue {
|
|
|
156
157
|
a.who = node.speaker || a.speaker;
|
|
157
158
|
this.full = String(text ?? ''); this.shown = 0; this.typing = true; this._opts = null;
|
|
158
159
|
this.engine.events.emit('dialogue:line', { script: a.speaker, node: id, speaker: a.who, text: this.full, data: node.data ?? {} });
|
|
159
|
-
if (
|
|
160
|
+
if (this.active !== a) return; // a dialogue:line listener ended it (a skip key)
|
|
161
|
+
if (!this.full || !(this.charsPerSecond > 0)) this._finishTyping(); // charsPerSecond 0 = whole line at once
|
|
160
162
|
else this._draw();
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -213,7 +215,7 @@ export class Dialogue {
|
|
|
213
215
|
const ops = this.engine.ops;
|
|
214
216
|
if (this.typing) {
|
|
215
217
|
const was = Math.floor(this.shown);
|
|
216
|
-
this.shown = Math.min(this.full.length, this.shown + dt * this.
|
|
218
|
+
this.shown = Math.min(this.full.length, this.shown + dt * this.charsPerSecond);
|
|
217
219
|
if (this.shown >= this.full.length) this._finishTyping();
|
|
218
220
|
else if (Math.floor(this.shown) !== was) this._draw(); // redraw only when another character shows
|
|
219
221
|
}
|
|
@@ -269,7 +271,7 @@ export function dialogue(opts = {}) {
|
|
|
269
271
|
if (!a && !bubbles.length) return;
|
|
270
272
|
const label = c => (typeof c.text === 'function' ? c.text(d.state, e) : c.text);
|
|
271
273
|
if (ctx.out.ui) {
|
|
272
|
-
if (a) ctx.out.ui.dialogue = { speaker: a.who, text: d.full, typing: d.typing, choices: (d._opts || []).map(label), selected: d._opts ? a.focus.index ?? 0 : -1 };
|
|
274
|
+
if (a) ctx.out.ui.dialogue = { speaker: a.who, text: d.full, typing: d.typing, choices: (d._opts || []).map(label), selected: d._opts ? a.focus.index ?? 0 : -1, advance: d.advanceActions.map(x => e.input.label(x)).join(' / ') };
|
|
273
275
|
if (bubbles.length) ctx.out.ui.bubbles = bubbles;
|
|
274
276
|
}
|
|
275
277
|
},
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// Using one is the op interaction.use { id?, action? } (recipes/23-ops.md): the interact key (in fixed), a click on the prompt, the dev bridge and tests all
|
|
5
5
|
// run it,
|
|
6
6
|
// so every use is logged and checked by the same can (exists, enabled, in range, input not locked). Without id it uses the one the actor would pick now.
|
|
7
|
-
// Who interacts is engine.actor (core/actor.js), measured with engine.actorPosition(): the player by default, a vehicle or squad member when the game says so;
|
|
7
|
+
// Who interacts is engine.actor (core/ops/actor.js), measured with engine.actorPosition(): the player by default, a vehicle or squad member when the game says so;
|
|
8
8
|
// the op's ctx.actor (a net peer, an NPC) is handed to label / enabled / onUse as (object, { actor }).
|
|
9
9
|
// How the one in front of you is chosen is the pick option: 'nearest' | 'facing' | 'aim' | a function (see interactions()). Each action is picked on its own,
|
|
10
10
|
// so one object can carry "Open" and "Lock" as two interactions with different action names (each bound to the game's own key).
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// once: true hides the object after a use that went through and it stays gone; counter: 'shells' adds 1 to that HUD counter (optional: engine.hud?.). So a
|
|
17
17
|
// mesh the game already built is a pick-and-count thing with no world record or bag; what was used is this module's save part, because a thing that comes
|
|
18
18
|
// back after a load while the count does not would be silently lost progress. Things that go in a bag, respawn or are decided by a net host: pickups.js.
|
|
19
|
-
// Finding candidates goes through one shared xz index (core/cells.js) keyed by each item's actual world position, instead of measuring every interaction
|
|
19
|
+
// Finding candidates goes through one shared xz index (core/stream/cells.js) keyed by each item's actual world position, instead of measuring every interaction
|
|
20
20
|
// each frame. Before a pick pass reads it, items that follow an object are re-filed if they moved: for an object straight under the scene (models, pickups,
|
|
21
21
|
// hand-placed meshes) the check is its local position against the last one seen, so a still crowd costs a few compares; a nested one (a part of a vehicle)
|
|
22
22
|
// is measured. Why the actual position and not the world record's: a game may move a record's model away from its record, and the item must be found where
|
|
@@ -26,11 +26,13 @@ import * as THREE from 'three';
|
|
|
26
26
|
import { worldToScreen } from '../../ui/UI.js';
|
|
27
27
|
import { promptPart } from './interactionPrompt.js';
|
|
28
28
|
|
|
29
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
30
|
-
import { codedError } from '../../core/errorHints.js';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
29
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
30
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
31
|
+
import { refuseSave } from '../../core/saves/saveValues.js';
|
|
32
|
+
import { isPlainObject } from '../../core/base/util.js';
|
|
33
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
34
|
+
import { vec3 } from '../../core/base/math.js';
|
|
35
|
+
import { Cells } from '../../core/stream/cells.js';
|
|
34
36
|
|
|
35
37
|
const PICKS = ['nearest', 'facing', 'aim'];
|
|
36
38
|
// 'facing': within 60° either side of where the actor faces (wide enough for a gamepad stick, narrow enough that doors behind you stay dark)
|
|
@@ -104,7 +106,7 @@ export class Interactions {
|
|
|
104
106
|
* approach: true walks the player there first (walkTo, stops 1.2 m away), then uses it. Returns a handle { remove() }.
|
|
105
107
|
* once: true hides the object after a use and it cannot be used again (onUse returning { ok: false } leaves it); saved, and back on a new game. The save
|
|
106
108
|
* knows it by id, else the object's name; development throws when it has neither. counter: name of a HUD counter that each use
|
|
107
|
-
* adds 1 to (hud.
|
|
109
|
+
* adds 1 to (hud.bump; nothing without hud()); declare it once at setup with hud.counter(name, { label, value: 0, max }), not on session:start.
|
|
108
110
|
* label, enabled and onUse are called with (object, { actor }): actor is the world record id of who asks / uses it (engine.actor for the local user,
|
|
109
111
|
* a net peer's or an NPC's id when they run interaction.use), so per-actor rules never read engine.player.
|
|
110
112
|
* @example engine.interactions.add(door, { label: (o, { actor }) => owns(actor) ? 'Open' : 'Knock', onUse: (o, { actor }) => engine.ops.run('door.open', { id: o.name }, { actor }) });
|
|
@@ -147,7 +149,7 @@ export class Interactions {
|
|
|
147
149
|
_run(it, actor) {
|
|
148
150
|
const r = it.onUse?.(it.object, { actor });
|
|
149
151
|
if (r?.ok === false) return r;
|
|
150
|
-
if (it.counter && this.engine.hud) { this.engine.hud.
|
|
152
|
+
if (it.counter && this.engine.hud) { this.engine.hud.bump(it.counter); this._counted.set(it.counter, (this._counted.get(it.counter) ?? 0) + 1); }
|
|
151
153
|
// shortcut: once lives on the local peer (interaction.use is net: 'local'); a thing all peers share in a net game is a pickup (the host decides)
|
|
152
154
|
if (it.once) { this._spent.add(it.id); it.object.visible = false; }
|
|
153
155
|
return r;
|
|
@@ -156,12 +158,15 @@ export class Interactions {
|
|
|
156
158
|
* @internal Load or new game. A counter gets the difference, not a value: its base is the game's (hud.counter(name, { value })), this module only knows
|
|
157
159
|
* what uses added. Only things whose state changed are shown or hidden: a once item the game hid itself stays hidden
|
|
158
160
|
*/
|
|
159
|
-
_load(
|
|
161
|
+
_load(d) {
|
|
162
|
+
const { spent, counted } = d ?? {};
|
|
163
|
+
if (!Array.isArray(spent) || !spent.every(id => typeof id === 'string') || !isPlainObject(counted) || !Object.values(counted).every(Number.isFinite))
|
|
164
|
+
refuseSave('interactions', 'the part', 'must be { spent: [id], counted: { id: number } }', d);
|
|
160
165
|
const was = this._spent; this._spent = new Set(spent);
|
|
161
166
|
for (const it of this._byId.values()) if (it.once && was.has(it.id) !== this._spent.has(it.id)) it.object.visible = !this._spent.has(it.id);
|
|
162
167
|
for (const name of new Set([...this._counted.keys(), ...Object.keys(counted)])) {
|
|
163
168
|
const d = (counted[name] ?? 0) - (this._counted.get(name) ?? 0);
|
|
164
|
-
if (d) this.engine.hud?.
|
|
169
|
+
if (d) this.engine.hud?.bump(name, d);
|
|
165
170
|
}
|
|
166
171
|
this._counted = new Map(Object.entries(counted));
|
|
167
172
|
}
|
|
@@ -219,8 +224,8 @@ export class Interactions {
|
|
|
219
224
|
return C;
|
|
220
225
|
}
|
|
221
226
|
|
|
222
|
-
/** The interaction with this id (
|
|
223
|
-
get(id) { return this._byId.get(id)
|
|
227
|
+
/** The interaction with this id (undefined if none). @param {string} id */
|
|
228
|
+
get(id) { return this._byId.get(id); }
|
|
224
229
|
/** All interactions in the order added (a fresh array each read) */
|
|
225
230
|
get items() { return [...this._byId.values()]; }
|
|
226
231
|
|
|
@@ -282,16 +287,23 @@ export class Interactions {
|
|
|
282
287
|
const c = fn(list, { engine: this.engine, actor, position: pos, action });
|
|
283
288
|
return c ? this.get(c.id) : null;
|
|
284
289
|
}
|
|
290
|
+
/** @internal The key went down and nothing was used: logged like a refused interaction.use, with the same codes. A record, not a warning: tapping E in a menu is normal play */
|
|
291
|
+
_pressRefused(action, reason) { const e = this.engine; e.ops.refused('interaction.use', { action, ...(reason === 'inputLocked' && { by: lockFacts(e).by }) }, { reason, actor: e.actor, source: 'player' }); }
|
|
285
292
|
/** Fixed step: each action's key fires that action's pick (input snapshot, frame-rate independent; picked on the spot, not from last frame). @internal */
|
|
286
293
|
fixed(dt) {
|
|
287
294
|
const inp = this.engine.input;
|
|
288
|
-
if (!inp.enabled) {
|
|
295
|
+
if (!inp.enabled) {
|
|
296
|
+
if (this._hold) this._interrupt('inputLocked');
|
|
297
|
+
// a press that does nothing still leaves a trace: an open dialogue swallowed every E, and the game's test could only report "have 0"
|
|
298
|
+
for (const a of this._actions.keys()) if (inp.pressedRaw(a)) this._pressRefused(a, 'inputLocked');
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
289
301
|
this._pass = ++this._passes;
|
|
290
302
|
if (this._hold) this._tickHold(dt);
|
|
291
303
|
for (const a of this._actions.keys()) {
|
|
292
304
|
if (!inp.pressed(a) || this._hold) continue;
|
|
293
305
|
const b = this.pick(undefined, a);
|
|
294
|
-
if (!b) continue;
|
|
306
|
+
if (!b) { this._pressRefused(a, 'nothingNear'); continue; }
|
|
295
307
|
if (b.hold > 0) { this._hold = { it: b, action: a, t: 0 }; this._holdView(); this.engine.events.emit('interaction:hold', { id: b.id, action: a, seconds: b.hold }); }
|
|
296
308
|
else this.engine.ops.run('interaction.use', { id: b.id }, { source: 'player' });
|
|
297
309
|
}
|
|
@@ -322,14 +334,14 @@ export class Interactions {
|
|
|
322
334
|
try { this._update(); } finally { this._pass = 0; }
|
|
323
335
|
}
|
|
324
336
|
/**
|
|
325
|
-
* @internal Dev: an interaction whose action has no key
|
|
326
|
-
*
|
|
327
|
-
* `await engine.start()` may still bind.
|
|
337
|
+
* @internal Dev: an interaction whose action has no key is reached by no key press, and nothing else would say so. A warning, not a throw: a click-only or touch-only
|
|
338
|
+
* game runs the op from its own code and is right, so this must not stop it (bind the action to [] to say so and the warning ends). Only once running: code right
|
|
339
|
+
* after `await engine.start()` may still bind. describe() keeps the note for every build.
|
|
328
340
|
*/
|
|
329
341
|
_checkKeys() {
|
|
330
342
|
this._keysDue = false;
|
|
331
343
|
for (const a of this._actions.keys()) {
|
|
332
|
-
if (this.engine.input.isUnbound(a))
|
|
344
|
+
if (this.engine.input.isUnbound(a)) warnOnce(coded('interaction-no-key', `interactions: action '${a}' has no key, so no key press reaches what was added to it. Add: ${bindLine(a)}. Reached by a click or your own code? engine.input.bind('${a}', []) says so`), `interaction-no-key:${a}`);
|
|
333
345
|
}
|
|
334
346
|
}
|
|
335
347
|
/** @internal */
|
|
@@ -427,8 +439,6 @@ function defineUse(e, i) {
|
|
|
427
439
|
const it = find(id, action, ctx);
|
|
428
440
|
if (!it) return id === undefined ? 'nothingNear' : 'unknown';
|
|
429
441
|
if (!it.enabled(it.object, { actor: ctx.actor })) return 'disabled';
|
|
430
|
-
// the local player only: a net peer or an NPC does not go through this page's keys. The bridge and tests are refused too, so `ops` never shows a ✓ no player can do
|
|
431
|
-
if (ctx.actor === e.actor && e.input.isUnbound(it.action)) return { code: 'noKey', facts: { action: it.action, fix: bindLine(it.action) } };
|
|
432
442
|
if (ctx.actor === e.actor && !e.input.enabled) return { code: 'inputLocked', facts: lockFacts(e) };
|
|
433
443
|
if (it.approach && !walkerOf(e, ctx.actor)) return 'cannotWalk';
|
|
434
444
|
const p = e.actorPosition(ctx.actor);
|
|
@@ -445,10 +455,13 @@ function defineUse(e, i) {
|
|
|
445
455
|
if (!it.approach) return i._run(it, ctx.actor);
|
|
446
456
|
const ch = walkerOf(e, ctx.actor), q = it.object.getWorldPosition(new THREE.Vector3());
|
|
447
457
|
if (Math.hypot(q.x - ch.position.x, q.z - ch.position.z) <= APPROACH_ARRIVE + 0.3) return i._run(it, ctx.actor);
|
|
458
|
+
// the game holds this character on the walk's layer: 'cannot walk now' is an answer, and from the key press in a fixed step a throw would freeze play
|
|
459
|
+
let walk; try { walk = ch.walkTo(q, { arrive: APPROACH_ARRIVE }); } catch (err) { if (err?.code === 'control-conflict') return { ok: false, code: 'cannotWalk' }; throw err; }
|
|
448
460
|
// used after arrival, so checked again then: removed or disabled while walking = not used
|
|
449
|
-
return { approaching:
|
|
461
|
+
return { approaching: walk.then(r => r.status === 'arrived' && !it._gone && it.enabled(it.object, { actor: ctx.actor }) ? e.ops.allow(() => i._run(it, ctx.actor)) : r) }; // allow: the op ended steps ago, the use is still its own
|
|
450
462
|
},
|
|
451
|
-
|
|
452
|
-
|
|
463
|
+
// no key: the op still runs when code asks (a click-only game), but it is not offered, so `ops` shows no ✓ for what no key reaches; describe() says why
|
|
464
|
+
offers(e, ctx) { const it = find(undefined, undefined, ctx); return it && !(ctx.actor === e.actor && e.input.isUnbound(it.action)) ? [{ id: it.id }] : []; },
|
|
465
|
+
reasons: { unknown: 'No interaction with this id', nothingNear: 'No interaction in range', disabled: 'Its enabled() is false', tooFar: 'Actor is outside its radius', cannotWalk: 'approach walks the player; this actor has no character to walk', inputLocked: 'A title, window, dialogue or cutscene locks input; facts.by names it' },
|
|
453
466
|
});
|
|
454
467
|
}
|
|
@@ -6,19 +6,19 @@
|
|
|
6
6
|
// inventory.define('fish', { name: '鲫鱼', icon: '🐟', iconUrl: '/textures/fish.png', desc: '河里钓的', stack: 20, weight: 0.5 });
|
|
7
7
|
// inventory.add('fish', 2); inventory.has('fish', 1); inventory.remove('fish'); // the local user's bag (engine.actor)
|
|
8
8
|
// inventory.of(ctx.actor).add('fish'); // inside an op: the bag of whoever runs it (a net peer, an NPC)
|
|
9
|
-
// One piece with its own data: const key = inventory.add('sword', 1, { data: { durability: 80 } }); // 'sword#1'; count('sword') counts every sword
|
|
9
|
+
// One piece with its own data: const { key } = inventory.add('sword', 1, { data: { durability: 80 } }); // 'sword#1'; count('sword') counts every sword
|
|
10
10
|
// Chest / corpse / shelf: inventory.container('chest-1', { capacity: 8 }).add('fish'); inventory.transfer('chest-1', 'player', 'fish', 2);
|
|
11
11
|
// Player actions with items are ops: inventory.transfer / inventory.use / inventory.drop (inventoryOps.js).
|
|
12
12
|
//
|
|
13
13
|
// Picture:
|
|
14
14
|
// window UI part 'inventory' (engine.ui.set('inventory', false | { drop: true } | yourPart)); body via ui.templates.inventory(data, { esc, t, icon })
|
|
15
15
|
// list styling CSS classes .threedog-win-inventory .threedog-row ... (override in ui.css)
|
|
16
|
-
import { checkOptions, warnMissing, freezeDef } from '../../core/validate.js';
|
|
17
|
-
import { readParams } from '../../core/params.js';
|
|
18
|
-
import { codedError } from '../../core/errorHints.js';
|
|
16
|
+
import { checkOptions, warnMissing, freezeDef } from '../../core/base/validate.js';
|
|
17
|
+
import { readParams } from '../../core/base/params.js';
|
|
18
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
19
19
|
import { Container } from './Container.js';
|
|
20
20
|
import { Containers } from './Containers.js';
|
|
21
|
-
import { followRuntimeIds } from '../../core/saveIds.js';
|
|
21
|
+
import { followRuntimeIds } from '../../core/saves/saveIds.js';
|
|
22
22
|
import { inventoryWindow, windowData, defineInventoryOps, INVENTORY_STRINGS } from './inventoryOps.js';
|
|
23
23
|
|
|
24
24
|
export class Inventory {
|
|
@@ -160,12 +160,11 @@ export class Inventory {
|
|
|
160
160
|
* @param {{ takeN?: number, giveN?: number, data?: Record<string, any>, silent?: boolean }} [opts]
|
|
161
161
|
*/
|
|
162
162
|
trade(take, give, opts) { return this.bag.trade(take, give, opts); }
|
|
163
|
-
get slotsUsed() { return this.bag.slotsUsed; }
|
|
164
163
|
/** Player inventory entries: [{ key, id, count, data, def }] (for custom UI). */
|
|
165
164
|
list() { return this.bag.list(); }
|
|
166
|
-
/** One player inventory entry by key: { key, id, count, data, def } or
|
|
165
|
+
/** One player inventory entry by key: { key, id, count, data, def } or undefined. */
|
|
167
166
|
get(key) { return this.bag.get(key); }
|
|
168
|
-
/** Add n (default 1) to the player inventory, opts { data, silent }; returns
|
|
167
|
+
/** Add n (default 1) to the player inventory, opts { data, silent }; returns { ok: true, key, added }, or { ok: false, code: 'full' } when none fit. */
|
|
169
168
|
add(id, n = 1, opts) { return this.bag.add(id, n, opts); }
|
|
170
169
|
/** Remove n (default 1) of an item or entry key from the player inventory; returns false if not enough. */
|
|
171
170
|
remove(id, n = 1) { return this.bag.remove(id, n); }
|
|
@@ -214,7 +213,7 @@ export function inventory(opts = {}) {
|
|
|
214
213
|
describe(e) {
|
|
215
214
|
const show = c => Object.fromEntries(c._entries.map(x => [x.key, x.data === undefined ? x.count : { count: x.count, data: x.data }]));
|
|
216
215
|
const boxes = Object.fromEntries([...inv._containers.map].filter(([, c]) => c !== inv.bag && c._entries.length).map(([id, c]) => [id, show(c)]));
|
|
217
|
-
return { items: show(inv.bag), slots: inv.capacity === Infinity ? `${inv.slotsUsed}` : `${inv.slotsUsed}/${inv.capacity}`, ...(inv.bag.weight && { weight: `${inv.bag.weight}/${inv.bag.maxWeight}` }), ...(Object.keys(boxes).length && { containers: boxes }) };
|
|
216
|
+
return { items: show(inv.bag), slots: inv.capacity === Infinity ? `${inv.bag.slotsUsed}` : `${inv.bag.slotsUsed}/${inv.capacity}`, ...(inv.bag.weight && { weight: `${inv.bag.weight}/${inv.bag.maxWeight}` }), ...(Object.keys(boxes).length && { containers: boxes }) };
|
|
218
217
|
},
|
|
219
218
|
};
|
|
220
219
|
}
|