threedog 0.5.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 +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- 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} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- 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} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- 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} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- 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} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- 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} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -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} +24 -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/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- 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 +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- 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 +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -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 +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- 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 +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- 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 +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- 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 +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- 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 +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- 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 +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -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 +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- 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 +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- 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 +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- 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 +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- 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 +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- 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 +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- 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 +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- 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/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- 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/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- 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 +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- 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 +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -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 +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /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/{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
|
@@ -10,31 +10,37 @@
|
|
|
10
10
|
// some games turn that into a bag entry. And who touches it is any actor: the local user, a net peer on the host, an NPC; the item goes into that actor's
|
|
11
11
|
// container, never a fixed 'player' bag. Taking is the op pickup.take (net: 'peer'), so a client's press is sent to the host and the host decides.
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
// gray box;
|
|
13
|
+
// Picture: shape = a model name from an asset pack: model option or the item's define(id, { model }), else a model named 'pickup:<item>', else 'pickup', else a
|
|
14
|
+
// gray box; pickups({ color, size, lift }) for the plain values; engine.pickups.material is the three.js material the box and geometry-only models draw with;
|
|
15
|
+
// spawn(pos, { mesh }) puts the game's own object down instead.
|
|
15
16
|
import * as THREE from 'three';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
17
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
18
|
+
import { copyPatches, isEngineMade, markEngineMade } from '../../render/patches.js';
|
|
19
|
+
import { xzOf, yOf } from '../../core/base/math.js';
|
|
20
|
+
import { placeY } from '../../core/scene/ground.js';
|
|
21
|
+
import { warnOnce, needMaterial, fmt } from '../../core/base/validate.js';
|
|
22
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
21
23
|
import { copyData } from './Container.js';
|
|
22
|
-
import { failure } from '../../core/opsFail.js';
|
|
23
|
-
import { protoOf } from '../../core/namedModel.js';
|
|
24
|
-
import { shadowDefaults } from '../../core/assetEntry.js';
|
|
25
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
24
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
25
|
+
import { protoOf } from '../../core/assets/namedModel.js';
|
|
26
|
+
import { shadowDefaults } from '../../core/assets/assetEntry.js';
|
|
27
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
26
28
|
|
|
27
29
|
const STRINGS = { 'zh-CN': { 'module.pickups': '拾取物', 'pickups.take': '捡起 {name}' }, en: { 'module.pickups': 'pickups', 'pickups.take': 'Pick up {name}' } };
|
|
28
30
|
const SPAWN_KEYS = ['give', 'count', 'data', 'name', 'model', 'color', 'mesh', 'respawnSeconds', 'bob', 'id', 'initial', 'zone', 'radius', 'auto'];
|
|
29
|
-
const STYLE_KEYS = ['color', 'size', 'lift'];
|
|
30
31
|
const NO_ACTORS = [];
|
|
32
|
+
const DEFAULT_COLOR = 0xcccccc;
|
|
31
33
|
// A net host measures peers at the position they last sent (a few steps old): pickup.take allows this much beyond the radius so a fair press is not refused
|
|
32
34
|
const NET_SLACK = 1;
|
|
33
35
|
|
|
34
36
|
export class Pickups {
|
|
35
37
|
/** @internal track: the module's ctx.track */
|
|
36
|
-
constructor(engine, { radius
|
|
38
|
+
constructor(engine, { radius, showDistance, takers, color, size, lift }, track) {
|
|
37
39
|
this.engine = engine;
|
|
40
|
+
/** Edge of the placeholder box (meters), read when one is built */ this.size = size;
|
|
41
|
+
/** Height above the ground new pickups float at (meters) */ this.lift = lift;
|
|
42
|
+
/** @internal */ this._material = neutralMaterial('pickup', { color });
|
|
43
|
+
/** @internal copies of the material for a pickup's own color or a vertex-colored geometry: 'color' or 'color:vc' -> material */ this._copies = new Map();
|
|
38
44
|
/** Reach of pickups that set no radius (meters); auto pickups are taken within it */ this.radius = radius;
|
|
39
45
|
/** @internal pickups float, spin and have a model only within this distance of the stream sources */ this.showDistance = showDistance;
|
|
40
46
|
/**
|
|
@@ -58,6 +64,27 @@ export class Pickups {
|
|
|
58
64
|
present(this);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The three.js material of every placeholder box and geometry-only model. Set it to swap the look of all of them at once; it is used as given, with no patches added.
|
|
69
|
+
* A pickup with a color of its own (spawn({ color }), inventory.define(id, { color })) or a vertex-colored geometry draws with a copy of it carrying that color.
|
|
70
|
+
* A file model and a generator's own Object3D keep their materials.
|
|
71
|
+
* @example engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a, metalness: 0.8, roughness: 0.3 });
|
|
72
|
+
* @type {THREE.Material}
|
|
73
|
+
*/
|
|
74
|
+
get material() { return this._material; }
|
|
75
|
+
set material(m) {
|
|
76
|
+
needMaterial('pickup-misuse', 'engine.pickups.material', m, '. Example: engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a })');
|
|
77
|
+
const old = this._material;
|
|
78
|
+
if (m === old) return;
|
|
79
|
+
this._material = m;
|
|
80
|
+
for (const c of this._copies.values()) c.dispose();
|
|
81
|
+
this._copies.clear();
|
|
82
|
+
if (isEngineMade(old)) old.dispose(); // a material the game gave stays the game's
|
|
83
|
+
const w = this.engine.world;
|
|
84
|
+
// only what is built now: a pickup out of reach has no model, and one built later asks for the current material
|
|
85
|
+
for (const r of w.query({ kind: 'pickup' })) w.view(r.id)?.traverse(o => { if (o.userData.pickupColor !== undefined) /** @type {any} */ (o).material = pickupMaterial(this, o); });
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
/**
|
|
62
89
|
* Place a pickup at position. give: an item id (goes into the picker's container, inventory.of(actor); needs inventory()) or a function
|
|
63
90
|
* (e, { actor, pickup }) => result for an instant effect (heal, score, power-up; no inventory needed). Returning { ok: false, code } (failure(code)) leaves it
|
|
@@ -85,16 +112,15 @@ export class Pickups {
|
|
|
85
112
|
if (item && !e.inventory) throw codedError('pickup-misuse', `pickups.spawn({ give: '${item}' }): an item pickup goes into the picker's container, so it needs inventory() installed; for an instant effect pass give: (e, { actor }) => ...`);
|
|
86
113
|
const [x, z] = xzOf(position);
|
|
87
114
|
// a given y is the reference height on multi-layer ground (as snapToGround): a pickup on a bridge deck or a second floor stays there; without one it sits on the top layer
|
|
88
|
-
const p = /** @type {any} */ (position).isObject3D ? /** @type {any} */ (position).position : position, refY = Array.isArray(p) ? p[1] : p.y;
|
|
89
115
|
const { count = 1, mesh = null, respawnSeconds = 0, bob = true, id, initial = false, zone, radius, auto = false, name, model: m, color } = opts;
|
|
90
116
|
const what = item ?? name ?? 'pickup';
|
|
91
117
|
if (radius != null && !(radius > 0)) throw codedError('pickup-misuse', `pickups.spawn('${what}'): radius must be a positive number of meters, got ${radius}`);
|
|
92
118
|
const data = copyData('pickups.spawn', what, opts.data);
|
|
93
119
|
const def = { id, kind: 'pickup', ...(item && { item }), count, bob, ...(data && { data }), ...(name != null && { name }), ...(m != null && { model: m }), ...(color != null && { color }),
|
|
94
120
|
...(radius != null && { radius }), ...(auto && { auto: true }), ...(respawnSeconds > 0 && { respawn: respawnSeconds }), ...(zone != null && { zone }),
|
|
95
|
-
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z,
|
|
121
|
+
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z, yOf(position)) + this.lift, z] };
|
|
96
122
|
const rec = initial ? w.add(def, { initial }) : id != null && w.get(id) || w.add(def); // initial data: world decides whether it exists / was deleted from the save (null)
|
|
97
|
-
if (rec && (rec.kind !== 'pickup' || (rec.item ?? null) !== item)) throw codedError('
|
|
123
|
+
if (rec && (rec.kind !== 'pickup' || (rec.item ?? null) !== item)) throw codedError('world-id', `pickup id '${id}' is already used by other data (${rec.kind}${rec.item ? ' ' + rec.item : ''}): use a different id`);
|
|
98
124
|
const wid = rec?.id ?? id;
|
|
99
125
|
if (mesh || !item) this._live.set(wid, { mesh, give: item ? null : give });
|
|
100
126
|
return { id: wid, give, get object() { return w.view(wid); }, remove: () => { w.remove(wid); this._live.delete(wid); } };
|
|
@@ -121,12 +147,12 @@ export class Pickups {
|
|
|
121
147
|
*/
|
|
122
148
|
_take(rec, actor) {
|
|
123
149
|
const e = this.engine, W = e.world;
|
|
124
|
-
let value;
|
|
150
|
+
let value, left = 0;
|
|
125
151
|
if (rec.item) {
|
|
126
152
|
if (!e.inventory) return failure('noInventory');
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
value = key;
|
|
153
|
+
const put = e.inventory.of(actor).add(rec.item, rec.count, rec.data && { data: rec.data });
|
|
154
|
+
if (!put.ok) return put;
|
|
155
|
+
value = put.key; left = rec.count - (put.added ?? rec.count); // a bag with room for part of it: the rest stays on the ground
|
|
130
156
|
} else {
|
|
131
157
|
const fn = this._live.get(rec.id)?.give;
|
|
132
158
|
if (!fn) { warnOnce(`pickups: '${rec.id}' gives with a function, which is not saved data; spawn it again with the same id after a load (content and setup code do)`); return failure('noGive'); }
|
|
@@ -134,9 +160,10 @@ export class Pickups {
|
|
|
134
160
|
if (value && value.ok === false) return value;
|
|
135
161
|
}
|
|
136
162
|
// without respawn the record is deleted; with respawn time it gets until (show tears down the model), saved so the countdown continues after a load
|
|
137
|
-
if (
|
|
163
|
+
if (left > 0) W.set(rec.id, { count: left });
|
|
164
|
+
else if (rec.respawn > 0) W.set(rec.id, { until: e.clock.now + rec.respawn });
|
|
138
165
|
else W.remove(rec.id); // world:remove drops the live parts
|
|
139
|
-
e.events.emit('pickup:take', { pickup: rec.id, item: rec.item ?? null, count: rec.count, actor, x: rec.position.x, z: rec.position.z });
|
|
166
|
+
e.events.emit('pickup:take', { pickup: rec.id, item: rec.item ?? null, count: rec.count - left, actor, x: rec.position.x, z: rec.position.z });
|
|
140
167
|
return { ok: true, value };
|
|
141
168
|
}
|
|
142
169
|
|
|
@@ -160,7 +187,7 @@ export class Pickups {
|
|
|
160
187
|
|
|
161
188
|
const inReach = (rec, p, r) => { const dx = rec.position.x - p.x, dy = rec.position.y - (p.y ?? 0), dz = rec.position.z - p.z; return dx * dx + dy * dy + dz * dz <= r * r; };
|
|
162
189
|
|
|
163
|
-
/** Register how pickups
|
|
190
|
+
/** Register how pickups picture and respawn (once, on install) @internal */
|
|
164
191
|
function present(pk) {
|
|
165
192
|
const e = pk.engine, w = e.world;
|
|
166
193
|
w.present('pickup', {
|
|
@@ -172,7 +199,7 @@ function present(pk) {
|
|
|
172
199
|
const t = e.time.now('real'), x = rec.position.x;
|
|
173
200
|
o.rotation.y = t * 1.5 + x; o.position.y = rec.position.y + Math.sin(t * 2 + x) * 0.08;
|
|
174
201
|
},
|
|
175
|
-
// only detached: a game's mesh is the game's, a model clone shares geometry / material with its prototype (protoOf),
|
|
202
|
+
// only detached: a game's mesh is the game's, a model clone shares geometry / material with its prototype (protoOf), the material is shared by every pickup;
|
|
176
203
|
// the placeholder box is the one thing built here alone, so its geometry is freed
|
|
177
204
|
dispose: (rec, o) => { o.userData.useHandle?.remove(); e.detach(o); o.traverse(c => { if (c.userData.ownGeometry) /** @type {any} */ (c).geometry.dispose(); }); },
|
|
178
205
|
});
|
|
@@ -182,18 +209,17 @@ function present(pk) {
|
|
|
182
209
|
}
|
|
183
210
|
|
|
184
211
|
// A pickup's shape goes one way only: a model name from assets (same protoOf as content props / templates: file or code-generated, cache, bake and shadow rules are identical).
|
|
185
|
-
// Name order: the pickup's own model -> the item definition's model -> 'pickup:<item id>' in assets -> 'pickup' -> neutral grey-box placeholder (warns once).
|
|
212
|
+
// Name order: the pickup's own model -> the item definition's model -> 'pickup:<item id>' in assets -> 'pickup' -> neutral grey-box placeholder (warns once).
|
|
186
213
|
const NO_PICKUP = "pickups: no model for '{item}', so it lies on the ground as a gray box (a placeholder). Register a model in an asset pack and name it: "
|
|
187
214
|
+ "pickups.spawn(p, { model: 'gem' }) / inventory.define('{item}', { model: 'gem' }), or call the model 'pickup:{item}' (this item) / 'pickup' (every pickup without its own)";
|
|
188
215
|
const NO_NAME = "pickups: '{item}' has model '{model}', but no asset pack registers a model of that name (engine.assets.manifest({ models: { {model}: fn | '/models/{model}.glb' } })); using the gray placeholder box";
|
|
189
|
-
const fill = (t, o) => t.replace(/\{(\w+)\}/g, (_, k) => o[k]);
|
|
190
216
|
/** Which model name a pickup shows (its own model, else the item's, else 'pickup:<item>' / 'pickup'), or null for the placeholder @internal */
|
|
191
217
|
function pickupModelName(e, item, model) {
|
|
192
218
|
const has = n => { const x = e.assets.entries.get(n); return !!x?.named && x.type === 'model'; };
|
|
193
219
|
const what = item ?? 'pickup';
|
|
194
|
-
if (typeof model === 'string') { if (has(model)) return model; warnOnce(
|
|
220
|
+
if (typeof model === 'string') { if (has(model)) return model; warnOnce(fmt(NO_NAME, { item: what, model })); return null; }
|
|
195
221
|
for (const n of item ? ['pickup:' + item, 'pickup'] : ['pickup']) if (has(n)) return n;
|
|
196
|
-
warnOnce(
|
|
222
|
+
warnOnce(fmt(NO_PICKUP, { item: what }));
|
|
197
223
|
return null;
|
|
198
224
|
}
|
|
199
225
|
/**
|
|
@@ -202,21 +228,21 @@ function pickupModelName(e, item, model) {
|
|
|
202
228
|
* file models must download and generators may read the dev cache, and none of that should make "a pickup nearby" appear a frame late.
|
|
203
229
|
*/
|
|
204
230
|
function model(pk, rec) {
|
|
205
|
-
const e = pk.engine, def = rec.item && e.inventory ? e.inventory.item(rec.item) : {}
|
|
231
|
+
const e = pk.engine, def = rec.item && e.inventory ? e.inventory.item(rec.item) : {};
|
|
206
232
|
let obj = pk._live.get(rec.id)?.mesh;
|
|
207
233
|
if (obj) obj.castShadow = true; // a mesh the game passed in stays the game's; only made to cast
|
|
208
234
|
else {
|
|
209
|
-
const color = rec.color ?? def.color ??
|
|
235
|
+
const color = rec.color ?? def.color ?? null, name = pickupModelName(e, rec.item ?? null, rec.model ?? def.model), holder = new THREE.Group();
|
|
210
236
|
holder.name = name ?? 'pickup'; holder.userData.name = holder.name; obj = holder;
|
|
211
237
|
const box = () => { // the neutral placeholder: also what a model that failed to build falls back to
|
|
212
|
-
const size =
|
|
213
|
-
m.userData.ownGeometry = true; holder.add(m);
|
|
238
|
+
const size = pk.size, m = shadowDefaults(new THREE.Mesh(new THREE.BoxGeometry(size, size, size)), {});
|
|
239
|
+
m.userData.ownGeometry = true; drawnBy(pk, m, color); holder.add(m);
|
|
214
240
|
};
|
|
215
241
|
if (!name) box();
|
|
216
242
|
else protoOf(e, pk, name).then(proto => {
|
|
217
243
|
const o = proto.obj.clone(); // geometry / materials stay the prototype's (shadow flags were settled once there, as for content props)
|
|
218
|
-
// generator gave only geometry:
|
|
219
|
-
if (proto.fromGeometry)
|
|
244
|
+
// generator gave only geometry: draw it with the pickups material in the item's own color (same color shares one); generators that return a full Object3D / file models stay as they are
|
|
245
|
+
if (proto.fromGeometry) drawnBy(pk, o, color);
|
|
220
246
|
holder.add(o);
|
|
221
247
|
}).catch(err => { warnOnce(`pickups: model '${name}' of '${rec.item ?? rec.id}' failed to build (${err?.message ?? err}); showing the gray placeholder box`); box(); });
|
|
222
248
|
}
|
|
@@ -233,12 +259,22 @@ function model(pk, rec) {
|
|
|
233
259
|
return obj;
|
|
234
260
|
}
|
|
235
261
|
|
|
236
|
-
/**
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
262
|
+
/** Mark a mesh as drawn by the pickups material (color: its own, or null) and give it that material @internal */
|
|
263
|
+
function drawnBy(pk, mesh, color) { mesh.userData.pickupColor = color; mesh.material = pickupMaterial(pk, mesh); }
|
|
264
|
+
|
|
265
|
+
/** The material of one marked mesh: pk.material itself, or a copy shared by every pickup of that color (and vertex colors or not) @internal */
|
|
266
|
+
function pickupMaterial(pk, mesh) {
|
|
267
|
+
const color = mesh.userData.pickupColor, vc = !!mesh.geometry.attributes.color, base = pk.material;
|
|
268
|
+
if (color == null && !vc) return base;
|
|
269
|
+
const key = color + (vc ? ':vc' : '');
|
|
270
|
+
if (!pk._copies.has(key)) {
|
|
271
|
+
const m = copyPatches(base, base.clone());
|
|
272
|
+
if (color != null) /** @type {any} */ (m).color?.set(color);
|
|
273
|
+
if (vc) m.vertexColors = true;
|
|
274
|
+
if (isEngineMade(base)) markEngineMade(m);
|
|
275
|
+
pk._copies.set(key, m);
|
|
276
|
+
}
|
|
277
|
+
return pk._copies.get(key);
|
|
242
278
|
}
|
|
243
279
|
|
|
244
280
|
/** The op pickup.take { id }: the interact key, auto pickups, a net peer's request, the dev bridge and tests all run it, as ctx.actor @internal */
|
|
@@ -269,12 +305,15 @@ const PICKUP_PARAMS = {
|
|
|
269
305
|
radius: { type: 'number', default: 2, min: 0, desc: 'reach of pickups that set no radius (meters); auto pickups are taken within it' },
|
|
270
306
|
showDistance: { type: 'number', default: 60, min: 0, desc: 'pickups have a model, float and spin only within this distance of the stream sources (meters)' },
|
|
271
307
|
takers: { type: 'any', optional: true, desc: 'e => actor ids that walk into auto pickups (default engine.actor, plus net peers on a host)' },
|
|
308
|
+
color: { type: 'any', default: DEFAULT_COLOR, desc: 'color of the placeholder box and geometry-only models when the pickup and its item set none' },
|
|
309
|
+
size: { type: 'number', default: 0.25, min: 0, desc: 'edge of the placeholder box (meters)' },
|
|
310
|
+
lift: { type: 'number', default: 0.4, desc: 'height above the ground a pickup floats at (meters)' },
|
|
272
311
|
};
|
|
273
312
|
|
|
274
313
|
/**
|
|
275
314
|
* Pickups module: things on the ground that give whoever takes them an item (into that actor's container) or an instant effect. Installs engine.pickups and
|
|
276
315
|
* the op pickup.take. Needs world() first; interactions() for the key prompt (auto: true pickups need none); inventory() only for give: itemId.
|
|
277
|
-
* Options: radius (default reach, 2 m), showDistance (60 m), takers (who walks into auto pickups).
|
|
316
|
+
* Options: radius (default reach, 2 m), showDistance (60 m), takers (who walks into auto pickups), color, size, lift (the placeholder's plain values); engine.pickups.material for the picture.
|
|
278
317
|
* @example engine.use(openWorld(), interactions({ ...presets.interactions.nearest }), inventory(), pickups())
|
|
279
318
|
* @example engine.use(world(), pickups({ radius: 1 })) // coins and health packs only: auto pickups with give functions, no inventory, no prompt
|
|
280
319
|
*/
|
|
@@ -285,9 +324,7 @@ export function pickups(opts = {}) {
|
|
|
285
324
|
name: 'pickups', type: 'rules', label: 'Pickups', params: PICKUP_PARAMS, options: o, requires: ['world'], optional: ['interactions', 'inventory', 'net'], stage: 'gameplay',
|
|
286
325
|
noSkip: 'auto pickups are spatial; respawn follows the game clock',
|
|
287
326
|
install(e, ctx) {
|
|
288
|
-
|
|
289
|
-
if (e.style.pickup) readParams('style.pickup', keysSchema(STYLE_KEYS), e.style.pickup);
|
|
290
|
-
pk = new Pickups(e, opts, ctx.track); defineTake(e, pk); return pk;
|
|
327
|
+
pk = new Pickups(e, o, ctx.track); defineTake(e, pk); return pk; // o: the schema defaults are filled in, the class repeats none
|
|
291
328
|
},
|
|
292
329
|
fixed() { pk._auto(); },
|
|
293
330
|
describe(e, ctx) { // use the model if present (same object the interactions module reports, merged into one entry); far away only data
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The quest log window as the UI part 'questLog'. Quests keeps the behavior through engine.ui (the J key toggles it; open = UI focus stack, input lock,
|
|
2
2
|
// Esc closes, ui:open / ui:close 'questLog'); the part only draws { title, key, quests, close() }. Replace it or turn it off with engine.ui.set('questLog', ...).
|
|
3
|
-
// Default
|
|
3
|
+
// Default picture: a .threedog-win window; its body can be replaced by ui.templates.quests({ quests }, { esc, t }) or restyled via .threedog-quest*.
|
|
4
4
|
import { injectUICSS, esc } from '../../ui/UI.js';
|
|
5
5
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
6
6
|
/** @import { QuestLogView } from '../../types/gameplay' */
|
|
@@ -25,7 +25,7 @@ function questLogPart(engine) {
|
|
|
25
25
|
const draw = v => {
|
|
26
26
|
if (!w) { w = document.createElement('div'); w.className = 'threedog-ui threedog-win threedog-win-quests'; engine.uiRoot.appendChild(w); }
|
|
27
27
|
w.hidden = false;
|
|
28
|
-
const tpl = engine.
|
|
28
|
+
const tpl = engine.ui.templates.quests;
|
|
29
29
|
w.innerHTML = `<div class="threedog-win-head"><span>${esc(v.title)}</span><span><span class="threedog-win-hint">${esc(v.key)}</span> <button class="threedog-btn threedog-close" type="button">${esc(engine.t('common.close'))}</button></span></div>${tpl ? tpl(v, tools) : body(v)}`;
|
|
30
30
|
w.querySelector('.threedog-close').onclick = () => v.close();
|
|
31
31
|
};
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// A step's (or parallel part's) id is its `id` field (quests.define / content: steps: [{ id: 'talk-mayor', text, done }]), else its position as text
|
|
5
5
|
// ('0', '1', ...): give steps ids before shipping, then edits to the step list never move a player's progress.
|
|
6
6
|
// Version 1 saved positions: migrateV1 maps them to ids through the quest definitions known when the save is loaded.
|
|
7
|
-
import { warnOnce } from '../../core/validate.js';
|
|
8
|
-
import { coded } from '../../core/errorHints.js';
|
|
7
|
+
import { warnOnce, fmt } from '../../core/base/validate.js';
|
|
8
|
+
import { coded } from '../../core/base/errorHints.js';
|
|
9
9
|
|
|
10
10
|
const STRINGS = {
|
|
11
11
|
missing: "quests: the save has quest '{q}' at step '{step}', which its definition no longer has; it restarts from the first step. Keep step ids stable, or add a migrate step to the 'quests' save part",
|
|
@@ -44,7 +44,7 @@ export function toSaved(def, s) {
|
|
|
44
44
|
*/
|
|
45
45
|
export function fromSaved(id, def, q) {
|
|
46
46
|
let step = q.done ? def.steps.length : indexOf(def, q.step);
|
|
47
|
-
if (step < 0) { warnOnce(coded('quest-step', STRINGS.missing
|
|
47
|
+
if (step < 0) { warnOnce(coded('quest-step', fmt(STRINGS.missing, { q: id, step: String(q.step) }))); step = 0; }
|
|
48
48
|
const s = { step, done: !!q.done };
|
|
49
49
|
if (q.failed) s.failed = true;
|
|
50
50
|
const st = def.steps[step];
|
package/modules/grid/Grid.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// mapping is one replaceable pair (grids.add({ mapping })), so a game with another lattice swaps two functions instead of every caller's math.
|
|
8
8
|
// A footprint is anchored at its min corner cell; rotation is in quarter turns (0-3) and odd turns swap width and depth.
|
|
9
9
|
import { Layer } from './Layer.js';
|
|
10
|
-
import { xzOf } from '../../core/math.js';
|
|
10
|
+
import { xzOf } from '../../core/base/math.js';
|
|
11
11
|
|
|
12
12
|
/** The default occupancy layer of an item that names none */
|
|
13
13
|
export const MAIN = 'main';
|
package/modules/grid/Layer.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// Version 1 saved every cell whole; its step turns that into { set, whole: true } (cells not listed are empty, whatever content authors now).
|
|
7
7
|
// Writes are saved gameplay state, so they pass the ops guard like world.set (write inside an op or a fixed step).
|
|
8
8
|
// _ver counts changes so views (tiles) rebuild only when something changed, without events.
|
|
9
|
-
import { DEV } from '../../core/validate.js';
|
|
10
|
-
import { codedError } from '../../core/errorHints.js';
|
|
9
|
+
import { DEV, needMaterial } from '../../core/base/validate.js';
|
|
10
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
11
11
|
|
|
12
12
|
const key = (i, j) => i + ',' + j;
|
|
13
13
|
const plainErr = (where, v) => `${where}: layer data must be plain values (numbers, strings, booleans, arrays, plain objects); got ${v?.constructor?.name ?? typeof v}. Keep models in tiles / world.present`;
|
|
@@ -42,6 +42,19 @@ export class Layer {
|
|
|
42
42
|
/** @internal 'i,j' -> authored data (content/grids.js layers): what the save diffs against */ this._base = new Map();
|
|
43
43
|
/** @internal the last save diff applied, so a baseline set after the load (content after the save) still gets it */ this._diff = null;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The three.js material of this layer's tiles (null when it draws none: a data layer, tiles: false or your own part). Set it to swap the picture, used as given.
|
|
47
|
+
* Tile colors are vertex colors, so a material with vertexColors: true shows them; without it, its own color covers every tile.
|
|
48
|
+
* @example field.layer('soil').material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 });
|
|
49
|
+
* @type {import('three').Material | null}
|
|
50
|
+
*/
|
|
51
|
+
get material() { return this.grid._owner._tiles.get(this)?.mesh?.material ?? null; }
|
|
52
|
+
set material(m) {
|
|
53
|
+
const mesh = this.grid._owner._tiles.get(this)?.mesh;
|
|
54
|
+
if (!mesh) throw codedError('grids-misuse', `layer '${this.name}'.material: this layer draws no default tiles; give it a picture first: grid.layer('${this.name}', { tiles: true })`);
|
|
55
|
+
needMaterial('grids-misuse', `layer '${this.name}'.material`, m);
|
|
56
|
+
mesh.material = m;
|
|
57
|
+
}
|
|
45
58
|
/** @internal */
|
|
46
59
|
_guard(what) { DEV && this.grid.engine.ops.guard(`grid layer ${this.grid.name}.${this.name}.${what}`); }
|
|
47
60
|
/**
|
|
@@ -138,6 +151,6 @@ export class Layer {
|
|
|
138
151
|
|
|
139
152
|
/**
|
|
140
153
|
* Options of grid.layer(name, opts)
|
|
141
|
-
* @typedef {{ tiles?: boolean | {
|
|
154
|
+
* @typedef {{ tiles?: boolean | { color?: (data: Record<string, any>, cell: [number, number]) => any, colors?: Record<string, number | string>, lift?: number }
|
|
142
155
|
* | ((engine: any, layer: Layer) => { update?: (cells: { cell: [number, number], data: Record<string, any> }[]) => void, dispose?: () => void }) }} LayerOptions
|
|
143
156
|
*/
|
package/modules/grid/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// Where state lives (nothing is stored twice):
|
|
7
7
|
// placed things -> world records with a `grid` field (saved by world); occupancy is an index rebuilt from them (world:add / change / remove / load)
|
|
8
8
|
// per-cell layers -> Layer maps, saved here under the save key 'grids' (version 2) as a per-cell diff against the authored cells (Layer.js)
|
|
9
|
+
// Picture: grids({ ok, bad, previewOpacity, previewHeight, tiles, tileLift }) for the plain values, pv.material and layer.material for the three.js materials.
|
|
9
10
|
// The index is the "don't go around it" check: in dev a record's grid field is frozen (editing it in place throws), writes outside ops
|
|
10
11
|
// trigger the ops guard, and a record whose footprint overlaps another one is reported with the fix.
|
|
11
12
|
import { Grid, MAIN, occKey } from './Grid.js';
|
|
@@ -15,11 +16,11 @@ import { defineGridOps, placed } from './ops.js';
|
|
|
15
16
|
|
|
16
17
|
/** Grids save part: version 1 stored every cell of a layer whole ([[i, j, data]]); version 2 stores a diff against the authored cells (Layer.js) */
|
|
17
18
|
const GRIDS_MIGRATE = { 1: d => Object.fromEntries(Object.entries(d || {}).map(([g, ls]) => [g, Object.fromEntries(Object.entries(ls || {}).map(([n, rows]) => [n, { set: rows, whole: true }]))])) };
|
|
18
|
-
import { closest, DEV, warnOnce } from '../../core/validate.js';
|
|
19
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
20
|
-
import { failure } from '../../core/opsFail.js';
|
|
19
|
+
import { closest, DEV, warnOnce, fmt } from '../../core/base/validate.js';
|
|
20
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
21
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
21
22
|
import { STRINGS as TEXT } from './strings.js';
|
|
22
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
23
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
23
24
|
|
|
24
25
|
const STRINGS = {
|
|
25
26
|
dup: "grids.add('{name}'): a grid with this name exists",
|
|
@@ -28,7 +29,6 @@ const STRINGS = {
|
|
|
28
29
|
orphan: "[engine] grid '{grid}': {id} is a '{item}', which this content no longer defines; it is kept in the save but takes no cells. Define '{item}' again (engine.grids.define) to bring it back, or remove it with engine.ops.run('grid.remove', { id })",
|
|
29
30
|
overlap: "[engine] grid '{grid}': {id} overlaps {other} at cell {cell}; the cell stays with {other}. Place things with engine.ops.run('grid.place', ...) / 'grid.move', which check can() first",
|
|
30
31
|
};
|
|
31
|
-
const fmt = (s, v) => s.replace(/\{(\w+)\}/g, (_, k) => v[k] ?? '');
|
|
32
32
|
const hint = (n, list) => { const c = closest(n, list); return c ? ` (did you mean '${c}'?)` : ''; };
|
|
33
33
|
const freeze = p => { Object.freeze(p.cell); Object.freeze(p.size); return Object.freeze(p); };
|
|
34
34
|
|
|
@@ -41,9 +41,19 @@ const freeze = p => { Object.freeze(p.cell); Object.freeze(p.size); return Objec
|
|
|
41
41
|
* @experimental
|
|
42
42
|
*/
|
|
43
43
|
export class Grids {
|
|
44
|
-
/**
|
|
45
|
-
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* @param {any} e
|
|
47
|
+
* @param {GridsOptions} o
|
|
48
|
+
*/
|
|
49
|
+
constructor(e, o) {
|
|
46
50
|
/** @internal */ this.engine = e;
|
|
51
|
+
/** Preview color where it can be placed, read when a preview is made @type {any} */ this.ok = o.ok;
|
|
52
|
+
/** Preview color where it cannot be placed, read when a preview is made @type {any} */ this.bad = o.bad;
|
|
53
|
+
/** Opacity of the preview box, read when a preview is made */ this.previewOpacity = o.previewOpacity;
|
|
54
|
+
/** Height of the preview box (meters), read when a preview is made */ this.previewHeight = o.previewHeight;
|
|
55
|
+
/** Tile colors by layer name, { layer: { field: color } } (first truthy field of a cell wins), read when a layer is made @type {Record<string, Record<string, any>>} */ this.tiles = o.tiles;
|
|
56
|
+
/** Height of tiles above the ground (meters), read when a layer is made */ this.tileLift = o.tileLift;
|
|
47
57
|
/** @internal */ this._grids = new Map();
|
|
48
58
|
/** @internal */ this._defs = new Map();
|
|
49
59
|
/** @internal id -> { g, keys } */ this._byId = new Map();
|
|
@@ -77,11 +87,11 @@ export class Grids {
|
|
|
77
87
|
return g;
|
|
78
88
|
}
|
|
79
89
|
/**
|
|
80
|
-
* A grid by name, or
|
|
90
|
+
* A grid by name, or undefined when there is none
|
|
81
91
|
* @param {string} name
|
|
82
|
-
* @returns {Grid |
|
|
92
|
+
* @returns {Grid | undefined}
|
|
83
93
|
*/
|
|
84
|
-
get(name) { return this._grids.get(name)
|
|
94
|
+
get(name) { return this._grids.get(name); }
|
|
85
95
|
/** @internal A grid by name; throws with the names that exist */
|
|
86
96
|
_must(name) {
|
|
87
97
|
const g = this._grids.get(name);
|
|
@@ -131,16 +141,16 @@ export class Grids {
|
|
|
131
141
|
}
|
|
132
142
|
/**
|
|
133
143
|
* Show where an item would go: the target cell under the pointer ('pointer', default), in front of the player ('front') or from your
|
|
134
|
-
* function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors;
|
|
135
|
-
*
|
|
144
|
+
* function, turned by the input action rotate (default name 'rotate'; the game binds it, e.g. presets.bindings.gridRotate; the engine binds no key itself), light when can() passes, dark otherwise (neutral tool colors; grids({ ok, bad }) override them).
|
|
145
|
+
* draw: false = no visual; (engine) => ({ update(view), hide(), dispose() }) = your own; pv.material is the default box's three.js material. place() runs grid.place with what is shown
|
|
136
146
|
* @example engine.input.bind({ place: ['Mouse0'], ...presets.bindings.gridRotate }); // the game's own bindings
|
|
137
147
|
* const pv = engine.grids.preview({ grid: 'field', item: 'tower' });
|
|
138
148
|
* engine.onFrame(() => { if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.code)); } });
|
|
139
|
-
* @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number,
|
|
149
|
+
* @param {{ grid: string, item: string, from?: 'pointer' | 'front' | ((e: any) => any), rotate?: string | false, rotation?: number, draw?: false | ((e: any) => any) }} opts
|
|
140
150
|
* @returns {{ cell: [number, number] | null, rotation: number, ok: boolean, code: string | null, rotate(n?: number): void, place(fields?: object): { ok: boolean, value?: any, code?: string }, remove(): void }}
|
|
141
151
|
*/
|
|
142
152
|
preview(opts) {
|
|
143
|
-
readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', '
|
|
153
|
+
readParams('grids.preview()', keysSchema(['grid', 'item', 'from', 'rotate', 'rotation', 'draw']), opts);
|
|
144
154
|
return makePreview(this.engine, this, opts);
|
|
145
155
|
}
|
|
146
156
|
|
|
@@ -148,11 +158,11 @@ export class Grids {
|
|
|
148
158
|
_layerAdded(l) {
|
|
149
159
|
const d = this._loaded?.[l.grid.name]?.[l.name];
|
|
150
160
|
if (d) l.fromJSON(d);
|
|
151
|
-
const t = layerTiles(this.engine, l);
|
|
161
|
+
const t = layerTiles(this.engine, l, this);
|
|
152
162
|
if (t) this._tiles.set(l, t);
|
|
153
163
|
}
|
|
154
164
|
/** @internal a layer's options changed after content created it: rebuild its tiles */
|
|
155
|
-
_retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l); if (t) this._tiles.set(l, t); }
|
|
165
|
+
_retile(l) { this._tiles.get(l)?.dispose(); this._tiles.delete(l); const t = layerTiles(this.engine, l, this); if (t) this._tiles.set(l, t); }
|
|
156
166
|
/** @internal */
|
|
157
167
|
_index(rec) {
|
|
158
168
|
const p = rec.grid, g = this._grids.get(p.id);
|
|
@@ -223,19 +233,37 @@ export class Grids {
|
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
235
|
|
|
236
|
+
// tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot)
|
|
237
|
+
const GRID_PARAMS = {
|
|
238
|
+
ok: { type: 'any', default: 0xe0e0e0, desc: 'preview color where it can be placed' },
|
|
239
|
+
bad: { type: 'any', default: 0x3a3a3a, desc: 'preview color where it cannot be placed' },
|
|
240
|
+
previewOpacity: { type: 'number', default: 0.45, min: 0, max: 1, desc: 'opacity of the preview box' },
|
|
241
|
+
previewHeight: { type: 'number', default: 0.08, min: 0, desc: 'height of the preview box (meters)' },
|
|
242
|
+
tiles: { type: 'any', default: {}, desc: 'tile colors by layer name: { layer: { field: color } }, first truthy field of a cell wins; a layer named here draws tiles' },
|
|
243
|
+
tileLift: { type: 'number', default: 0.03, desc: 'height of tiles above the ground (meters)' },
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Options of grids()
|
|
247
|
+
* @typedef {{ ok?: any, bad?: any, previewOpacity?: number, previewHeight?: number, tiles?: Record<string, Record<string, any>>, tileLift?: number }} GridsOptions
|
|
248
|
+
*/
|
|
249
|
+
|
|
226
250
|
/**
|
|
227
251
|
* Grid placement module: installed as engine.grids. Needs world(). Adds the ops grid.place / grid.remove / grid.move and the save key 'grids' (layers).
|
|
252
|
+
* Options: ok, bad, previewOpacity, previewHeight (the preview box), tiles, tileLift (layer tiles). The materials are pv.material and layer.material.
|
|
228
253
|
* @example engine.use(world(), grids())
|
|
254
|
+
* @example engine.use(world(), grids({ ok: 0x66dd88, bad: 0xdd5544, tiles: { soil: { watered: 0x5b3d2a, tilled: 0x8a6243 } } }))
|
|
255
|
+
* @param {GridsOptions} [opts]
|
|
229
256
|
* @returns {import('../../types/core').ModuleDef<Grids>}
|
|
230
257
|
* @experimental
|
|
231
258
|
*/
|
|
232
|
-
export function grids() {
|
|
259
|
+
export function grids(opts = {}) {
|
|
260
|
+
const o = readParams('grids', GRID_PARAMS, opts);
|
|
233
261
|
let G = null, offOps = null;
|
|
234
262
|
const subs = [];
|
|
235
263
|
return {
|
|
236
|
-
name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'],
|
|
264
|
+
name: 'grids', type: 'world', label: 'Grid placement', stage: 'gameplay', requires: ['world'], params: GRID_PARAMS, options: o,
|
|
237
265
|
install(e) {
|
|
238
|
-
G = new Grids(e);
|
|
266
|
+
G = new Grids(e, o);
|
|
239
267
|
e.i18n.add(TEXT); // grid.<code> player text for every built-in failure code, and the rotate action's label
|
|
240
268
|
e.saves.register('grids', { atomic: true, version: 2, migrate: GRIDS_MIGRATE, save: () => G.toJSON(), load: d => G.fromJSON(d) });
|
|
241
269
|
offOps = defineGridOps(e, G);
|
package/modules/grid/preview.js
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
// Placement preview (engine.grids.preview): picks the target cell every frame (under the pointer, in front of the player, or from
|
|
2
2
|
// your function), keeps a rotation turned by an input action, asks can(), and shows a see-through footprint
|
|
3
|
-
// (
|
|
4
|
-
// The
|
|
3
|
+
// (grids({ ok, bad }) colors). It never changes gameplay state: place() runs the grid.place op with what it shows.
|
|
4
|
+
// The picture is a replaceable part: draw: false (no visual, the handle still answers), or (engine) => ({ update(view), hide(), dispose() }); pv.material is the default box's.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
|
-
import {
|
|
7
|
-
import { screenToGround } from '../../core/screenToGround.js';
|
|
8
|
-
import { warnOnce } from '../../core/validate.js';
|
|
9
|
-
import { failure } from '../../core/opsFail.js';
|
|
6
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
7
|
+
import { screenToGround } from '../../core/scene/screenToGround.js';
|
|
8
|
+
import { warnOnce, needMaterial, fmt } from '../../core/base/validate.js';
|
|
9
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
10
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
10
11
|
|
|
11
|
-
// tool colors, not art: neutral defaults that still tell the two apart (light = can place, dark = cannot); a style may override them
|
|
12
|
-
const OK = 0xe0e0e0, BAD = 0x3a3a3a;
|
|
13
12
|
const NO_KEY = 'grids.preview(): the action "{a}" has no keys, so the preview cannot be turned by input. Bind it (engine.input.bind("{a}", ["KeyR"]) or presets.bindings.gridRotate), or pass rotate: false and call pv.rotate() from your own control';
|
|
14
13
|
|
|
15
|
-
/** Default
|
|
16
|
-
function
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), mat);
|
|
14
|
+
/** Default picture: a flat translucent box over the footprint @internal */
|
|
15
|
+
function boxPart(e, st) {
|
|
16
|
+
const own = neutralMaterial('decal', { transparent: true, opacity: st.previewOpacity, depthWrite: false });
|
|
17
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), own);
|
|
20
18
|
mesh.name = 'grid:preview'; mesh.visible = false; mesh.renderOrder = 2;
|
|
21
19
|
e.add(mesh, { owner: 'engine:grid' });
|
|
22
|
-
const ok = new THREE.Color(st.ok
|
|
20
|
+
const ok = new THREE.Color(st.ok), bad = new THREE.Color(st.bad), h = st.previewHeight;
|
|
23
21
|
return {
|
|
22
|
+
get material() { return mesh.material; },
|
|
23
|
+
set material(m) {
|
|
24
|
+
needMaterial('grids-misuse', 'pv.material', m);
|
|
25
|
+
mesh.material = m;
|
|
26
|
+
},
|
|
24
27
|
update(v) {
|
|
25
28
|
mesh.visible = true;
|
|
26
29
|
mesh.scale.set(v.size[0] - 0.04, h, v.size[1] - 0.04);
|
|
27
30
|
mesh.position.set(v.center.x, v.center.y + h / 2, v.center.z);
|
|
28
|
-
|
|
31
|
+
/** @type {any} */ (mesh.material).color?.copy(v.ok ? ok : bad); // telling can from cannot is the preview's job, on any material that has a color
|
|
29
32
|
},
|
|
30
33
|
hide() { mesh.visible = false; },
|
|
31
|
-
dispose() { e.remove(mesh); mesh.geometry.dispose();
|
|
34
|
+
dispose() { e.remove(mesh); mesh.geometry.dispose(); own.dispose(); }, // a material the game set stays the game's
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -46,17 +49,23 @@ function target(e, from, g) {
|
|
|
46
49
|
|
|
47
50
|
/** Create a preview handle @internal */
|
|
48
51
|
export function makePreview(e, grids, opts) {
|
|
49
|
-
const { grid, item, from = 'pointer', rotate = 'rotate',
|
|
52
|
+
const { grid, item, from = 'pointer', rotate = 'rotate', draw } = opts;
|
|
50
53
|
const g = grids._must(grid), rule = grids._rule(item);
|
|
51
54
|
// declared by the preview, owned by the grid module and taken away with the preview (or the module), so nothing outlives it; the game binds
|
|
52
55
|
// the key (presets.bindings.gridRotate) like every module action
|
|
53
56
|
const decl = rotate ? e.input.action(rotate, { label: 'grid.rotate', owner: 'grids', optional: true }) : null;
|
|
54
|
-
if (rotate && !e.input.keysOf(rotate).length) warnOnce(NO_KEY
|
|
55
|
-
const part =
|
|
57
|
+
if (rotate && !e.input.keysOf(rotate).length) warnOnce(fmt(NO_KEY, { a: rotate }));
|
|
58
|
+
const part = draw === false ? null : typeof draw === 'function' ? draw(e) : boxPart(e, grids);
|
|
56
59
|
const h = {
|
|
57
60
|
/** target cell or null (nothing under the pointer) */ cell: null,
|
|
58
61
|
rotation: opts.rotation ?? 0,
|
|
59
62
|
/** why it cannot be placed: 'noTarget' or the grid.can() code; null when ok */ ok: false, code: 'noTarget',
|
|
63
|
+
/** The default box's three.js material (null with draw: false or your own part). Set it to swap the picture, used as given; its color still shows ok / bad */
|
|
64
|
+
get material() { return part?.material ?? null; },
|
|
65
|
+
set material(m) {
|
|
66
|
+
if (!part || !('material' in part)) throw codedError('grids-misuse', "pv.material: this preview has draw: false or your own part, so it draws no default box");
|
|
67
|
+
part.material = m;
|
|
68
|
+
},
|
|
60
69
|
/** Turn by quarter turns (the rotate action does this too) */
|
|
61
70
|
rotate(n = 1) { h.rotation = (((h.rotation + n) % 4) + 4) % 4; },
|
|
62
71
|
/** Run grid.place with the shown cell and rotation; returns the op result */
|
|
@@ -65,7 +74,7 @@ export function makePreview(e, grids, opts) {
|
|
|
65
74
|
return e.ops.run('grid.place', { grid, item, cell: h.cell, rotation: h.rotation, ...(fields ? { fields } : {}) });
|
|
66
75
|
},
|
|
67
76
|
/** Remove the preview (cancel convention: safe to call again) */
|
|
68
|
-
remove() { grids._previews.delete(h); decl?.remove(); part?.dispose?.(); },
|
|
77
|
+
remove() { if (!grids._previews.delete(h)) return; decl?.remove(); part?.dispose?.(); },
|
|
69
78
|
/** @internal */
|
|
70
79
|
frame() {
|
|
71
80
|
if (rotate && e.input.pressed(rotate)) h.rotate(1);
|