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
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
# UI parts: replace or turn off any piece of the engine's screen UI
|
|
2
2
|
|
|
3
|
+
**In this recipe**: Reskin · 1. Pick at start · 2. Your own part · 3. Toasts · 4. Dialogue box · The choice cursor · 5. Title screen · 6. Settings menu · 7. Keys, UI that follows the world
|
|
4
|
+
|
|
3
5
|
Every piece of UI the engine draws is a named **part** with a plain default:
|
|
4
6
|
`loading`, `toast`, `title` (off by default), `touch` (on-screen stick and buttons),
|
|
5
7
|
`hud.marker`, `hud.counter`, `hud.bar`, `dialogue`, `prompt` ("E · Talk"), `questLog`, `inventory` (with the inventory module).
|
|
6
8
|
The engine keeps the behavior (when to show, the UI focus stack and Esc, input lock, i18n); a part only draws the data it gets.
|
|
7
9
|
Each name takes one value: `false` off · `true` default · `{ ...options }` default with options ·
|
|
8
10
|
`(engine, options) => ({ show, update, hide, dispose })` your own (any verb may be omitted).
|
|
9
|
-
Only want different colors / layout? Use
|
|
11
|
+
Only want different colors / layout? Use "Reskin" below, not a new part.
|
|
12
|
+
|
|
13
|
+
## Reskin: your picture on every default part, in one place
|
|
14
|
+
The default parts are neutral gray on purpose. About ten lines give all of them the game's picture; do this before writing a dialogue box or HUD of your own:
|
|
15
|
+
```js
|
|
16
|
+
const theme = { // picture/ui.js
|
|
17
|
+
bg: 'rgba(38,28,20,.94)', // panels: dialogue, prompt, toast, windows; the HUD uses it slightly see-through
|
|
18
|
+
fg: '#f4e8d0', muted: '#b8a88c', // text, secondary text
|
|
19
|
+
accent: '#e8a13a', good: '#9ccf6a', // names, cursor, toast border, HUD bars; "done"
|
|
20
|
+
line: 'rgba(244,232,208,.25)', // borders, dividers
|
|
21
|
+
font: '"Georgia", serif', // a font file: ui.fonts: ['name'] (recipe 05, fonts)
|
|
22
|
+
radius: '4px', radiusSmall: '2px', // windows and dialogue; buttons, prompts, toasts, HUD counters
|
|
23
|
+
loadingBg: '#1c140e', // loading and title screens, cutscene bars
|
|
24
|
+
};
|
|
25
|
+
const engine = createEngine({ canvas, ui: { theme } }); // the same ui option as the parts below
|
|
26
|
+
```
|
|
27
|
+
Each key becomes the CSS variable `--threedog-<key>` (`radiusSmall` -> `--threedog-radius-small`) on `engine.uiRoot`, and no default rule has a color or corner of
|
|
28
|
+
its own. Also there: `shadow` (windows), `shadowSmall` (bubbles, marker labels), `fadeBg` (scene fades), and `hudBg` / `hudFg` / `hudAccent`,
|
|
29
|
+
which follow the main ones unless set. Your own part can read the same variables. Further steps, beside `theme` in the same `ui`: `css` is placed after every default, so it
|
|
30
|
+
overrides the `.threedog-*` classes (sizes, layout); `templates.<window>` replaces a window's HTML (`engine.ui.templates` is the same object, written directly); `fonts` lists
|
|
31
|
+
font assets. Every other key of `ui` is a part name (§1). How high the prompt floats is `interactions({ promptHeight })`. Different behavior, not colors: a part of your own (§2).
|
|
10
32
|
|
|
11
33
|
## 1. Pick at start (copy it)
|
|
12
34
|
```js
|
|
@@ -64,7 +86,7 @@ engine.ui.set('toast', (engine) => ({ show: ({ text, kind }) => { if (kind !== '
|
|
|
64
86
|
engine.use(quests({ notify: false })); // or only silence quest messages; notify: ({ type, id, text }) => ... shows them your way
|
|
65
87
|
```
|
|
66
88
|
|
|
67
|
-
## 4. Dialogue box: your own
|
|
89
|
+
## 4. Dialogue box: your own picture, your own fields
|
|
68
90
|
The engine keeps the dialogue logic (typing on game time, input lock, Esc, number keys, conditions).
|
|
69
91
|
The part draws `view` and answers with `view.advance()` / `view.choose(i)`, which run the ops `dialogue.advance` / `dialogue.choose`.
|
|
70
92
|
`view = { script, node, speaker, text (typed so far), full, typing, choices: [{ text, key, data }], hint, data, lock, advance(), choose(i) }`
|
|
@@ -110,22 +132,24 @@ Every entry of the UI focus stack (dialogue, `engine.ui.open` parts, `makeWindow
|
|
|
110
132
|
(Esc, pad B) is still the back key. Only the top entry moves, so a dialogue over an open window never moves the window's slots.
|
|
111
133
|
- A window or full-screen part: the cursor walks the controls inside the part's `el` (button, input, select, `[data-nav]`) by screen layout,
|
|
112
134
|
so lists, slot grids and settings rows all work without declaring columns; left / right change a slider or a dropdown. The selected control
|
|
113
|
-
has the class `is-cursor` (style it in `
|
|
135
|
+
has the class `is-cursor` (style it in `ui.css`). Your own part opts in by exposing `get el() { return root; }`.
|
|
114
136
|
- Your own focus entry: `uiFocus(engine).push('shop', { cancel, nav: () => shopEl })`, or a list you draw yourself:
|
|
115
137
|
`nav: { count: () => items.length, moved: i => draw(i), confirm: i => engine.ops.run('shop.buy', { item: items[i].id }) }`.
|
|
116
138
|
- Keys are actions: rebind with `createEngine({ bindings: { uiUp: ['KeyI', 'PadUp'], confirm: ['Space', 'PadB'], cancel: ['Escape', 'PadA'] } })` or the settings menu.
|
|
117
139
|
|
|
118
140
|
### A window: results, game over, summary, any modal
|
|
119
141
|
`makeWindow` is the one window: it opens on top of the UI focus stack, locks game input while open, closes with its close button or Esc
|
|
120
|
-
(pad B), and its buttons take the choice cursor, so it works with the keyboard, a gamepad and the mouse
|
|
121
|
-
|
|
142
|
+
(pad B), and its buttons take the choice cursor, so it works with the keyboard, a gamepad and the mouse (opening it lets go of a locked mouse; the next click on
|
|
143
|
+
the view locks again). A window that ends something, win or lose, takes `closable: false`: no close button and Esc does nothing, so the player cannot slip back into the
|
|
144
|
+
game past it and only your buttons end it. Nothing else closes a window: a game that restarts by another road (a new game from the title, a load) closes it on `session:start`. Its picture is your `ui.css` /
|
|
145
|
+
`ui.templates[id]`. A level clear, a match score, a day's earnings or a run summary are all this:
|
|
122
146
|
```js
|
|
123
147
|
import { makeWindow } from 'threedog';
|
|
124
148
|
const results = makeWindow(engine, {
|
|
125
149
|
id: 'results', title: () => 'Run complete',
|
|
126
150
|
data: () => ({ score: run.score, best: run.best }), // read on every refresh(), so it shows the current values
|
|
127
151
|
render: (d, { esc }) => `<p>${esc(d.score)} / ${esc(d.best)}</p><button class="threedog-btn" data-act="again">Again</button>`,
|
|
128
|
-
|
|
152
|
+
closable: false, // a run summary ends the run; for a window Esc may leave, drop this (onCancel changes what Esc does)
|
|
129
153
|
});
|
|
130
154
|
results.el.addEventListener('click', ev => { // one listener: refresh() rewrites the content, not this
|
|
131
155
|
if (ev.target.closest('[data-act="again"]')) { results.toggle(false); startRun(); } // a click, Enter or pad A on the cursor
|
|
@@ -133,6 +157,7 @@ results.el.addEventListener('click', ev => { // one li
|
|
|
133
157
|
let held = null; // stop gameplay behind it (the picture keeps drawing)
|
|
134
158
|
engine.events.on('ui:open', id => { if (id === 'results') held = engine.freeze('results'); });
|
|
135
159
|
engine.events.on('ui:close', id => { if (id === 'results') { held?.remove(); held = null; } });
|
|
160
|
+
engine.events.on('session:start', () => results.toggle(false)); // a new run or a load, however it was started
|
|
136
161
|
results.toggle(true); // when the run ends; results.refresh() after the data changes
|
|
137
162
|
```
|
|
138
163
|
|
|
@@ -144,12 +169,27 @@ engine.ui.open('title'); // show it again (the setti
|
|
|
144
169
|
```
|
|
145
170
|
While the title is open gameplay is frozen, input is locked, and Esc goes to it (the settings menu does not open).
|
|
146
171
|
|
|
172
|
+
**A custom item closes the title itself.** The built-in `continue` / `start` call `e.ui.close('title')` after they load; an item you write does not, so `flow` can reach `playing` with the title still on top and no warning. End every item that leaves the title with `e.ui.close('title')`:
|
|
173
|
+
```js fragment
|
|
174
|
+
{ label: 'Tutorial', run: async e => { await e.session.newGame(); e.ui.close('title'); } }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Photo mode: the picture without the interface, and hiding the interface
|
|
178
|
+
`engine.photo.take()` (op `photo.take`) draws one frame of the game canvas at a higher pixel ratio and reads it back, so the picture never contains DOM: HUD, toasts and windows are not in it (a HUD drawn into the canvas by your own render code is). To hide the interface on screen for a photo mode, hide the engine's UI root, one element that holds every part:
|
|
179
|
+
```js
|
|
180
|
+
const photoMode = on => { engine.uiRoot.style.display = on ? 'none' : ''; }; // engine ui: hud, toasts, windows, title
|
|
181
|
+
engine.photo.take(); // shot.url is the picture, the album keeps it; the DOM was never in it
|
|
182
|
+
photoMode(true); // the player's screen without interface, e.g. while a photo mode is framing
|
|
183
|
+
```
|
|
184
|
+
HUD text follows the engine locale (`createEngine({ locale })`, default `'auto'` = the browser language): a game written in English sets `locale: 'en'`, or distance labels read `50 米` on a Chinese browser.
|
|
185
|
+
|
|
147
186
|
## 6. Settings menu: only the tabs the game needs
|
|
148
187
|
```js
|
|
149
188
|
engine.use(settings({ sections: ['game', 'graphics', 'audio', 'controls', 'camera'] })); // default: graphics, audio, controls, language, saves
|
|
150
189
|
// optional built-ins by name: 'game' (resume / load / back to title), 'camera' (sensitivity, invert Y, field of view; re-applied on 'camera:change')
|
|
151
190
|
engine.settings.addSection('camera');
|
|
152
|
-
|
|
191
|
+
// leave graphics rows out: the entry { id: 'graphics', omit } in the list; an omitted row stays the game's value, and no preset or stored value moves it
|
|
192
|
+
settings({ sections: [{ id: 'graphics', omit: ['pixelRatio', 'antialias', 'adaptive'] }, 'audio', 'controls', 'language', 'saves'] });
|
|
153
193
|
|
|
154
194
|
// a tab of your own: render gets tools with the control helpers (row / toggle / range / segmented) already bound
|
|
155
195
|
engine.settings.define('subtitles', true, on => { document.body.dataset.subtitles = String(on); });
|
|
@@ -159,29 +199,23 @@ engine.settings.addSection('gameplay', {
|
|
|
159
199
|
order: 50,
|
|
160
200
|
});
|
|
161
201
|
```
|
|
162
|
-
A row that switches off an effect of your own (a post effect, a
|
|
202
|
+
A row that switches off an effect of your own (a post effect, a picture value): name the shared value it limits, and it works like the
|
|
163
203
|
built-in shadows row. Off holds the value off on the settings layer, so a later scene, weather or cutscene cannot turn it back on; on
|
|
164
|
-
allows whatever the scene chose. A number row from 0 to 1 is a factor on a number value. Define the row after the effect exists.
|
|
204
|
+
allows whatever the scene chose. A number row from 0 to 1 is a factor on a number value. Define the row after the effect exists. `bloom` and `ao` already have rows of their own (limiting `post.bloom.enabled` / `post.ao.enabled`), so `settings.define('bloom', ...)` throws: switch them with `engine.settings.set('bloom', false)`, or in a preset.
|
|
165
205
|
```js
|
|
166
|
-
engine.
|
|
167
|
-
engine.settings.define('volFog', true, { limits: '
|
|
168
|
-
engine.settings.define('
|
|
206
|
+
engine.post.add(volFog); // post.volFog.enabled now exists
|
|
207
|
+
engine.settings.define('volFog', true, { limits: 'post.volFog.enabled' }); // add apply: v => ... too if the game reacts in code
|
|
208
|
+
engine.settings.define('flashCap', 1, { limits: 'sky.flash' }); // 0.5 = half of any lightning flash
|
|
169
209
|
settings({ presets: { low: { volFog: false } } }); // a preset can switch the row like any other key
|
|
210
|
+
settings({ presets: { low: { pixelRatio: 0.5 } } }); // pixelRatio in a preset: a share (0 to 1) of the ratio the engine picked for this device
|
|
170
211
|
```
|
|
171
|
-
`engine.describe().shared['
|
|
212
|
+
`engine.describe().shared['post.volFog.enabled']` shows the settings entry and what the scene wanted underneath.
|
|
172
213
|
|
|
173
214
|
A completely different menu: don't install `settings()`; open your own with `uiFocus(engine).setRoot(() => myMenu.open())` so Esc on an empty stack reaches it.
|
|
174
215
|
|
|
175
216
|
Check what is in use: `engine.ui.describe()` → `{ loading: 'default', toast: 'off', 'hud.bar': 'custom', ... }`.
|
|
176
217
|
|
|
177
218
|
## 7. Keys, and UI that follows the world
|
|
178
|
-
- Bind keys
|
|
179
|
-
jump) in the fixed step, UI keys in the frame hook. Never `addEventListener('keydown')`, and never read `pointer.clicked` for gameplay; bind a
|
|
180
|
-
`Mouse0` action instead.
|
|
181
|
-
- A menu, vehicle or build mode that takes over keys pushes an input context: `const h = engine.input.push('menu')` (opaque) or
|
|
182
|
-
`push('vehicle', { pass: true })`, then `h.remove()`. Tests and the dev bridge press keys with `engine.input.simulate(action, down)`:
|
|
183
|
-
action names, not keys (`simulate('moveForward')` walks like a held W until `simulate('moveForward', false)`); an unknown name throws.
|
|
219
|
+
- Bind keys and read them by action name (recipe 58): gameplay keys (attack, jump) in the fixed step, UI keys in the frame hook. Never `addEventListener('keydown')`, and never read `pointer.clicked` for gameplay; bind a `Mouse0` action instead.
|
|
184
220
|
- A label over a world position: `worldToScreen(engine, pos)` gives screen coordinates for an HTML element.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
Bind a counter to an item count (coins): `engine.onFrame(() => engine.hud.counter('coins', { icon: '🪙', label: 'Coins', value: engine.inventory.count('coin') }));`. Same id = update, unchanged value touches no DOM, and a loaded save follows automatically (recipe 22 section 4).
|
|
221
|
+
- A counter bound to an item count: recipe 22 section 4.
|
package/docs/recipes/27-net.md
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
puzzle, a turn-based board, trading). One player's browser is the **host** and
|
|
5
5
|
owns the game state; friends are **clients** that mirror it and ask for changes through ops. Not installed = no cost.
|
|
6
6
|
**What it is not (yet)**: action netcode. There is no client prediction or rollback, so a client's attack / roll / shot waits one round trip.
|
|
7
|
-
Souls-like and shooter games need that later step; the rules below (ops with self-contained args, state only changed in fixed steps and ops,
|
|
8
|
-
snapshot-able world data) are what it will build on.
|
|
9
7
|
|
|
10
8
|
## 1. Install
|
|
11
9
|
The same game code runs on every machine; only `role` and the transport differ.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
# Terrain: your own generator, digging, raising and painting the ground
|
|
1
|
+
# Terrain: your own generator, digging, raising and painting the ground, islands
|
|
2
|
+
|
|
3
|
+
**In this recipe**: 0. Noise preset · 1. Your own generator · 2. Changing the ground · 3. Farming soil and ground types · 4. Height and snapping · 5. Where the ground ends: `shape` · 6. Replace the picture, keep play · 7. A chunk that fails · 8. Triangle cut and bounds margin · 9. Height from a grid or image
|
|
2
4
|
|
|
3
5
|
Requires module `terrain()` (in the `openWorld()` preset). The API list is in `../api/terrain.md`.
|
|
4
6
|
|
|
5
7
|
The engine always does the chunks, streaming, workers, collision and vegetation. It has **no built-in landform**: `terrain()` without a generator is
|
|
6
8
|
flat gray ground at y = 0, with a dev warning. The height and ground type come from your own two functions or a preset, and the player can change the
|
|
7
|
-
ground during play.
|
|
9
|
+
ground during play. How the ground looks: recipes 36 and 53.
|
|
8
10
|
|
|
9
11
|
Flat island (no noise): `terrain({ height: () => 2, shape: { mask: (x, z) => 25 - Math.hypot(x, z) } })`; inside `openWorld` the same object goes under `terrain:`.
|
|
10
12
|
|
|
@@ -16,23 +18,24 @@ engine.use(openWorld({ camera: 'follow', seed: 7, terrain: terrainPreset({ shape
|
|
|
16
18
|
const preview = createTerrain({ seed: 7, ...terrainPreset() }); // same heights before the engine starts
|
|
17
19
|
const dry = (x, z) => riverAt(x, z, preview.noise) === 0;
|
|
18
20
|
```
|
|
19
|
-
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`;
|
|
20
|
-
|
|
21
|
-
`heightScale mountains rivers riverWidth biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
21
|
+
Its ground types are `beach snow rock riverbank wetland savanna forest highland meadow`; the game colors them (`terrain({ colors, biomeColors })`),
|
|
22
|
+
and `terrainStrings` names them for `describe()`. Other options:
|
|
23
|
+
`heightScale mountains rivers riverWidth river biomes noise island canyon` (types in the package's `index.d.ts`).
|
|
22
24
|
|
|
23
25
|
## 1. Your own generator
|
|
24
26
|
```js
|
|
25
27
|
import { terrain } from 'threedog';
|
|
26
28
|
terrain({
|
|
27
|
-
// meters at (x, z); n = { fbm(x, z, octaves), noise(x, z), hash(x, z, salt), seed, waterLevel, params }
|
|
29
|
+
// meters at (x, z); n = { fbm(x, z, octaves), noise(x, z), hash(x, z, salt), seed, waterLevel, params }; fbm, noise and hash all give 0 to 1, not -1 to 1
|
|
30
|
+
// (fbm gathers around 0.5 and seldom reaches either end: subtract 0.5 to center it, and sample the map before choosing a cut for a ground type)
|
|
28
31
|
height: (x, z, n) => 4 + 30 * n.fbm(x * 0.004, z * 0.004) - 8 * Math.abs(Math.sin(x * 0.01)),
|
|
29
32
|
// a ground type name (null = 'default'); its colors come from biomeColors[type]
|
|
30
33
|
groundType: (x, z, h, slope) => slope > 0.8 ? 'rock' : h < 1 ? 'beach' : 'grass',
|
|
31
34
|
waterLevel: 0, // a sea at y = 0; leave it out for no water (the default is -Infinity; terrainPreset() sets 0)
|
|
32
35
|
});
|
|
33
36
|
```
|
|
34
|
-
The terrain moves the camera's far plane out to its view distance
|
|
35
|
-
the
|
|
37
|
+
The terrain moves the camera's far plane out to its view distance and leaves the fog to the game; `terrain({ viewFog: true })` (on in `openWorld()`) writes that
|
|
38
|
+
distance to the signal `engine.uniforms.uViewDistance`, which your fog code reads so the far chunk edge fades out (recipe 34). It never writes `scene.fog`.
|
|
36
39
|
Both functions run in workers, so they are **pure**: they see only their parameters and globals like `Math`. Reading a variable from outside
|
|
37
40
|
(`(x, z) => x * scale`) throws at `terrain()` and names the variable; put the number inside the function, or pass settings as plain data in
|
|
38
41
|
`terrain({ params })` and read them as `n.params`. `flatten` plots still apply on top. A new type name needs colors:
|
|
@@ -47,8 +50,6 @@ engine.ops.define('ground.level', { args: { at: 'position' }, run(e, a) {
|
|
|
47
50
|
} });
|
|
48
51
|
engine.ops.run('ground.dig', { at });
|
|
49
52
|
```
|
|
50
|
-
- One of `raise` / `lower` (meters) / `flatten` (target height), and / or `paint` (a ground type, `null` gives back the generated type). `shape` is
|
|
51
|
-
`'circle'` (default) or `'square'`, `radius` in meters.
|
|
52
53
|
- Edits snap to the terrain grid: heights to grid points, paint to whole cells of `engine.terrain.cellSize` meters (`chunkSize / resolution`, default
|
|
53
54
|
4). A shape smaller than a cell takes the nearest one. For finer paint use a higher `terrain({ resolution })` (64 gives 1 m cells); per-cell
|
|
54
55
|
gameplay state belongs in a grid layer (section 3).
|
|
@@ -72,42 +73,137 @@ engine.ops.define('path.sand', { args: { at: 'position' }, // a sandy path; a
|
|
|
72
73
|
Read the ground with `engine.surface(x, z)` (also `slope`, `groundType`, `waterAt`) and put an object on it with `engine.snapToGround(obj)`. Don't
|
|
73
74
|
raycast the terrain for this: the height function is exact and works before the chunk has a mesh.
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
## 4b. A road laid on the ground
|
|
77
|
+
|
|
78
|
+
The road and the height function must read the same data, or the road floats or sinks wherever they disagree. Write the road's shape once as plain numbers and hand them over with `terrain({ params })`. The height function runs in workers and sees only `n.params`, so it works out the centre line itself: a formula or a small table of numbers, never a curve object. Near the line it returns the road's level, and it blends to the hills further out.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const ROAD = { R: 130, wobble: 24, level: 14, flat: 10, blend: 40 }; // the one copy of the road's shape
|
|
82
|
+
|
|
83
|
+
function height(x, z, n) {
|
|
84
|
+
const p = n.params, t = Math.atan2(z, x);
|
|
85
|
+
const centre = p.R + p.wobble * Math.sin(2 * t);
|
|
86
|
+
const k0 = Math.min(1, Math.max(0, (Math.abs(Math.hypot(x, z) - centre) - p.flat) / p.blend)), k = k0 * k0 * (3 - 2 * k0);
|
|
87
|
+
const hills = 10 + 60 * (n.fbm(x * 0.009, z * 0.009, 4) - 0.5);
|
|
88
|
+
return p.level + (hills - p.level) * k;
|
|
89
|
+
}
|
|
90
|
+
// terrain({ params: ROAD, height })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The road itself comes from the same numbers, with its heights read from `engine.surface`, so nothing is computed twice:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const points = [];
|
|
97
|
+
for (let i = 0; i < 720; i++) {
|
|
98
|
+
const t = i / 720 * Math.PI * 2, r = ROAD.R + ROAD.wobble * Math.sin(2 * t), x = r * Math.cos(t), z = r * Math.sin(t);
|
|
99
|
+
points.push({ x, y: engine.surface(x, z), z });
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Build the road's mesh from `points`, a little above the ground, and keep `flat` wider than half the road. The same data answers gameplay questions too, such as where the road is or how far a car has left it.
|
|
76
104
|
|
|
77
105
|
## 5. Where the ground ends: `shape`
|
|
106
|
+
`terrain({ shape })` decides where there is ground at all: an island, a floating rock, a world that ends. Without it the ground goes on forever. With it, ground exists only
|
|
107
|
+
where `mask > 0`; the rim is cut through the cells in straight lines, walls hang down from it, and an optional underside closes it. The keys and their defaults are `TerrainShape` in `types/world.d.ts`.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { createEngine, openWorld } from 'threedog';
|
|
111
|
+
|
|
112
|
+
const engine = createEngine({ canvas: document.querySelector('canvas') });
|
|
113
|
+
engine.use(openWorld({ camera: 'follow', water: false, terrain: { // water: false -- a floating island has no sea under it
|
|
114
|
+
height: (x, z, n) => 4 + 6 * n.fbm(x * 0.02, z * 0.02),
|
|
115
|
+
shape: {
|
|
116
|
+
mask: (x, z) => 60 - Math.hypot(x, z), // > 0 ground: a 60 m disc (meters read best)
|
|
117
|
+
edge: { noise: 8, size: 20, jitter: 0.6, round: 1.5 }, // ragged outline, jagged rim, top bends down 1.5 m at the edge
|
|
118
|
+
side: { depth: 3, ground: 'cliff' }, // 3 m of cliff band, colored by biomeColors.cliff
|
|
119
|
+
bottom: { depth: (x, z, n, m) => 2 + m * 0.5 + 4 * n.fbm(x * 0.1, z * 0.1), ground: 'rock' }, // hangs lower inland (m grows inward)
|
|
120
|
+
},
|
|
121
|
+
} }));
|
|
122
|
+
await engine.start();
|
|
78
123
|
|
|
79
|
-
|
|
80
|
-
|
|
124
|
+
const home = { x: 0, z: 0 };
|
|
125
|
+
engine.events.on('terrain:void', ({ who }) => { // fell off: the game decides (the engine never respawns)
|
|
126
|
+
if (who === engine.player) engine.player.placeAt(home);
|
|
127
|
+
});
|
|
128
|
+
```
|
|
81
129
|
|
|
82
|
-
|
|
130
|
+
Colors come from `terrain({ biomeColors })` as usual: add `cliff` and `rock` (a name without a color is neutral gray). The mask is pure like `height`, or a gray image.
|
|
131
|
+
Without `bottom` the island is open underneath (the cheapest choice when the camera never looks up at it). The side wall follows every bend of an `edge.round` top, so no slit shows between them.
|
|
132
|
+
|
|
133
|
+
What the rest of the engine does off the outline:
|
|
134
|
+
|
|
135
|
+
- `engine.surface(x, z)` is `-Infinity`, `engine.ground.has(x, z)` is `false`, `engine.slope` is 0, `engine.groundType` is `'void'`.
|
|
136
|
+
Check `has` before placing things: `engine.snapToGround` over the void warns once and leaves the object where it is, instead of writing an infinite y.
|
|
137
|
+
The same holds for every place-it-here entry (`engine.content.spawn`, content props, pickups, npcs, `character.placeAt`): a warning once per caller with this advice, and they keep the caller's y (or 0), never `-Infinity` (a save would turn it into NaN). Camera starts, HUD anchors, grid tiles and shot paths fall back to y 0 / the last height without a word.
|
|
138
|
+
- Characters walk off the rim and fall; pathfinding and spawn search treat the void as not walkable.
|
|
139
|
+
- Physics: the top and the walls collide (a rolling barrel stops at a wall, a ball falls off the edge); the underside does not.
|
|
140
|
+
- Vegetation never grows off the outline. `engine.terrain.edit` off it does nothing (returns `{ heights: 0, cells: 0 }`); near the rim it
|
|
141
|
+
still digs, and painting works. The outline itself cannot be edited.
|
|
142
|
+
- The player and every moving rigid body that drops below `engine.terrain.voidY` get one `terrain:void { who, position }` per fall.
|
|
143
|
+
- Global water still draws at its level: a floating island usually turns water off (`water: false` above).
|
|
144
|
+
|
|
145
|
+
Limits:
|
|
146
|
+
|
|
147
|
+
- The cut follows cell edges, so detail finer than a cell (`chunkSize / resolution`, 4 m by default) is lost. Keep `edge.size` above a cell,
|
|
148
|
+
or raise `resolution`.
|
|
149
|
+
- `shading: 'texture'`: the color map covers the top only (void pixels keep the color of the ground under them, so no seam shows at the rim, with alpha 0); sides and bottom use vertex colors or `side.material`.
|
|
150
|
+
- The mask is fixed at start; a game that wants the outline to change while playing builds that itself.
|
|
151
|
+
|
|
152
|
+
## 6. Drawing the ground and plants your own way: replace the picture, keep play
|
|
83
153
|
|
|
84
154
|
`terrain()` and `vegetation()` each install two modules: the data part (`engine.terrain`: heights, chunks, edits, collision;
|
|
85
|
-
`engine.vegetation`: species, placement, tree collision, felling) and the
|
|
86
|
-
`engine.
|
|
87
|
-
replaces a
|
|
155
|
+
`engine.vegetation`: species, placement, tree collision, felling) and the picture (`engine.terrainDraw`, slot `'terrain-draw'`;
|
|
156
|
+
`engine.vegetationDraw`, slot `'vegetation-draw'`). Collision, paths, `engine.surface`, `instanceAt` and saves read only the data, so a game that
|
|
157
|
+
replaces a picture keeps all of play. A picture listens to the data part's `view` hooks and never changes the data:
|
|
88
158
|
```js
|
|
89
|
-
engine.use({ name: 'myGround', type: '
|
|
159
|
+
engine.use({ name: 'myGround', type: 'picture', provides: ['terrain-draw'], install(e, ctx) {
|
|
90
160
|
const meshes = new Map();
|
|
91
161
|
ctx.track(e.terrain.view({
|
|
92
|
-
add(c) { const m = buildMesh(c.data.pos, c.data.nor, c.data.col); m.position.set(c.cx * e.terrain.
|
|
93
|
-
change(c) { refill(meshes.get(c), c.data); }, // terrain.edit rewrote the arrays (
|
|
162
|
+
add(c) { const m = buildMesh(c.data.pos, c.data.nor, c.data.col); m.position.set(c.cx * e.terrain.chunkSize, 0, c.cz * e.terrain.chunkSize); e.scene.add(m); meshes.set(c, m); },
|
|
163
|
+
change(c) { refill(meshes.get(c), c.data); }, // terrain.edit rewrote the arrays (the count can differ on an 'adaptive' rim)
|
|
94
164
|
remove(c) { e.scene.remove(meshes.get(c)); meshes.delete(c); },
|
|
95
165
|
show(c, visible) { meshes.get(c).visible = visible; },
|
|
96
166
|
}));
|
|
97
|
-
} }, { replaces: 'terrain-
|
|
98
|
-
engine.use({ name: 'myPlants', type: 'look', provides: ['vegetation-look'], install(e, ctx) {
|
|
99
|
-
ctx.track(e.vegetation.view({
|
|
100
|
-
species(sp) { /* sp.source = what vegetation.define was given (geometry, model, material, wind) */ },
|
|
101
|
-
change(c, name) { /* c.plants[name]: { n, m (16 floats per plant, chunk-local), c (colors), ids }; c.hidden[name]: felled slots; gone = drop that mesh */ },
|
|
102
|
-
ring(c, ring) { /* LOD: ring 1 = the chunk a source stands in plus one ring around */ },
|
|
103
|
-
show(c, visible) {}, drop(c) { /* chunk released */ },
|
|
104
|
-
}));
|
|
105
|
-
} }, { replaces: 'vegetation-look' });
|
|
167
|
+
} }, { replaces: 'terrain-draw' });
|
|
106
168
|
```
|
|
107
|
-
|
|
169
|
+
Plants work the same way: a module with `provides: ['vegetation-draw']`, `{ replaces: 'vegetation-draw' }` and `e.vegetation.view({ species, change, ring, show, drop })` (hooks in `../api/vegetation.md`). In `change(c, name)`, `c.plants[name]` is `{ n, m (16 floats per plant, chunk-local), c (colors), ids }` and `c.hidden[name]` the felled slots; when it is gone, drop that mesh.
|
|
170
|
+
`c.data` holds `pos`, `nor`, `col`, `uv`, and `tex: { data, size }` in texture mode; `engine.terrain.generator.buildChunk(cx, cz)` returns the same raw arrays.
|
|
171
|
+
Only the material, not the meshes? `engine.terrain.material = material` swaps it on every loaded chunk in place (recipe 36).
|
|
108
172
|
|
|
109
173
|
## 7. A chunk that fails
|
|
110
174
|
|
|
111
175
|
A chunk job that throws (usually the game's `height` / `groundType` / placement rule at that spot) is tried 3 times, then the chunk stays empty
|
|
112
176
|
(no ground, no collision there): `terrain:chunkFailed` `{ cx, cz, error }` fires, the error `[terrain-chunk-failed]` names the chunk and the cause,
|
|
113
177
|
and `describe().perf.chunks.failed` counts it. Fix the rule, then `engine.terrain.retry()` sends every failed chunk again.
|
|
178
|
+
|
|
179
|
+
## 8. Triangle cut and bounds margin
|
|
180
|
+
```js
|
|
181
|
+
terrain({ diagonal: 'adaptive' }) // 'fixed' (default) | 'adaptive' | 'alternate'
|
|
182
|
+
```
|
|
183
|
+
`fixed` cuts every cell the same way. `adaptive` cuts along the diagonal with the smaller height difference, which removes
|
|
184
|
+
the zigzag ridges a fixed cut leaves on a slope; `alternate` flips every other cell (no directional bias on flat low-poly facets). `engine.surface`,
|
|
185
|
+
collision and vegetation heights follow the chosen cut, so nothing floats. It changes the walkable shape, so `recolor` does not take it.
|
|
186
|
+
|
|
187
|
+
`boundsPad: { up: 3, radius: 8 }` (meters, the defaults) is the margin of the chunk's bounding sphere: the center is raised by `up`, the radius grows
|
|
188
|
+
by `radius`. Raise it if a shader moves vertices far (wind on tall ground cover, a vertex-displacement patch) and chunks pop out at the screen edge.
|
|
189
|
+
|
|
190
|
+
## 9. Height from a grid or image
|
|
191
|
+
`sampleGrid(data, opts)` (`../api/tools.md`) turns numbers laid out on a regular grid into a function `(x, z) => value`;
|
|
192
|
+
`await engine.assets.gridFromImage(nameOrUrl, opts)` (`../api/assets.md`) reads such a grid from an image. Samples sit on the grid nodes, so
|
|
193
|
+
`width` samples span `width - 1` cells. The grid is just a field: height, moisture, a
|
|
194
|
+
ground-type weight, spawn density, a walkable mask, danger, travel cost.
|
|
195
|
+
|
|
196
|
+
`interp` is the picture between nodes, and none of them is the right one: `'nearest'` for terraces, blocky ground, tile masks and ids; `'linear'` (default) for most fields;
|
|
197
|
+
`'cubic'` for slopes without cell creases, which can overshoot beside a sharp step (`clamp: true` keeps it inside the four corner values).
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
const g = await engine.assets.gridFromImage('/maps/height16.png', { range: [-5, 60] }); // meters, 16-bit file
|
|
201
|
+
const heightAt = sampleGrid(g.data, { ...g, size: [512, 512], origin: [-256, -256], interp: 'cubic', clamp: true });
|
|
202
|
+
heightAt(10, 20); // gameplay side: where to put a camp, a mine, a lighthouse
|
|
203
|
+
const wet = sampleGrid(moisture, { width: 32, height: 32, cellSize: 8 }); // a hand-made field: wetter ground grows reeds, rice, moss
|
|
204
|
+
const walk = sampleGrid(mask, { width: 64, height: 64, cellSize: 1, interp: 'nearest', outside: 0 }); // 0 / 1 per tile; off the map: not walkable
|
|
205
|
+
```
|
|
206
|
+
A terrain `height` function is recompiled in a worker and cannot capture `heightAt`, so the terrain reads the same image through its own
|
|
207
|
+
`heightmap` (bilinear, centered on `center`): `terrain({ heightmap: { ...g, size: [512, 512], min: -5, max: 60 } })` with `g` from `gridFromImage`
|
|
208
|
+
using the default `range` (it expects 0-1 values; `min`/`max` scale them). Use `sampleGrid` for everything outside the terrain module; when you need
|
|
209
|
+
a picture the terrain's bilinear read does not give (terraces: `nearest`), bake it into the data first or write the step in a `height` function.
|
package/docs/recipes/29-grid.md
CHANGED
|
@@ -40,7 +40,7 @@ player text of its own codes (zh-CN and en; override a line with `engine.i18n.ad
|
|
|
40
40
|
`can` codes, need their own `grid.<code>` line through `engine.i18n.add`. `engine.explain({ grid: { grid: 'room', item: 'bed', cell: [4, 4] } }).text` says which cell
|
|
41
41
|
and which record is in the way.
|
|
42
42
|
A placed record looks like `{ id, kind, position, rot, ...fields, grid: { id: 'room', cell: [4, 4], size: [2, 1], rotation: 1, item: 'bed' } }`. Give
|
|
43
|
-
it a
|
|
43
|
+
it a picture with `world.present(kind, ...)` as usual (`rot` is the yaw in radians).
|
|
44
44
|
To build several things at once, call `grid.place` from your own op (`build.wall`), so each placement is still checked.
|
|
45
45
|
|
|
46
46
|
**Occupancy is not saved separately.** `room.at(cell)` / `room.area(cell, size)` read an index built from the world records' `grid` field, so a save
|
|
@@ -80,10 +80,10 @@ Cells that exist from the start go in content: `content/grids.js` <!-- r18-ignor
|
|
|
80
80
|
`plot: { cell: 1, origin: [20, 0], size: [8, 8], layers: { soil: [[3, 5, { tilled: true }]] } }` <!-- r18-ignore-line -->
|
|
81
81
|
(or `grids.add(name, { layers })`). They are the baseline: a save keeps only cells changed from it, so editing the content later still reaches old saves.
|
|
82
82
|
|
|
83
|
-
**Tiles.** The game gives a layer its colors: `plot.layer('soil', { tiles: {
|
|
84
|
-
(what the data means is gameplay, so
|
|
83
|
+
**Tiles.** The game gives a layer its colors: `plot.layer('soil', { tiles: { color: d => d.watered ? 0x5b3d2a : d.tilled ? 0x8a6243 : null } })`
|
|
84
|
+
(what the data means is gameplay, so the game writes these). A layer with tiles shows crisp per-cell quads just above the ground, following its
|
|
85
85
|
height (slopes, ramps, level meshes).
|
|
86
|
-
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `
|
|
86
|
+
`tiles: { colors: { watered: 0x5b3d2a, tilled: 0x8a6243 } }` is the same as `color` from a table (first truthy field wins) and wins over the module's `grids({ tiles: { soil: { ... } } })`; `plot.layer('soil', { tiles: false })` turns them off; `{ tiles: true }` draws every non-empty cell gray; `lift` raises them; `{ tiles:
|
|
87
87
|
(engine, layer) => ({ update(cells), dispose() }) }` is your own view. Options are read when the layer is first created.
|
|
88
88
|
|
|
89
89
|
## 4. Preview
|
|
@@ -100,9 +100,18 @@ The engine binds no key: the preview declares the action `rotate` (gone with the
|
|
|
100
100
|
`engine.input.bind('rotate', ['KeyR'])`; pass `rotate: 'myAction'` to read another one, `false` for none. Without a binding the preview warns once and only `pv.rotate()` turns
|
|
101
101
|
it. `pv.cell`, `pv.rotation`, `pv.ok`, `pv.code` (the `can` answer, `'noTarget'` with no cell, null when ok)
|
|
102
102
|
are readable every frame.
|
|
103
|
-
Colors come from `
|
|
103
|
+
Colors come from `grids({ ok, bad, previewOpacity, previewHeight })`. `draw: false` hides the default box; `draw: (engine) => ({ update(view), hide(), dispose()
|
|
104
104
|
})` draws your own (`view = { cells, center, size, rotation, ok, code }`).
|
|
105
105
|
|
|
106
|
+
## Materials
|
|
107
|
+
```js
|
|
108
|
+
engine.use(world(), grids({ ok: 0x66dd88, bad: 0xdd5544, previewOpacity: 0.6, tileLift: 0.05 }));
|
|
109
|
+
plot.layer('soil').material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 });
|
|
110
|
+
pv.material = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0.5, depthWrite: false });
|
|
111
|
+
```
|
|
112
|
+
Both are plain three.js materials, used as given. Tile colors are vertex colors, so a tile material keeps `vertexColors: true` to show them; the default also has a polygon
|
|
113
|
+
offset against the ground. The preview still writes ok / bad to its material's `color`. `layer.material` is null on a layer that draws no tiles, `pv.material` with `draw` off or your own.
|
|
114
|
+
|
|
106
115
|
## 5. Baked data vs state the player changes
|
|
107
116
|
Anything the player can change in play must be runtime state, never baked into generated height or ground-type data: a tilled plot (farming), a dug or mined
|
|
108
117
|
tile (survival), a road or placed floor (city builder), a painted tile (puzzle), a breakable wall (action). Bake only what never changes: the landform (hills,
|
|
@@ -119,7 +128,7 @@ engine.ops.define('plot.dig', { args: { cell: 'any' },
|
|
|
119
128
|
e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
|
|
120
129
|
} });
|
|
121
130
|
```
|
|
122
|
-
Undo with `paint: null` and `raise`.
|
|
131
|
+
Undo with `paint: null` and `raise`.
|
|
123
132
|
|
|
124
133
|
## 6. Verify
|
|
125
|
-
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
134
|
+
`engine.describe().grids` -> `{ room: { occupied, items: { bed: 1 }, layers: {} }, plot: { ..., layers: { soil: 30 } } }`.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# Templates: reusable objects, definition vs instance state
|
|
2
2
|
|
|
3
|
-
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
-
5. Point -> thing · 6. When to use a template
|
|
3
|
+
**In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
|
|
4
|
+
5. Point -> thing · 6. When to use a template · 7. A group of things
|
|
5
5
|
|
|
6
6
|
Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
|
|
7
|
-
`inventory()`.
|
|
7
|
+
`inventory()`.
|
|
8
8
|
|
|
9
9
|
A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
|
|
10
10
|
state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
|
|
11
|
-
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template
|
|
11
|
+
only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template, and a template is plain JS, so
|
|
12
|
+
`{ ...chest, model: 'iron-chest' }` is that other template in one line.
|
|
12
13
|
|
|
13
14
|
## 1. Define a template
|
|
14
15
|
`games/<game>/content/templates.js` (add it to `content/index.js`):
|
|
@@ -16,7 +17,7 @@ only its own state. There is no inheritance and no variant layer; a different lo
|
|
|
16
17
|
export default {
|
|
17
18
|
chest: {
|
|
18
19
|
model: 'chest', // an asset name (file or generator of an asset pack, the same name pickups and vegetation take); every chest clones one shared prototype
|
|
19
|
-
collide: 'box', // 'box'
|
|
20
|
+
collide: 'box', // 'box' = the model's bounds; 'circle' = a cylinder on its base; omitted = does not block
|
|
20
21
|
state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
|
|
21
22
|
interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
|
|
22
23
|
container: { capacity: 6, items: { berry: 2 } }, // each chest gets a container whose id is the record id; items = starting goods (placed once)
|
|
@@ -32,6 +33,11 @@ engine.ops.define('chest.toggle', { run: (e, { id }) => e.world.set(id, { opened
|
|
|
32
33
|
`interact` fields: `op` (required), `label` (text, i18n key, or `(rec, engine) => text`), `radius` (default 2.5), `height`, `action`,
|
|
33
34
|
`enabled: (rec, engine) => boolean`.
|
|
34
35
|
|
|
36
|
+
`collide` forms (the same on a plain prop): `'box'` is the model's bounding box, for buildings and crates. `'circle'` is a cylinder on the model's **base**: the
|
|
37
|
+
geometry in the lowest fifth of its height above the ground, so a tree gets its trunk and a street lamp its pole, and a crown or an arm blocks nobody. Write the radius
|
|
38
|
+
yourself with `collide: { circle: 0.25 }` (model meters: it follows `scale`), still centred on the base; add `occluder: false` when the follow camera may pass it
|
|
39
|
+
(recipes/21-camera.md). A bush or a tree whose crown hangs below head height but above that fifth lets a character walk into the leaves: give it a larger `circle`.
|
|
40
|
+
|
|
35
41
|
## 2. Place instances
|
|
36
42
|
In `content/props.js`, an entry with `template` instead of `model` places an instance. It takes a position and a few explicit overrides:
|
|
37
43
|
```js
|
|
@@ -52,7 +58,7 @@ turret: { model: 'turret', state: { ammo: 30 }, fields: { ammo: { min: 0, max: 9
|
|
|
52
58
|
```
|
|
53
59
|
`npm run check` then reports a placement with `stage: 9`, `sort: 'rice'` or a misspelled `stagee` (with the closest name), and dev `engine.content.spawn`
|
|
54
60
|
throws on the same mistakes. `engine.content.fields('crop')` returns the whole table (placement fields plus state fields, with each state default),
|
|
55
|
-
in the `core/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
61
|
+
in the `core/base/params.js` format; `fields('props')`, `fields('pickups')`, `fields('views')` and `fields('props.grid')` give the engine's own placement
|
|
56
62
|
fields, and a game kind in `content/rules.js` can declare `fields` the same way. A state field may not be named `id`, `kind` or `position`: those
|
|
57
63
|
are the record's own.
|
|
58
64
|
|
|
@@ -117,7 +123,7 @@ export default {
|
|
|
117
123
|
},
|
|
118
124
|
};
|
|
119
125
|
```
|
|
120
|
-
- `duration` is
|
|
126
|
+
- `duration` is calendar seconds (`engine.clock.now`) spent in a stage; only the last stage may leave it out (it stays there). `scale` multiplies the
|
|
121
127
|
instance's scale; `model` is a model name shown from that stage on. Stages are data: content-check validates them with the engine's own rules.
|
|
122
128
|
- Each instance gets the state field `stage` (default 0, an int 0..n-1, so a placement may write `{ template: 'crop', stage: 2 }` and
|
|
123
129
|
`content.fields('crop').stage` describes it) and `stageAt`, the clock time it entered. Both are on the world record and saved like any other field.
|
|
@@ -147,11 +153,6 @@ value on the record instead (`engine.world.set(id, { opened: true })`). Read a d
|
|
|
147
153
|
`engine.inventory.item(id)`. For your own tables of kinds (enemy types, crop types), the same split applies: keep the table in content, store `kind`
|
|
148
154
|
plus the changing values on the record, and wrap the table with `Object.freeze` if you like. <!-- r18-ignore-line -->
|
|
149
155
|
|
|
150
|
-
## 4. Tests
|
|
151
|
-
`tests/specs/templates.mjs`: two chests of one template share the model, open / goods per instance, save and reload restores each, the definition
|
|
152
|
-
never changes. `tests/specs/template-stages.mjs`: stages grow over game time near and far and survive save / load, `update` runs on the
|
|
153
|
-
fixed step, an interaction runs its op, and the engine root has no second placement path (no entities module, no root-level spawn). `tests/specs/single-source.mjs` (`npm test -- "Single source"`): ids, duplicates, baseline + diff, orphans, level nodes, source lines, pick.
|
|
154
|
-
|
|
155
156
|
## 5. Point -> thing: where is this defined
|
|
156
157
|
Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
|
|
157
158
|
the entry, ask the engine what a thing is:
|
|
@@ -162,22 +163,62 @@ engine.world.origin('chest-home'); // the same source info for an id
|
|
|
162
163
|
```
|
|
163
164
|
`hit.thing` is on every `engine.pick` / `engine.raycast` hit (computed when read); a hit on a batched copy resolves to its original object.
|
|
164
165
|
`engine.inspect(id).thing` and `engine.explain({ op, args: { id } })` say the same. A hit on a plain object added with `engine.add` gets its
|
|
165
|
-
`hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe
|
|
166
|
+
`hit.thing` from the registry (id, `at` = the file:line of the add, `saved`, `edit`; recipe 40). A record made during play shows the op and tick that spawned it
|
|
166
167
|
(`spawned`), a level node its level and node name. Source lines exist in dev and test builds only (a Vite transform tags `content/*.js` with their
|
|
167
168
|
line numbers); a release build has none and pays nothing. From a terminal or an MCP client: `threedog pick 480,270` (screen pixels from the canvas
|
|
168
169
|
top-left) or the MCP tool `pick { x, y }`.
|
|
169
170
|
|
|
170
171
|
## 6. When to use a template
|
|
171
|
-
|
|
172
|
-
windmill, colliders, interactions. A template plus a placement with an `id` in `content/props.js` (or `pickups`, `npcs`, `containers`, a game kind
|
|
173
|
-
from `rules.js`, the level model) is what you want when the thing must be saved with its own state, edited without touching code, or copied many
|
|
174
|
-
times. Both land in the same registry: `engine.thing(id)` answers for either and says what a save keeps (recipe 41). Game code keeps the rules: ops,
|
|
175
|
-
`world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
172
|
+
Plain three.js or a template: recipe 40 sections 1 and 2 decide. Game code keeps the rules: ops, `world.simulate` / `world.present`, conditions and UI. Something that appears during play is created inside an op with `engine.content.spawn`.
|
|
176
173
|
|
|
177
|
-
`npm run check` (rule R33) flags only what
|
|
174
|
+
`npm run check` (rule R33) flags only what can break, in examples, templates and `games/*` alike. Warning, with `// runtime: <reason>` as the way to say it is fine (no saves, a new run only): `world.add` (without `{ save: false }`),
|
|
178
175
|
`engine.content.spawn`, `pickups.spawn` or `npcs.add` at module top level or in an `engine:ready` / `level:loaded` / `session:start`
|
|
179
|
-
handler, because those are saved whole and the startup code would make a second copy after every load
|
|
180
|
-
anywhere. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
176
|
+
handler, because those are saved whole and the startup code would make a second copy after every load. Error: `world.add(…, { initial: true })`
|
|
177
|
+
anywhere, which corrupts what saves compare against. Warning: code that `engine.add`s a `world.view(id)` model or writes its position / rotation / scale (world puts it back every frame).
|
|
181
178
|
The fix is a placement in content, or an op. Places computed from the seed (a flat spot for `home`) stay in code and are passed as `places` to
|
|
182
179
|
`content.load`; a mesh built in code becomes a model by name (`engine.assets.manifest({ models: { cabin } })`) when you want it as a template.
|
|
183
180
|
A line that really must do it from code at startup carries `// runtime: <reason>`.
|
|
181
|
+
|
|
182
|
+
## 7. A group of things
|
|
183
|
+
A market stall, a gun nest, a pit lane, a shop shelf, a puzzle room: several things that belong together. Content stays flat. Each thing is its own plain
|
|
184
|
+
entry with its own id, and what holds them together is the **place** they stand at. Nothing nests at runtime: there is no group object, no parent and no
|
|
185
|
+
per-part override, so `engine.thing(id)`, the save, `threedog content set` and `engine.pick` see each entry the same way as any other.
|
|
186
|
+
|
|
187
|
+
`content/places.js`, one place per group; `rot` is optional, radians about Y:
|
|
188
|
+
```js
|
|
189
|
+
export default { 'stall-1': { x: 40, z: -12 }, 'nest-1': { x: 8, z: 30, rot: 1.57 } };
|
|
190
|
+
```
|
|
191
|
+
`content/props.js`, entries around that place (`template` is the prototype, `id` the instance):
|
|
192
|
+
```js
|
|
193
|
+
export default [
|
|
194
|
+
{ id: 'stall-1-counter', model: 'counter', collide: 'box', place: 'stall-1', source: 'stall' },
|
|
195
|
+
{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' },
|
|
196
|
+
{ id: 'nest-1-wall', template: 'sandbags', place: 'nest-1', z: 2, source: 'nest' },
|
|
197
|
+
{ id: 'nest-1-gun', template: 'turret', place: 'nest-1', x: 1, rot: 0.5, ammo: 5, source: 'nest' },
|
|
198
|
+
];
|
|
199
|
+
```
|
|
200
|
+
**One edit moves the group.** An entry's `x`, `z` are offsets from the place and turn with its `rot` (the same sense as a model's `rotation.y`); its own `rot` adds to
|
|
201
|
+
the place's. Change the place and every entry follows, with its model and collision. This also holds without a page reload when the place changes through a
|
|
202
|
+
second `engine.content.load(data, { places })`. What play moved or turned stays where the player left it, and a save keeps only what play changed, so an old
|
|
203
|
+
save follows the new place too. Only places in `places.js` (or the `places` of `content.load`) have `rot`; a level marker gives a position.
|
|
204
|
+
|
|
205
|
+
**`source`** (experimental, with `content stamp` and `content capture`) is a plain optional string on a model or template entry, naming what the entry was copied from. It has no effect at runtime; it is there to ask:
|
|
206
|
+
```js fragment
|
|
207
|
+
engine.world.query({ where: r => r.source === 'stall' }); // every thing copied from that arrangement
|
|
208
|
+
```
|
|
209
|
+
**Moving entries by hand.** On the dev server press F2 (or add `?edit=1` to the address), click an entry and drag its handle: letting go writes `x` and `z` into its content file, as an offset when it stands on a place. Comments and alignment stay. A value someone changed since the click is refused, and code-built entries and things added by code say why they cannot be saved.
|
|
210
|
+
|
|
211
|
+
**Arrangements.** To stamp out the same group again (`threedog content stamp <name> id=stall-1 x=20 z=5 rot=1.6`, then `threedog content set --source <name> <part> y=2` changes that part in every copy, as one explicit edit), keep it as a small file, `content/arrangements/<name>.js`: entries around zero, with a local `part` name
|
|
212
|
+
instead of an id and no place. Only the tools read it, when they copy it into `props.js`; the game never loads it, so the copies are ordinary entries from then
|
|
213
|
+
on and changing the file later changes nothing already placed.
|
|
214
|
+
```js
|
|
215
|
+
export default [
|
|
216
|
+
{ part: 'counter', model: 'counter', collide: 'box' },
|
|
217
|
+
{ part: 'chest', template: 'chest', x: 1 },
|
|
218
|
+
];
|
|
219
|
+
```
|
|
220
|
+
Copied to `stall-1`, part `chest` becomes `{ id: 'stall-1-chest', template: 'chest', place: 'stall-1', x: 1, source: 'stall' }`.
|
|
221
|
+
|
|
222
|
+
**Deleting.** Delete an entry and a save that changed it still loads: the change is an orphan, kept in the save, listed in `engine.describe().world.orphans` and warned
|
|
223
|
+
about once; the `renames` content file says where it went (`null` = deleted on purpose). Delete a place and `threedog check` names every entry still standing on it; the
|
|
224
|
+
load refuses it too (`content-place`), because an entry with no place has no position.
|