threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- 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} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -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} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- 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} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -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 +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- 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/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /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/{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
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Error hints: "what to do + which doc to read" for any error, so an AI that sees one knows the next step without searching. Appended to
|
|
2
2
|
// engine.error (errors.js), warnOnce (validate.js), .threedog/errors.log (vite-error-relay) and the dev bridge `errors` command, all through
|
|
3
|
-
// hintText()
|
|
3
|
+
// hintText().
|
|
4
4
|
//
|
|
5
5
|
// throw codedError('clock-interval', 'clock.every(0): ...') // err.code, err.fix, err.docs; the message ends with [clock-interval]
|
|
6
6
|
// hintFor('... [world-plain]') // { id: 'world-plain', cause: ERROR_CODES fix, docs } (from the tag)
|
|
@@ -31,14 +31,26 @@ export const ERROR_HINTS = [
|
|
|
31
31
|
// undefined only: a module that is not installed is undefined, never null. A read on null is another cause (null-value below), and
|
|
32
32
|
// calling it "not installed" sent a reader after engine.use() when three.js mergeGeometries had returned null.
|
|
33
33
|
{ id: 'not-installed', match: /Cannot read properties of undefined \(reading '[\w$]+'\)|engine\.[\w$]+(\.[\w$]+)* is undefined/,
|
|
34
|
-
cause: '
|
|
35
|
-
'engine.start() finished
|
|
34
|
+
cause: 'A plain TypeError: something was undefined where code read a property, and the message does not say which. If the stack line reads engine.<module>, ' +
|
|
35
|
+
'that module is not installed (engine.use(...)) or the code ran before engine.start() finished; otherwise it is a missing object, array item or ' +
|
|
36
|
+
'misspelled field in the game own code. Check the stack for the line.',
|
|
36
37
|
docs: ['recipes/01-new-game.md', 'api/engine.md'] },
|
|
37
38
|
{ id: 'null-value', match: /Cannot read properties of null \(reading '[\w$]+'\)|[\w$.]+ is null/,
|
|
38
39
|
cause: 'A value was null where code read a property: a lookup or helper returned null (document.querySelector found nothing; ' +
|
|
39
40
|
'three.js BufferGeometryUtils.mergeGeometries returns null when the geometries have different attributes and logs which one in the ' +
|
|
40
41
|
'console just before). Check the stack for the line and what produced the value.',
|
|
41
|
-
docs: ['
|
|
42
|
+
docs: ['THREE.md', 'recipes/16-dev-bridge.md'] },
|
|
43
|
+
// A guessed pause method (the engine has one answer: engine.freeze; `threedog check` asks this entry too, tools/types.mjs)
|
|
44
|
+
{ id: 'fall-prevent', match: /\bpreventDefault is not a function/,
|
|
45
|
+
cause: "The character:fall event can no longer be cancelled: falling is the rule 'fall'. To leave a fall to the game: engine.mod('fall', { owner: 'game', id: 'player', set: false }).",
|
|
46
|
+
docs: ['MIGRATING-1.0.md', 'recipes/55-mods-time-wrap.md'] },
|
|
47
|
+
{ id: 'thing-explain', match: /\.explain is not a function/,
|
|
48
|
+
cause: 'engine.explain is the one way to ask why: what engine.thing(id).explain() gave is engine.explain({ thing: id }).detail.',
|
|
49
|
+
docs: ['MIGRATING-1.0.md', 'recipes/40-scene.md'] },
|
|
50
|
+
{ id: 'pause-guess', match: /\b(?:time\.(?:pause|stop|resume)|engine\.(?:pause|resume|stop)) is not a function/,
|
|
51
|
+
cause: 'The engine has no pause method of that name. To pause the world call engine.freeze(owner): it returns the handle that releases it ' +
|
|
52
|
+
'(handle.release()); settings({ freezeWorld: true }) does it for a menu.',
|
|
53
|
+
docs: ['recipes/07-flow-scenes-pause.md', 'api/engine.md'] },
|
|
42
54
|
{ id: 'not-function', match: /[\w$.]+ is not a function/,
|
|
43
55
|
cause: 'The method name is wrong, or the module is not installed (the property is then undefined). Check spelling against api/<module>.md.',
|
|
44
56
|
docs: ['api/engine.md', 'CODEMAP.md'] },
|
|
@@ -97,11 +109,6 @@ export function coded(code, message) { return `${message} [${code}]`; }
|
|
|
97
109
|
/** Indented lines "Code" (when the message has no [code] tag) + "Possible cause" + "Read"; '' if no hint matches. @param {unknown} message */
|
|
98
110
|
export function hintText(message) {
|
|
99
111
|
const h = hintFor(message);
|
|
100
|
-
if (!h) return '';
|
|
112
|
+
if (!h || ERROR_CODES[h.id]?.brief) return '';
|
|
101
113
|
return (tagOf(String(message)) ? '' : `\n Code: ${h.id}`) + `\n Possible cause: ${h.cause}\n Read: ${h.docs.join(', ')}`;
|
|
102
114
|
}
|
|
103
|
-
|
|
104
|
-
/** message + its hint (unchanged if none matches or it already has one). @example withHint('world data must be plain values (...)') @param {string} message */
|
|
105
|
-
export function withHint(message) {
|
|
106
|
-
return /\n\s*Possible cause:/.test(message) ? message : message + hintText(message);
|
|
107
|
-
}
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
// so a half-deducted inventory or half-updated quest does not keep running, and a test does not mistake it for normal. A release build reports once and keeps running (so the player is not stuck for the whole session).
|
|
8
8
|
// soft (core steps such as rendering and stream.update): report once per site and continue.
|
|
9
9
|
// engine.error is machine-readable: { where, message, code, fix, docs } (code / fix / docs come from the error itself or from the hint table, errorHints.js).
|
|
10
|
-
import { DEV } from './validate.js';
|
|
10
|
+
import { DEV, fmt } from './validate.js';
|
|
11
11
|
import { errorInfo, hintText } from './errorHints.js';
|
|
12
12
|
|
|
13
13
|
const STRINGS = { once: '[engine] {key} threw (later errors at the same place are not reported again)', disabled: '[engine] {type} module {name} threw and was disabled (the game continues) [module-disabled]', halted: '[engine] {key} threw and gameplay is frozen (in dev / tests a gameplay error fails hard; see engine.error for details) [gameplay-frozen]', listener: 'listener of event {name}',
|
|
14
14
|
rejected: '[engine] a promise rejected and nothing caught it (e.g. audio.play() of a missing file, an async callback that threw); reported once, the game continues. Add .catch or await it in try. ' };
|
|
15
15
|
|
|
16
16
|
/** picture / ui modules only show the game, so an error in one switches it off instead of freezing gameplay (the type is the one source; no extra flag) */
|
|
17
|
-
|
|
17
|
+
const failsSoft = m => m?.type === 'picture' || m?.type === 'ui';
|
|
18
18
|
|
|
19
19
|
/** Handle an error. key: where it happened (for display); module: the module definition that threw (none means a game callback / event listener, counted as gameplay); soft: report only once */
|
|
20
20
|
export function reportError(engine, err, key, { module = null, soft = false } = {}) {
|
|
@@ -23,14 +23,14 @@ export function reportError(engine, err, key, { module = null, soft = false } =
|
|
|
23
23
|
const message = String(err?.message ?? err);
|
|
24
24
|
// code + fix + docs: what to do and which page to read; at: the line that threw (the message alone often does not say which callback line)
|
|
25
25
|
engine.error = { where: key, message, ...errorInfo(err), at: firstFrame(err) };
|
|
26
|
-
engine.freeze('error');
|
|
27
|
-
console.error(STRINGS.halted
|
|
26
|
+
engine.freeze('error'); // until reload, a new game included: dev must not walk past a bug, and a new playthrough on top of it would hide it. Release builds keep running
|
|
27
|
+
console.error(fmt(STRINGS.halted, { key }) + hintText(err?.code ? `[${err.code}]` : message), err);
|
|
28
28
|
engine.events.emit('engine:error', engine.error);
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
if (engine._hookErrors.has(key)) return;
|
|
32
32
|
engine._hookErrors.add(key);
|
|
33
|
-
console.error(STRINGS.once
|
|
33
|
+
console.error(fmt(STRINGS.once, { key }), err);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** First stack frame of an error: V8 "at fn (file:line:col)", Firefox / Safari "fn@file:line:col"; null without a stack */
|
|
@@ -51,13 +51,15 @@ export function watchRejections(engine) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** An event listener threw (called by the event bus): counted as gameplay */
|
|
54
|
-
export function reportListenerError(engine, name, err) { reportError(engine, err, STRINGS.listener
|
|
54
|
+
export function reportListenerError(engine, name, err) { reportError(engine, err, fmt(STRINGS.listener, { name })); }
|
|
55
55
|
|
|
56
|
-
/** Disable a picture / ui module: remove its fixed / frame / afterRender hooks */
|
|
56
|
+
/** Disable a picture / ui module: give back what it borrowed, remove its fixed / frame / afterRender hooks */
|
|
57
57
|
function disableModule(engine, m, err) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const was = engine._modState.get(m.name);
|
|
59
|
+
if (was === 'disabled') return;
|
|
60
|
+
if (was !== 'failed') engine._modState.set(m.name, 'disabled'); // a failed init stays 'failed': that word is what blocks the modules that require it
|
|
61
|
+
engine._returnBorrowed(m.name);
|
|
60
62
|
for (const k in engine._hooks) engine._hooks[k] = engine._hooks[k].filter(h => h.name !== m.name);
|
|
61
|
-
console.error(STRINGS.disabled
|
|
63
|
+
console.error(fmt(STRINGS.disabled, { type: m.type, name: m.name }), err);
|
|
62
64
|
engine.events.emit('module:disabled', { name: m.name, message: String(err?.message ?? err) });
|
|
63
65
|
}
|
|
@@ -25,8 +25,11 @@ export const ENGINE_EVENTS = [
|
|
|
25
25
|
'camera:change',
|
|
26
26
|
'character:jump',
|
|
27
27
|
'character:launch',
|
|
28
|
+
'link:enter',
|
|
29
|
+
'link:exit',
|
|
28
30
|
'character:fall',
|
|
29
31
|
'character:model',
|
|
32
|
+
'character:step',
|
|
30
33
|
'character:land',
|
|
31
34
|
'character:water',
|
|
32
35
|
'dialogue:start',
|
|
@@ -44,11 +47,17 @@ export const ENGINE_EVENTS = [
|
|
|
44
47
|
'quest:done',
|
|
45
48
|
'quest:part',
|
|
46
49
|
'quest:fail',
|
|
50
|
+
'quest:unpaid',
|
|
51
|
+
'content:failed',
|
|
47
52
|
'photo:taken',
|
|
48
53
|
'photo:denied',
|
|
49
54
|
'trigger:enter',
|
|
50
55
|
'trigger:exit',
|
|
56
|
+
'level:loading',
|
|
51
57
|
'level:loaded',
|
|
58
|
+
'level:unloaded',
|
|
59
|
+
'level:playable',
|
|
60
|
+
'level:failed',
|
|
52
61
|
'timeline:start',
|
|
53
62
|
'timeline:end',
|
|
54
63
|
'template:stage',
|
|
@@ -75,6 +84,8 @@ export const ENGINE_EVENTS = [
|
|
|
75
84
|
'net:result',
|
|
76
85
|
'engine:error',
|
|
77
86
|
'module:disabled',
|
|
87
|
+
'module:restored',
|
|
88
|
+
'state:replaced',
|
|
78
89
|
'vehicle:enter',
|
|
79
90
|
'vehicle:exit',
|
|
80
91
|
'flow:change',
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// A copy of another owner's data, checked when it is read: rigid's mirror of the walls, a level's walls in the collision module, nav's obstacles, chunks on the ground.
|
|
2
|
+
// Why identity first and then version: a version counts per owner, so a new owner can match the old number with other data in it. Why on read: a frozen engine runs no
|
|
3
|
+
// step and a skip runs no frame, so a copy kept by hooks answers from the past exactly when a menu or a timer asks.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal sync(update) answers false while the copy is current; else it runs update(change), change being 'source' (another owner, or the first read: what was built in the
|
|
7
|
+
* old one is gone) or 'version' (the same owner changed), and answers change. The copy counts as current only once update returned: one that throws is built again by the next
|
|
8
|
+
* read. A read from inside update answers false, so a rebuild that asks its own owner does not start over. reset() makes the next read stale: the copy was thrown away.
|
|
9
|
+
* @template S @param {() => S} source who holds the data now @param {(s: S) => any} [version] that owner's change count
|
|
10
|
+
*/
|
|
11
|
+
export function follows(source, version) {
|
|
12
|
+
let held, at, read = false, busy = false;
|
|
13
|
+
return {
|
|
14
|
+
sync(update) {
|
|
15
|
+
if (busy) return false;
|
|
16
|
+
const s = source(), v = version?.(s);
|
|
17
|
+
if (read && s === held && v === at) return false;
|
|
18
|
+
const change = read && s === held ? 'version' : 'source';
|
|
19
|
+
busy = true;
|
|
20
|
+
try { update(change); } finally { busy = false; }
|
|
21
|
+
held = s; at = v; read = true;
|
|
22
|
+
return change;
|
|
23
|
+
},
|
|
24
|
+
reset() { read = false; },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Small shared helpers
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { codedError } from './errorHints.js';
|
|
4
|
+
|
|
5
|
+
// API convention: a position is one argument. The old (x, z, ...) form arrives as a number; throw with the fix (otherwise it silently becomes the origin)
|
|
6
|
+
const STRINGS = { position: 'A position must be passed as one argument: Vector3 / object / [x, y, z] / { x, z } (see the API conventions); got ' };
|
|
7
|
+
const POS_ERR = STRINGS.position;
|
|
8
|
+
/**
|
|
9
|
+
* The one bad-position error. It carries the value: an op tells a bad argument (refused) from a bad value of its own making (a bug, reported) by it.
|
|
10
|
+
* @param {string} message @param {any} value @param {ErrorConstructor} [Type] @internal
|
|
11
|
+
*/
|
|
12
|
+
export const badPosition = (message, value, Type) => Object.assign(codedError('bad-position', message, Type), { value });
|
|
13
|
+
// A horizontal position missing x or z (a 2-element [x, z] array reads z as undefined; { x, y } has no z) would become 0 silently
|
|
14
|
+
// (player.placeAt([10, 20]) at z = 0): say which part is missing and how to write it
|
|
15
|
+
const MAX_COORD = 1e9;
|
|
16
|
+
const VEC_ERR = 'A position or vector needs finite numbers in every part; got ';
|
|
17
|
+
const XZ_ERR = 'A horizontal position needs finite x and z: pass [x, y, z] (a 2-element [x, z] array does not work) or { x, z }; got ';
|
|
18
|
+
|
|
19
|
+
/** Round to one decimal (describe, budget reports) @param {number} v @returns {number} */
|
|
20
|
+
export const r1 = v => Math.round(v * 10) / 10;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Show a value someone set (style post params, exposure, light intensity) without changing it: 4 significant digits, never fewer than
|
|
24
|
+
* the integer part. r1 is for measurements (positions, ms); a set value rounded to one decimal misreports it (bloom 0.25 read as 0.3,
|
|
25
|
+
* contrast 1.12 as 1.1, R5), and a reader then "fixes" a value that was already right. 4 digits only drops float noise (0.30000000000000004).
|
|
26
|
+
* @param {number} v @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
export const rv = v => (Number.isFinite(v) && v !== 0 ? Number(v.toPrecision(Math.max(4, Math.floor(Math.log10(Math.abs(v))) + 1))) : v);
|
|
29
|
+
|
|
30
|
+
/** An angle in radians as the same turn in -PI..PI; of a difference, the short way round @param {number} a @returns {number} */
|
|
31
|
+
export const wrapAngle = a => Math.atan2(Math.sin(a), Math.cos(a));
|
|
32
|
+
|
|
33
|
+
const _world = new THREE.Vector3();
|
|
34
|
+
/** Where an Object3D stands: a position argument is a place in the world, and a child's .position is one in its parent's space */
|
|
35
|
+
const placeOf = o => (o.parent && !o.parent.isScene ? o.getWorldPosition(_world) : o.position);
|
|
36
|
+
|
|
37
|
+
/** Normalize a Vector3 / Object3D / [x, y, z] / { x, y, z } into a Vector3. Every part must be a finite number: a NaN let in here reaches the solver, the picture and the save far from the call that made it */
|
|
38
|
+
export function vec3(v, out = new THREE.Vector3()) {
|
|
39
|
+
if (v == null || v === false || v === '') return out;
|
|
40
|
+
if (typeof v !== 'object') throw badPosition(POS_ERR + JSON.stringify(v), v, TypeError);
|
|
41
|
+
if (v.isVector3) out.copy(v);
|
|
42
|
+
else if (v.isObject3D) out.copy(placeOf(v));
|
|
43
|
+
else if (Array.isArray(v)) out.set(v[0] ?? 0, v[1] ?? 0, v[2] ?? 0);
|
|
44
|
+
else out.set(v.x ?? 0, v.y ?? 0, v.z ?? 0);
|
|
45
|
+
if (!Number.isFinite(out.x) || !Number.isFinite(out.y) || !Number.isFinite(out.z)) throw badPosition(VEC_ERR + `[${out.x}, ${out.y}, ${out.z}]`, v, TypeError);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The height a position names, or undefined when it names none ({ x, z }) */
|
|
50
|
+
export function yOf(v) {
|
|
51
|
+
if (v?.isObject3D) v = placeOf(v);
|
|
52
|
+
const y = Array.isArray(v) ? v[1] : v?.y;
|
|
53
|
+
return Number.isFinite(y) ? y : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Get the horizontal coordinates [x, z] from a Vector3 / Object3D / [x, y, z] / { x, z } */
|
|
57
|
+
export function xzOf(v) {
|
|
58
|
+
if (!v || typeof v !== 'object') throw badPosition(POS_ERR + JSON.stringify(v), v, TypeError);
|
|
59
|
+
if (v.isObject3D) v = placeOf(v);
|
|
60
|
+
const x = Array.isArray(v) ? v[0] : v.x, z = Array.isArray(v) ? v[2] : v.z;
|
|
61
|
+
if (!Number.isFinite(x) || !Number.isFinite(z)) throw badPosition(XZ_ERR + JSON.stringify(v), v, TypeError);
|
|
62
|
+
// Far past float precision (render coordinates are 32-bit): not a place. Worse, the chunk loops (`for (cx = floor(x / size); ...; cx++)`) never advance once x / size passes 2^53, a silent freeze (found by fuzz: pos z = -3.6e178)
|
|
63
|
+
if (Math.abs(x) > MAX_COORD || Math.abs(z) > MAX_COORD) throw badPosition(`A horizontal position must lie within ±${MAX_COORD} (far past that nothing renders or streams correctly, and chunk loops stop advancing); got ` + JSON.stringify(v), v, RangeError);
|
|
64
|
+
return [x, z];
|
|
65
|
+
}
|
|
66
|
+
|
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
// several shapes: 'bool|object' (any of them; e.g. createEngine's batching: false or { ... }), checked like one type
|
|
7
7
|
import { closest, fmt, DEV, warnOnce, unknownOptionText } from './validate.js';
|
|
8
8
|
import { codedError, coded } from './errorHints.js';
|
|
9
|
+
import { isOptions, isObject } from './util.js';
|
|
9
10
|
|
|
10
11
|
/** Types an op arg may use: plain data only. Two meanings of 'id' on purpose: as a module param it is any string; as an op arg it must also be a world record id (checked in dev by opsCheck) */
|
|
11
12
|
export const OP_TYPES = ['string', 'number', 'int', 'bool', 'position', 'id', 'any'];
|
|
12
13
|
// 'color': 0xRRGGBB or '#rrggbb' (a model generator's params, shown as a color picker in the dev panel); not an op arg type
|
|
13
14
|
const TYPES = ['string', 'number', 'int', 'bool', 'position', 'id', 'any', 'object', 'array', 'function', 'color'];
|
|
14
|
-
const SPEC_KEYS = ['type', 'default', 'min', 'max', 'values', 'desc', 'optional'];
|
|
15
|
+
const SPEC_KEYS = ['type', 'default', 'min', 'max', 'values', 'desc', 'optional', 'label', 'rare']; // label, rare: how a panel shows the field
|
|
15
16
|
const isPos = v => Array.isArray(v) && (v.length === 2 || v.length === 3) && v.every(Number.isFinite);
|
|
16
17
|
/** type name -> value check (op args use the first seven: plain data only) */
|
|
17
18
|
const CHECK = {
|
|
18
19
|
string: v => typeof v === 'string', number: v => Number.isFinite(v), int: v => Number.isInteger(v), bool: v => typeof v === 'boolean',
|
|
19
|
-
position: isPos, id: v => typeof v === 'string', any: () => true, object:
|
|
20
|
+
position: isPos, id: v => typeof v === 'string', any: () => true, object: isObject,
|
|
20
21
|
array: Array.isArray, function: v => typeof v === 'function',
|
|
21
22
|
color: v => (Number.isInteger(v) && v >= 0 && v <= 0xffffff) || (typeof v === 'string' && /^#[0-9a-f]{6}$/i.test(v)),
|
|
22
23
|
};
|
|
@@ -33,8 +34,6 @@ const STRINGS = {
|
|
|
33
34
|
// Why cache: public APIs (collision.addCircle, particles.emit ...) call readParams on every call; the same schema object is parsed once;
|
|
34
35
|
// a literal schema written fresh each call is not cached (WeakMap keys by object, collected after use), it is just parsed once more
|
|
35
36
|
const parsed = new WeakMap(), keyCache = new WeakMap();
|
|
36
|
-
/** Is o an options object (not a number, string, array, Three.js object or vector)? Data checks use it where a field may also be a name or a list */
|
|
37
|
-
export const isOptions = o => !!o && typeof o === 'object' && !Array.isArray(o) && !o.isObject3D && !o.isVector3 && !o.isColor;
|
|
38
37
|
const parsedOf = (where, schema) => { let s = parsed.get(schema); if (!s) { s = parseSchema(where, schema); parsed.set(schema, s); } return s; };
|
|
39
38
|
|
|
40
39
|
/** Parse one field spec ('int?' or { type, default, ... }) into { type, optional, default?, min?, max?, values?, desc? }; throws on a bad spec */
|
|
@@ -91,14 +90,14 @@ export function schemaInfo(shape) {
|
|
|
91
90
|
for (const key in shape) {
|
|
92
91
|
const s = shape[key], o = /** @type {Record<string, any>} */ ({ type: s.type });
|
|
93
92
|
if (s.optional) o.optional = true;
|
|
94
|
-
for (const f of ['default', 'min', 'max', 'values', 'desc']) if (s[f] !== undefined && typeof s[f] !== 'function') o[f] = s[f];
|
|
93
|
+
for (const f of ['default', 'min', 'max', 'values', 'desc', 'label', 'rare']) if (s[f] !== undefined && typeof s[f] !== 'function') o[f] = s[f];
|
|
95
94
|
out[key] = o;
|
|
96
95
|
}
|
|
97
96
|
return out;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
/**
|
|
101
|
-
* Module options read through a params schema
|
|
100
|
+
* Module options read through a params schema, defaults filled in. A wrong type, a value out of range or a missing required option throws (with the fix) in every build, a release one too; an unknown key throws in dev only and warns once in a release build.
|
|
102
101
|
* Put the schema on the module definition too (`params`, `options`), so engine.catalog(name) shows every option, its default and the value in use.
|
|
103
102
|
* @param {string} where who reads them, for the error text (the module name)
|
|
104
103
|
* @param {Record<string, string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean }>} schema
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Load-time number checks. A part's load() passes each saved number through here, so a hand-edited or damaged value (a negative clock, a random
|
|
2
|
+
// state 'abc', a count of 1e308) never reaches the running game. Each bad value is clamped to its range (or replaced by a fallback when it is not
|
|
3
|
+
// a finite number at all), the rest of the part loads, and the part prints ONE warning listing what it fixed (save-value).
|
|
4
|
+
// Why clamp and not refuse: these are scalars with an obvious safe value; refusing the whole save over a clock of -1000 would cost the player the
|
|
5
|
+
// rest of the playthrough. Shapes that have no safe value (a record position, world/persist.js) are refused instead (save-bad-record).
|
|
6
|
+
//
|
|
7
|
+
// const v = saveValues('clock');
|
|
8
|
+
// this._now = v.num(d?.now, 'now', { min: 0, fallback: 0 });
|
|
9
|
+
// v.done(); // one warning for the part, only when something was fixed
|
|
10
|
+
import { warnOnce, fmt } from './validate.js';
|
|
11
|
+
import { coded, codedError } from './errorHints.js';
|
|
12
|
+
|
|
13
|
+
const STRINGS = {
|
|
14
|
+
warn: "[saves] save part '{part}' had {n} bad value(s), fixed while loading: {list}. The save was edited by hand or damaged; the next save writes the fixed values",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { SAVE_MAX, saveNumberOk } from './validate.js';
|
|
18
|
+
/** Clock seconds beyond this are damage: 30000 years of play, and much further a fixed step no longer moves the number, so time stops for good */
|
|
19
|
+
export const SAVE_MAX_SECONDS = 1e12;
|
|
20
|
+
/**
|
|
21
|
+
* Refuse a damaged save: throw save-bad-record, and saves.apply rolls the whole load back and reports this message. For shapes with no safe value.
|
|
22
|
+
* @param {string} part 'world', 'scene'...
|
|
23
|
+
* @param {string} path where in the part
|
|
24
|
+
* @param {string} why 'must be ...'
|
|
25
|
+
* @param {any} got
|
|
26
|
+
* @returns {never}
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export function refuseSave(part, path, why, got) {
|
|
30
|
+
throw codedError('save-bad-record', `${part} save: ${path} ${why} (got ${String(JSON.stringify(got)).slice(0, 120)}); the save was refused and the game was rolled back. The save was edited by hand or damaged: fix that field, or load another save`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Would a loader stay on this page's origin, inside the game's folders, with this text? new URL reads it as the browser's fetch does; a backslash or control character (read as a slash or dropped) has no place in a game's path */
|
|
34
|
+
const staysHome = name => {
|
|
35
|
+
if (/^[a-z][a-z\d+.-]*:|[\0-\x1f\\]|(^|\/)(\.|%2e){2}(\/|[?#]|$)/i.test(name)) return false;
|
|
36
|
+
try { const here = new URL(location.href), u = new URL(name, here); return u.protocol === here.protocol && u.host === here.host; } catch { return false; }
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A file name in a save, before anything loads it. A save is outside data (a shared file, a hand edit), so it names what the game knows and never decides where the game
|
|
40
|
+
* connects to: an asset entry the game made passes, whatever its URL; anything else must be a relative path on this origin. A reload forgets the paths a
|
|
41
|
+
* playthrough used, so "the game used it" can only be read as "it is one of the game's own paths". Refuses like refuseSave.
|
|
42
|
+
* @param {any} assets engine.assets
|
|
43
|
+
* @param {string} part
|
|
44
|
+
* @param {string} path where in the part
|
|
45
|
+
* @param {string} name
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export function checkSaveFile(assets, part, path, name) {
|
|
49
|
+
if (!assets.entries.has(name) && !staysHome(name)) refuseSave(part, path, 'must be a registered asset name or a relative path on this site', name);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A checker for one part's load: num() clamps / replaces, done() warns once when anything was fixed.
|
|
54
|
+
* @param {string} part
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export function saveValues(part) {
|
|
58
|
+
const fixed = [];
|
|
59
|
+
return {
|
|
60
|
+
/**
|
|
61
|
+
* @param {any} v the saved value
|
|
62
|
+
* @param {string} path for the warning
|
|
63
|
+
* @param {{ min?: number, max?: number, int?: boolean, fallback: number }} o
|
|
64
|
+
* @returns {number}
|
|
65
|
+
*/
|
|
66
|
+
num(v, path, { min = -Infinity, max = Infinity, int = false, fallback }) {
|
|
67
|
+
if (typeof v !== 'number' || !Number.isFinite(v)) { fixed.push(`${path} ${JSON.stringify(v) ?? 'undefined'} -> ${fallback}`); return fallback; }
|
|
68
|
+
let n = int ? Math.round(v) : v;
|
|
69
|
+
n = Math.min(max, Math.max(min, n));
|
|
70
|
+
if (n !== v) fixed.push(`${path} ${v} -> ${n}`);
|
|
71
|
+
return n;
|
|
72
|
+
},
|
|
73
|
+
/** Note a value dropped by the caller (a timer without a due time) */
|
|
74
|
+
drop(path, v) { fixed.push(`${path} ${String(JSON.stringify(v)).slice(0, 60)} dropped`); },
|
|
75
|
+
/** One warning for the part when anything was fixed; returns how many */
|
|
76
|
+
done() {
|
|
77
|
+
if (fixed.length) warnOnce(coded('save-value', fmt(STRINGS.warn, { part, n: fixed.length, list: fixed.slice(0, 6).join('; ') + (fixed.length > 6 ? '; …' : '') })));
|
|
78
|
+
return fixed.length;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Content sections: the one protocol for "this data becomes live state". A module owns a section through its `content` field:
|
|
2
|
+
// content: { quests: { desc, references, validate, prepare, commit, cancel } }
|
|
3
|
+
// validate(data, c) refuses bad data by throwing. prepare(data, c) does everything that can fail without touching the live game, and may be async.
|
|
4
|
+
// commit(prepared, c) swaps the prepared result in: it is the only step that changes state, so a failure before it leaves the old state whole. It returns
|
|
5
|
+
// DROPPED when this section gave way to a newer load of the same thing (the other sections go on), or a Promise for slow work nothing else stands on (a pack does not wait for it).
|
|
6
|
+
// waitFor(prepared, c): a Promise while the commits must wait for something newer that decides what they stand on; asked again when it ends. Every prepare is done by then.
|
|
7
|
+
// cancel(prepared, c): this prepare will not commit, let go of what it holds (prepared may be its Promise, still running: say so with a field on the Promise).
|
|
8
|
+
// undo(prepared, c): called just before commit; returns the function that puts back what this commit changes, whole or half done. A later step of the transaction
|
|
9
|
+
// failed, or this commit threw: every commit made so far is taken back, newest first, so state and registrations equal the state before it. That function may return a
|
|
10
|
+
// Promise (a level that has to load again): its first lines run in that order, what it waits for runs side by side, and the transaction fails only when all of it ended.
|
|
11
|
+
// What could not be put back rides on the error as err.notRestored, a list: the caller knows the old state is not whole.
|
|
12
|
+
// A commit that cannot leave a trace needs none; what a section without undo committed stays (a game kind's load is game code, so it runs after the modules' sections).
|
|
13
|
+
// Why one protocol: a level switch and a content pack are the same transaction at different sizes. Two forms would give them two failure rules.
|
|
14
|
+
// desc: one sentence for the docs and the "unknown content" error; the section's name and meaning are written here and nowhere else (metadata.mjs reads them).
|
|
15
|
+
// references(data): [{ section, id, at }], the ids this data names in other sections.
|
|
16
|
+
// effects: { word: { ref, desc, describe, run } }, effect words the section's owner runs, so replacing the module replaces its words too.
|
|
17
|
+
// live: true says one entry can be loaded again on its own in a running game, so the editor need not reload the page.
|
|
18
|
+
// once: true says commit gives state rather than a definition (starting goods): a module put back after a failed replaces has that state from its save part, so it is not committed again. A getter answers for this install: a level is state only once the save part brought it back.
|
|
19
|
+
// c from a content load: { engine, content, where, bind, zone, ids, origin, pickupId, track, after } (modules/content/loader.js).
|
|
20
|
+
import { codedError, coded } from './errorHints.js';
|
|
21
|
+
import { warnOnce } from './validate.js';
|
|
22
|
+
|
|
23
|
+
const KEYS = ['desc', 'references', 'validate', 'prepare', 'waitFor', 'commit', 'cancel', 'undo', 'effects', 'live', 'once'];
|
|
24
|
+
|
|
25
|
+
/** What a commit returns when it gave way to a newer load: this section is skipped, the newest stands, and the rest of the transaction goes on */
|
|
26
|
+
export const DROPPED = Symbol('section dropped');
|
|
27
|
+
|
|
28
|
+
/** An undo for a Map or Set a commit writes to: the function that puts its entries back. @param {Map<any, any> | Set<any>} t @returns {() => void} */
|
|
29
|
+
export function keepTable(t) {
|
|
30
|
+
const was = [...t];
|
|
31
|
+
return () => { t.clear(); for (const x of was) if (t instanceof Map) t.set(x[0], x[1]); else t.add(x); };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Every section of the installed modules: name -> { owner, ...section }. Two owners of one name are an error, not a last-writer-wins */
|
|
35
|
+
export function sectionsOf(e) {
|
|
36
|
+
const out = new Map();
|
|
37
|
+
for (const m of e.modules.values()) for (const [name, s] of Object.entries(m.content ?? {})) {
|
|
38
|
+
if (out.has(name)) throw codedError('content-misuse', `content section "${name}" has two owners, ${out.get(name).owner} and ${m.name}: keep one`);
|
|
39
|
+
const bad = Object.keys(s).find(k => !KEYS.includes(k));
|
|
40
|
+
if (bad) throw codedError('content-misuse', `content section "${name}" of module ${m.name}: unknown key "${bad}". Keys: ${KEYS.join(', ')}`);
|
|
41
|
+
if (typeof s.commit !== 'function') throw codedError('content-misuse', `content section "${name}" of module ${m.name} needs commit(prepared, c)`);
|
|
42
|
+
out.set(name, { owner: m.name, ...s });
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sections as one transaction, one or every pack of a load: all checked, then all prepared, then all committed in list order. Anything refused cancels what was prepared
|
|
49
|
+
* and nothing commits; a commit that throws takes back the commits before it (undo, above). With nothing to wait for the commits run on this tick, so a
|
|
50
|
+
* section is live on the next line; otherwise they run together once every prepare and `after` (an earlier transaction these stand on) are done, and a Promise of that
|
|
51
|
+
* comes back. Either way they run in one tick, so nothing reads a half-committed load. around runs the commits (content's window for writes). A failure whose undo has to wait
|
|
52
|
+
* rejects that Promise when the undo ended, even on the path that otherwise answers on this tick; around gets the Promise as fn's result.
|
|
53
|
+
* @param {{ s: any, data: any, done?: (committed: any) => void, gaveWay?: () => void }[]} list done: called after the section's commit with what it returned; gaveWay: when it returned DROPPED
|
|
54
|
+
* @param {any} c
|
|
55
|
+
* @param {{ after?: Promise<any> | null, around?: (fn: () => (void | Promise<void>)) => any }} [opts]
|
|
56
|
+
* @returns {Promise<void> | undefined}
|
|
57
|
+
*/
|
|
58
|
+
export function runSections(list, c, { after = null, around = fn => fn() } = {}) {
|
|
59
|
+
for (const { s, data } of list) s.validate?.(data, c);
|
|
60
|
+
const prepared = [];
|
|
61
|
+
const cancel = from => {
|
|
62
|
+
for (let i = prepared.length - 1; i >= from; i--) {
|
|
63
|
+
prepared[i]?.then?.(null, () => {}); // nobody waits for it now, so its failure is nobody's error
|
|
64
|
+
list[i].s.cancel?.(prepared[i], c);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
try { for (const { s, data } of list) prepared.push(s.prepare ? s.prepare(data, c) : data); }
|
|
68
|
+
catch (err) { cancel(0); throw err; }
|
|
69
|
+
const commit = values => {
|
|
70
|
+
const undos = [];
|
|
71
|
+
const takeBack = cause => {
|
|
72
|
+
const lost = [], waits = [];
|
|
73
|
+
const told = err => { lost.push(err); warnOnce(coded('content-misuse', `content: an undo failed, so part of a failed load may remain: ${err.message}`)); };
|
|
74
|
+
for (const fn of undos.reverse()) {
|
|
75
|
+
try { const r = fn(); if (typeof r?.then === 'function') waits.push(r.catch(told)); } catch (err) { told(err); } // the rest still goes back
|
|
76
|
+
}
|
|
77
|
+
const fail = () => { if (lost.length) cause.notRestored = lost; throw cause; };
|
|
78
|
+
if (waits.length) return Promise.all(waits).then(fail);
|
|
79
|
+
fail();
|
|
80
|
+
};
|
|
81
|
+
let i = 0;
|
|
82
|
+
try {
|
|
83
|
+
for (; i < list.length; i++) {
|
|
84
|
+
const undo = list[i].s.undo?.(values[i], c);
|
|
85
|
+
if (undo) undos.push(undo);
|
|
86
|
+
const r = list[i].s.commit(values[i], c);
|
|
87
|
+
if (r === DROPPED) { if (undo) undos.pop(); list[i].gaveWay?.(); } else list[i].done?.(r);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) { cancel(i + 1); return takeBack(err); }
|
|
90
|
+
};
|
|
91
|
+
if (!after && !prepared.some(p => typeof p?.then === 'function')) return around(() => commit(prepared));
|
|
92
|
+
const settled = values => {
|
|
93
|
+
const waits = list.flatMap((l, i) => l.s.waitFor?.(values[i], c) ?? []);
|
|
94
|
+
return waits.length ? Promise.all(waits).then(() => settled(values)) : around(() => commit(values));
|
|
95
|
+
};
|
|
96
|
+
return Promise.all([after, ...prepared]).then(([, ...values]) => settled(values), err => { cancel(0); throw err; });
|
|
97
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Spelling helpers with no imports: "did you mean" in the engine's runtime checks (validate.js) and in the tools (packages/tools/lib/text.mjs),
|
|
2
|
+
// and the node-name rule that the asset report and `threedog assets check` both apply. One copy each; a change here changes both.
|
|
3
|
+
|
|
4
|
+
/** Edit distance (case-insensitive; swapping two adjacent letters counts as 1, e.g. jupm -> jump) */
|
|
5
|
+
export function distance(a, b) {
|
|
6
|
+
a = a.toLowerCase(); b = b.toLowerCase();
|
|
7
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i]);
|
|
8
|
+
for (let j = 1; j <= b.length; j++) d[0][j] = j;
|
|
9
|
+
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
|
|
10
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
11
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
12
|
+
}
|
|
13
|
+
return d[a.length][b.length];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The entry of list closest to name; null if too far. Without maxDist the limit scales with length (longer names tolerate more errors).
|
|
18
|
+
* Too far by spelling, a name of 4+ letters that is part of exactly one entry still matches ('forward' -> 'moveForward'): AIs often drop a prefix.
|
|
19
|
+
*/
|
|
20
|
+
export function closest(name, list, maxDist) {
|
|
21
|
+
name = String(name);
|
|
22
|
+
const limit = maxDist ?? (name.length <= 4 ? 1 : name.length <= 8 ? 2 : 3);
|
|
23
|
+
let best = null, bd = Infinity;
|
|
24
|
+
for (const c of list) { if (c === name) continue; const d = distance(name, String(c)); if (d < bd) { bd = d; best = c; } }
|
|
25
|
+
if (bd <= limit) return best;
|
|
26
|
+
if (maxDist != null || name.length < 4) return null;
|
|
27
|
+
const low = name.toLowerCase(), part = [...list].filter(c => String(c).toLowerCase().includes(low));
|
|
28
|
+
return part.length === 1 ? part[0] : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** three's PropertyBinding.sanitizeNodeName: the name the engine sees ("door.001" -> "door001", spaces -> "_") */
|
|
32
|
+
export const sanitize = n => String(n ?? '').replace(/\s/g, '_').replace(/[[\].:/]/g, '');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Small shared core helpers. One definition each, so "what counts as a plain object" and "how a dotted path is read" cannot drift apart.
|
|
2
|
+
|
|
3
|
+
/** A plain data object: { } or Object.create(null); not an array, class instance, three.js object or function */
|
|
4
|
+
export const isPlainObject = v => isObject(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v));
|
|
5
|
+
/** Is v an object at all (class instances count; not null, not an array)? isPlainObject is the strict answer, for data that must stay plain */
|
|
6
|
+
export const isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
7
|
+
/** Is o an options object a game passed (not a number, string, array, Three.js object, vector or color)? Data checks use it where a field may also be a name or a list */
|
|
8
|
+
export const isOptions = o => isObject(o) && !o.isObject3D && !o.isVector3 && !o.isColor;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* f() or null when it throws. For read-only reports (thing.explain and its module parts) that join several sources: one source that cannot
|
|
12
|
+
* answer (an unknown template, a disposed part) leaves its field null instead of failing the whole report. Never for gameplay paths.
|
|
13
|
+
*/
|
|
14
|
+
export const orNull = f => { try { return f(); } catch { return null; } };
|
|
15
|
+
|
|
16
|
+
/** One value or a list, as a list @template T @param {T | T[]} v @returns {T[]} */
|
|
17
|
+
export const list = v => (Array.isArray(v) ? v : [v]);
|
|
18
|
+
|
|
19
|
+
/** A model name in model / lod position: 'pine' or ['flower', 0xff0000] (content data and vegetation.define take the same form) @param {any} m */
|
|
20
|
+
export const isModelName = m => typeof m === 'string' || Array.isArray(m) && typeof m[0] === 'string';
|
|
21
|
+
|
|
22
|
+
/** Is o root, or does it hang under root? @param {any} o @param {any} root */
|
|
23
|
+
export function isUnder(o, root) { for (let p = o; p; p = p.parent) if (p === root) return true; return false; }
|
|
24
|
+
/** Is o visible, itself and every parent (what traverseVisible checks)? @param {any} o */
|
|
25
|
+
export function isShown(o) { for (let p = o; p; p = p.parent) if (!p.visible) return false; return true; }
|
|
26
|
+
|
|
27
|
+
/** Read a dotted path ('a.b.c'); undefined as soon as a step is missing @param {any} obj @param {string} path */
|
|
28
|
+
export function getPath(obj, path) {
|
|
29
|
+
let v = obj;
|
|
30
|
+
for (const k of path.split('.')) v = v?.[k];
|
|
31
|
+
return v;
|
|
32
|
+
}
|