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,20 +1,21 @@
|
|
|
1
|
-
// Read 'file.js:50' places out of an Error stack: where a thing was added (things.js)
|
|
1
|
+
// Read 'file.js:50' places out of an Error stack: where a thing was added (things.js) or took
|
|
2
2
|
// a shared point (sharedPoint.js: the conflict error names both sides' lines).
|
|
3
3
|
// Why one file: the two copies of the frame regex drifted apart once already (a query string after the file name, a Windows path), and a fix made in
|
|
4
4
|
// one never reached the other. Both read V8 and Firefox / Safari frame lines ("at f (http://host/src/main.js?v=1:50:7)" and "f@http://host/src/main.js:50:7").
|
|
5
|
-
import { DEV } from '
|
|
5
|
+
import { DEV } from '../base/validate.js';
|
|
6
6
|
const FRAME = /\(?((?:[a-z]+:\/\/[^/\s]+)?[^\s()]+?\.[cm]?[jt]sx?)(?:\?[^:\s)]*)?:(\d+):\d+\)?\s*$/i;
|
|
7
7
|
const FUNC = /^[^@\s/]*@(?=[a-z]+:\/\/)/i;
|
|
8
|
+
const NAME = /^\s*(?:at\s+(?:async\s+)?([^\s(]+(?: \[as [^\]]+\])?)\s+\(|([^@\s/]+)@)/; // V8 "at name (file" / Firefox "name@file"; none for an anonymous function
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* The frames of a stack text that name a source file, outermost call last: [{ file, line }]. file keeps its URL host (so a caller can tell engine
|
|
11
|
+
* The frames of a stack text that name a source file, outermost call last: [{ file, line, fn }]. fn: the function name, '' when anonymous. file keeps its URL host (so a caller can tell engine
|
|
11
12
|
* files from game files by path) with Windows backslashes turned into slashes.
|
|
12
|
-
* @param {string} stack @returns {{ file: string, line: number }[]}
|
|
13
|
+
* @param {string} stack @returns {{ file: string, line: number, fn: string }[]}
|
|
13
14
|
*/
|
|
14
15
|
export function stackFrames(stack) {
|
|
15
16
|
const out = [];
|
|
16
17
|
// FUNC: a Firefox / Safari line puts the function name before the URL ("add@http://..."); dropped only before a scheme, so '/@scope/' paths stay
|
|
17
|
-
for (const l of String(stack ?? '').split('\n')) { const f = FRAME.exec(l); if (f) out.push({ file: f[1].replace(FUNC, '').replace(/\\/g, '/'), line: +f[2] }); }
|
|
18
|
+
for (const l of String(stack ?? '').split('\n')) { const f = FRAME.exec(l); if (f) { const n = NAME.exec(l); out.push({ file: f[1].replace(FUNC, '').replace(/\\/g, '/'), line: +f[2], fn: n?.[1] ?? n?.[2] ?? '' }); } }
|
|
18
19
|
return out;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -22,6 +23,16 @@ export function stackFrames(stack) {
|
|
|
22
23
|
export const frameText = f => `${f.file.replace(/^[a-z]+:\/\/[^/]+\//i, '').replace(/^\/+/, '')}:${f.line}`;
|
|
23
24
|
|
|
24
25
|
const ENGINE_FRAME = /(?:engine|threedog)\/(?:core|modules|render|ui)\//; // engine code (engine.mod called from inside the engine) is skipped: `at` names the game's line
|
|
26
|
+
const ENGINE_PARTS = /^(?:core|modules|render|ui)\//;
|
|
27
|
+
// the engine's own folder as this page's server names it. Why not only the path pattern above: a page served from the engine's folder (its tests) has
|
|
28
|
+
// /core/x.js with no 'engine' in it, and a game's own core/ folder must not pass for the engine's. String work, not new URL('..', import.meta.url): a bundler reads that form as an asset
|
|
29
|
+
const engineDir = () => import.meta.url.replace(/\?.*$/, '').replace(/(?:[^/]*\/){2}[^/]*$/, '');
|
|
30
|
+
|
|
31
|
+
/** Is this frame file the engine's own code? @param {string} file a frame's file */
|
|
32
|
+
export function engineFile(file) {
|
|
33
|
+
const dir = engineDir();
|
|
34
|
+
return ENGINE_FRAME.test(file) || (file.startsWith(dir) && ENGINE_PARTS.test(file.slice(dir.length)));
|
|
35
|
+
}
|
|
25
36
|
|
|
26
37
|
/** 'main.js:50' of the first caller outside the engine (dev only: release builds keep no stacks) */
|
|
27
38
|
export function callerAt() {
|
|
@@ -29,6 +40,6 @@ export function callerAt() {
|
|
|
29
40
|
const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error); // stackTraceLimit is V8's (Chrome), not in the DOM typings
|
|
30
41
|
const lim = E.stackTraceLimit; E.stackTraceLimit = 14;
|
|
31
42
|
const stack = String(new Error().stack ?? ''); E.stackTraceLimit = lim;
|
|
32
|
-
const f = stackFrames(stack).find(x => !
|
|
43
|
+
const f = stackFrames(stack).find(x => !engineFile(x.file));
|
|
33
44
|
return f ? frameText(f) : null;
|
|
34
45
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// engine.stacks: the registry of every shared point (the point itself and its rules are core/sharedPoint.js). Here: define / get / mod, the timers
|
|
1
|
+
// engine.stacks: the registry of every shared point (the point itself and its rules are core/ops/sharedPoint.js). Here: define / get / mod, the timers
|
|
2
2
|
// behind `for`, saving entries, and describe().shared. Kept apart from sharedPoint.js only for size: the rules read without the bookkeeping between.
|
|
3
|
-
import { codedError } from '
|
|
4
|
-
import { DEV, warnOnce } from '
|
|
3
|
+
import { codedError } from '../base/errorHints.js';
|
|
4
|
+
import { DEV, warnOnce } from '../base/validate.js';
|
|
5
5
|
import { Stack } from './sharedPoint.js';
|
|
6
6
|
|
|
7
7
|
const KEYS = ['owner', 'set', 'add', 'mul', 'clamp', 'value', 'for', 'clock', 'id', 'layer'];
|
|
8
|
-
// Saved: engine /
|
|
8
|
+
// Saved: engine / game / effect entries (what the playthrough did). Not saved: system / debug (menus, cutscenes, debug: "what the
|
|
9
9
|
// screen is doing now", retaken after a load), settings (the settings module re-applies the player's choices from its own prefs)
|
|
10
|
-
const SAVED = new Set(['engine', '
|
|
10
|
+
const SAVED = new Set(['engine', 'game', 'effect']);
|
|
11
11
|
const saved = e => SAVED.has(e.layer);
|
|
12
12
|
|
|
13
13
|
/** engine.stacks: every shared point by name; engine.mod(name, o) is the one way to change one */
|
|
@@ -17,33 +17,31 @@ export class Stacks {
|
|
|
17
17
|
/** @type {Map<string, Stack>} */ this._all = new Map();
|
|
18
18
|
/** @internal saved entries of a point the game has not defined yet: applied when it does */ this._pending = {};
|
|
19
19
|
this._version = 0; this._timedDirty = false;
|
|
20
|
-
/** @internal now on a clock ('real' or a channel); core/time.js replaces it */ this._nowOf = () => 0;
|
|
21
|
-
// since = game clock time of the take (
|
|
20
|
+
/** @internal now on a clock ('real' or a channel); core/time/time.js replaces it */ this._nowOf = () => 0;
|
|
21
|
+
// since = game clock time of the take (calendar seconds), not engine.time.now('real'): session.newGame resets the clock, so an entry a fresh
|
|
22
22
|
// playthrough makes reads the same in every new game
|
|
23
|
-
this._at = () =>
|
|
24
|
-
this._hooked = false; this._hook();
|
|
23
|
+
this._at = () => this._nowOf('calendar');
|
|
25
24
|
}
|
|
26
|
-
/** @internal saves and world:remove. The registry is made before them (Engine.js: the
|
|
27
|
-
* createServices calls this
|
|
25
|
+
/** @internal saves and world:remove. The registry is made before them (Engine.js: the drawing parts' points exist from the first drawing part on);
|
|
26
|
+
* createServices calls this once saves and events exist */
|
|
28
27
|
_hook() {
|
|
29
28
|
const e = this.engine;
|
|
30
|
-
if (this._hooked || !e.saves || !e.events) return;
|
|
31
|
-
this._hooked = true;
|
|
32
29
|
e.saves.register('stacks', { save: () => this._save(), load: d => this._load(d) });
|
|
33
|
-
|
|
30
|
+
// input.keys and input.gate key their entries by action name, not record id: a removed record 'fire' must not unbind the action 'fire'
|
|
31
|
+
e.events.on('world:remove', ({ id }) => { for (const s of this._all.values()) if (s.per && !s.name.startsWith('input.')) s.dropId(id); });
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* Define a shared point (engine modules and games use the same call). kind: 'number' (default; base 1), 'value' (any data, set only), 'any'
|
|
37
35
|
* (true while held), 'top' (latest holder wins), 'one' (an exclusive slot; modules take theirs with `provides`).
|
|
38
36
|
* per: true = one value per record id (mod with { id }); per: 'optional' = an entry with { id } is that record's, one without is every record's
|
|
39
37
|
* (move.speed: haste on the player, mud on everyone). save: false keeps it out of saves (screen state like the camera holder).
|
|
40
|
-
* manual: the copyable takeover call the conflict error offers (a
|
|
38
|
+
* manual: the copyable takeover call the conflict error offers (a drawing part's manual()).
|
|
41
39
|
* @param {string} name @param {{ kind?: 'number' | 'value' | 'any' | 'top' | 'one', base?: any, min?: number, max?: number, per?: boolean | 'optional', save?: boolean, manual?: string, settingsSet?: boolean, onChange?: (id: string | null) => void }} [o]
|
|
42
40
|
* @returns {Stack}
|
|
43
41
|
* @example engine.stacks.define('damageTaken', { per: true, min: 0 }); engine.mod('damageTaken', { owner: 'shield', id: 'player', mul: 0.5, for: 3 });
|
|
44
42
|
*/
|
|
45
43
|
define(name, o = {}) {
|
|
46
|
-
if (this._all.has(name)) throw codedError('
|
|
44
|
+
if (this._all.has(name)) throw codedError('engine-misuse', `engine.stacks.define('${name}'): already defined; read it with engine.stacks.get('${name}')`);
|
|
47
45
|
const s = new Stack(this, name, o);
|
|
48
46
|
this._all.set(name, s);
|
|
49
47
|
if (this._pending[name]) { this._loadOne(s, this._pending[name]); delete this._pending[name]; }
|
|
@@ -61,7 +59,7 @@ export class Stacks {
|
|
|
61
59
|
list() { return [...this._all.keys()]; }
|
|
62
60
|
/**
|
|
63
61
|
* The one entry: change a shared point; returns a handle whose remove() ends only this owner's entry.
|
|
64
|
-
* @param {string} name @param {{ owner: string, set?: any, add?: number, mul?: number, clamp?: { min?: number, max?: number }, value?: any, for?: number, clock?: string, id?: string, layer?: 'engine' | '
|
|
62
|
+
* @param {string} name @param {{ owner: string, set?: any, add?: number, mul?: number, clamp?: { min?: number, max?: number }, value?: any, for?: number, clock?: string, id?: string, layer?: 'engine' | 'game' | 'effect' | 'system' | 'settings' | 'debug' }} o
|
|
65
63
|
* @returns {{ owner: string, remove(): void, change(value: any): boolean }} remove() ends it; change(v) rewrites its value in place (same op, layer)
|
|
66
64
|
*/
|
|
67
65
|
mod(name, o) {
|
|
@@ -79,7 +77,7 @@ export class Stacks {
|
|
|
79
77
|
if (s.per) {
|
|
80
78
|
for (const id of s.ids()) out[`${s.name}[${id}]`] = s.row(id);
|
|
81
79
|
if (s.size()) out[`${s.name}[*]`] = s.row();
|
|
82
|
-
} else if (s.size()
|
|
80
|
+
} else if (s.size()) out[s.name] = s.row();
|
|
83
81
|
}
|
|
84
82
|
return out;
|
|
85
83
|
}
|
|
@@ -104,7 +102,7 @@ export class Stacks {
|
|
|
104
102
|
return out;
|
|
105
103
|
}
|
|
106
104
|
/**
|
|
107
|
-
* @internal End every entry whose time is up (core/time.js calls it after advancing the clocks), earliest first; emits mod:end for each.
|
|
105
|
+
* @internal End every entry whose time is up (core/time/time.js calls it after advancing the clocks), earliest first; emits mod:end for each.
|
|
108
106
|
* @returns {number} how many ended
|
|
109
107
|
*/
|
|
110
108
|
_expire() {
|
|
@@ -119,7 +117,7 @@ export class Stacks {
|
|
|
119
117
|
}
|
|
120
118
|
return due.length;
|
|
121
119
|
}
|
|
122
|
-
/** @internal smallest time left on any timed entry, converted to
|
|
120
|
+
/** @internal smallest time left on any timed entry, converted to calendar seconds by toGame(clock, left) (engine.skip ends a segment there) */
|
|
123
121
|
_untilNext(toGame) {
|
|
124
122
|
let best = Infinity;
|
|
125
123
|
for (const [, e] of this._timed()) best = Math.min(best, toGame(e.clock, Math.max(0, e.until - this._nowOf(e.clock))));
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
// The wrapper is installed on the object itself, so every caller of that method goes through it: the game, the module's ops (the op
|
|
11
11
|
// inventory.transfer calls engine.inventory.transfer) and other modules alike. It wraps one method, not a behaviour: a rule that must hold for
|
|
12
12
|
// every way items enter the bag wraps each api method that can do it (add and transfer), or uses the module's own option (maxWeight).
|
|
13
|
-
//
|
|
14
|
-
import { fmt } from '
|
|
15
|
-
import { codedError } from '
|
|
13
|
+
// Wrap what the contract lists (modules/<m>/contract.js). A name starting with '_' is the module's inside: it works, and dev warns once that it may change.
|
|
14
|
+
import { DEV, fmt, warnOnce } from '../base/validate.js';
|
|
15
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
16
16
|
|
|
17
17
|
const STRINGS = {
|
|
18
|
-
target:
|
|
18
|
+
target: 'engine.wrap(target, method, fn): target is an object with the method, such as engine.inventory or engine.flow; got {got}',
|
|
19
19
|
fn: "engine.wrap(target, '{method}', fn): fn must be a function (next, ...args) => ..., e.g. (next, ...a) => next(...a)",
|
|
20
|
-
|
|
20
|
+
name: "engine.wrap(target, method, fn): method is a method name, got {method}; public methods: {list}",
|
|
21
|
+
priv: "engine.wrap({name}, '{method}'): '{method}' is the object's inside (leading _), so an engine update may change it without notice. Public methods: {list}",
|
|
21
22
|
missing: "engine.wrap({name}, '{method}'): {name} has no method '{method}'; public methods: {list}",
|
|
22
23
|
};
|
|
23
24
|
|
|
@@ -55,7 +56,8 @@ export class Wraps {
|
|
|
55
56
|
if (!target || (typeof target !== 'object' && typeof target !== 'function')) throw codedError('wrap-misuse', fmt(STRINGS.target, { got: target === null ? 'null' : typeof target }), TypeError);
|
|
56
57
|
if (typeof fn !== 'function') throw codedError('wrap-misuse', fmt(STRINGS.fn, { method }), TypeError);
|
|
57
58
|
const name = this._name(target);
|
|
58
|
-
if (typeof method !== 'string'
|
|
59
|
+
if (typeof method !== 'string') throw codedError('wrap-misuse', fmt(STRINGS.name, { method: String(method), list: methodsOf(target).join(', ') }));
|
|
60
|
+
if (DEV && method.startsWith('_')) warnOnce(coded('wrap-misuse', fmt(STRINGS.priv, { name, method, list: methodsOf(target).join(', ') })));
|
|
59
61
|
let slots = this._map.get(target);
|
|
60
62
|
if (!slots) this._map.set(target, slots = new Map());
|
|
61
63
|
let slot = slots.get(method);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { codedError } from '
|
|
1
|
+
import { codedError } from '../base/errorHints.js';
|
|
2
2
|
// Save storage layer: uses the browser's native IndexedDB (no third-party library) and falls back to localStorage when it is unavailable. Saves uses it; modules never touch it directly.
|
|
3
3
|
//
|
|
4
4
|
// Two stores in the database:
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
// Several tabs of one game share the storage. Each write carries a rev; a tab overwrites a slot only while the stored rev is the one it last read,
|
|
11
11
|
// wrote or loaded (compare-and-write in one IndexedDB transaction), so a forgotten tab's autosave can never replace newer progress made in another
|
|
12
12
|
// tab: that save is refused (false, toast, save-stale). A BroadcastChannel tells the other tabs a slot changed, so their list / load see it at once.
|
|
13
|
-
/** @import { SaveProvider } from '
|
|
13
|
+
/** @import { SaveProvider } from '../../types/core' */
|
|
14
14
|
import { SaveStore } from './SaveStore.js';
|
|
15
|
-
import { checkTypeRule } from '
|
|
16
|
-
import { toast } from '
|
|
17
|
-
import { warnOnce, fmt } from '
|
|
18
|
-
import { readParams, keysSchema } from '
|
|
19
|
-
import { reportError } from '
|
|
20
|
-
import { codedError, coded } from '
|
|
15
|
+
import { checkTypeRule } from '../engine/moduleTypes.js';
|
|
16
|
+
import { toast } from '../../ui/UI.js';
|
|
17
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
18
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
19
|
+
import { reportError } from '../base/errors.js';
|
|
20
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
21
21
|
import { checkPartVersion, readSave } from './saveVersions.js';
|
|
22
22
|
import { exportSaveFile, importSaveFile, importText, SAVE_STRINGS } from './saveFiles.js';
|
|
23
23
|
import { applySave, loadSlot, adoptPart, collectParts } from './saveApply.js';
|
|
@@ -37,8 +37,8 @@ export class Saves {
|
|
|
37
37
|
/** @internal */
|
|
38
38
|
constructor(engine, { prefix = 'game-' } = {}) {
|
|
39
39
|
/** @internal */ this.engine = engine;
|
|
40
|
-
/**
|
|
41
|
-
this.
|
|
40
|
+
/** @internal Start of the key names in the localStorage fallback and of the IndexedDB database name; a module asks storageKey(name) instead */
|
|
41
|
+
this._prefix = prefix + 'save-';
|
|
42
42
|
/** @internal */ this.providers = new Map();
|
|
43
43
|
/** @internal */ this._auto = null;
|
|
44
44
|
/** @internal Slot -> JSON text (all saves stay in memory: list / check / export are synchronous) */ this._json = new Map();
|
|
@@ -50,7 +50,7 @@ export class Saves {
|
|
|
50
50
|
this._tab = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${performance.now()}`; // wall-clock: only a fallback id, unique per tab
|
|
51
51
|
/** @internal */ this._n = 0;
|
|
52
52
|
/** @internal other tabs of this game: 'slot changed' notes */
|
|
53
|
-
this._bc = typeof BroadcastChannel === 'function' ? new BroadcastChannel(this.
|
|
53
|
+
this._bc = typeof BroadcastChannel === 'function' ? new BroadcastChannel(this._prefix + 'db') : null;
|
|
54
54
|
if (this._bc) this._bc.onmessage = ev => this._remote(ev.data?.slot);
|
|
55
55
|
/** @internal Parts of the last loaded save that no registered module owns (a module not installed in this build): written back unchanged on every save */
|
|
56
56
|
this._foreign = { parts: {}, versions: {} };
|
|
@@ -59,8 +59,9 @@ export class Saves {
|
|
|
59
59
|
* Storage layer: saves in the IndexedDB slots store, attachments (by group, e.g. 'photo') in the blobs store; mode 'localStorage' without IndexedDB.
|
|
60
60
|
* @type {{ mode: 'idb' | 'localStorage', blobs(group?: string): Promise<{ group: string, id: string, at: number, blob: Blob, meta: any }[]>,
|
|
61
61
|
* putBlob(group: string, id: string, blob: Blob, meta?: any, at?: number): Promise<void>, deleteBlob(group: string, id: string): Promise<void> }}
|
|
62
|
+
* @experimental
|
|
62
63
|
*/
|
|
63
|
-
this.store = /** @type {any} */ (new SaveStore(this.
|
|
64
|
+
this.store = /** @type {any} */ (new SaveStore(this._prefix + 'db', this._prefix));
|
|
64
65
|
/** Has the save index been read into memory? (start() waits for it; game code rarely needs to care) */
|
|
65
66
|
this.ready = false;
|
|
66
67
|
/** Resolves once the save index is in memory; await it only to list / load before start() @type {Promise<void>} */
|
|
@@ -73,9 +74,6 @@ export class Saves {
|
|
|
73
74
|
* shape.
|
|
74
75
|
* A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept).
|
|
75
76
|
* A part registered after a save was loaded (a module installed later) is handed its data from that save at once.
|
|
76
|
-
* movedFrom: { oldPart: data => newData } when this part's data used to be saved under another part's name (a module split in two: the calendar's
|
|
77
|
-
* time and day were part 'sky'); an old save without this part but with oldPart hands that data, converted, to this part, and oldPart is dropped
|
|
78
|
-
* (unless a registered part still owns that name).
|
|
79
77
|
* atomic: true joins this part to atomic ops: it is copied before an atomic op runs and put back if the op fails (plain data only; afterLoad does not run on rollback).
|
|
80
78
|
* checkNewGame(data): dev only, called once start() finished with this part's data in the new-game state, to warn about what should not be there yet
|
|
81
79
|
* (world: records placed by code instead of content). The part knows its own format; core only hands the data over.
|
|
@@ -88,14 +86,11 @@ export class Saves {
|
|
|
88
86
|
*/
|
|
89
87
|
register(key, provider) {
|
|
90
88
|
checkTypeRule(this.engine, 'saves.register', `registered save part '${key}'`);
|
|
91
|
-
readParams(`saves.register('${key}')`, keysSchema(['save', 'load', 'first', 'version', 'migrate', 'atomic', '
|
|
92
|
-
const { save, load, first = false, version = 1, migrate = {}, atomic = false,
|
|
93
|
-
checkPartVersion(key, version, migrate
|
|
94
|
-
this.providers.set(key, { save, load, first, version, migrate, atomic: atomic === true,
|
|
89
|
+
readParams(`saves.register('${key}')`, keysSchema(['save', 'load', 'first', 'version', 'migrate', 'atomic', 'checkNewGame']), provider);
|
|
90
|
+
const { save, load, first = false, version = 1, migrate = {}, atomic = false, checkNewGame = null } = provider;
|
|
91
|
+
checkPartVersion(key, version, migrate);
|
|
92
|
+
this.providers.set(key, { save, load, first, version, migrate, atomic: atomic === true, checkNewGame });
|
|
95
93
|
this.engine.session._late(key); // a part registered after start() (a module installed later) joins the new-game state as it is now
|
|
96
|
-
// registered after a save was loaded: the old part's data is still kept as foreign, move it over now (the same step readSave does on load)
|
|
97
|
-
const F = this._foreign, old = movedFrom && !(key in F.parts) && Object.keys(movedFrom).find(o => o in F.parts && !this.providers.has(o));
|
|
98
|
-
if (old) { F.parts[key] = movedFrom[old](structuredClone(F.parts[old])); F.versions[key] = version; delete F.parts[old]; delete F.versions[old]; }
|
|
99
94
|
if (key in this._foreign.parts) adoptPart(this, key);
|
|
100
95
|
}
|
|
101
96
|
/**
|
|
@@ -110,18 +105,14 @@ export class Saves {
|
|
|
110
105
|
const idb = await this.store.open();
|
|
111
106
|
if (!idb) warnOnce(coded('indexeddb', DEV_STRINGS.noIdb));
|
|
112
107
|
try {
|
|
113
|
-
for (const r of await this.store.slots())
|
|
114
|
-
this.
|
|
108
|
+
for (const r of await this.store.slots()) {
|
|
109
|
+
this._rev.set(r.slot, r.rev ?? ''); this._mine.set(r.slot, r.rev ?? ''); // also for a save made before this ran: its write comes after and expects this record
|
|
110
|
+
if (!this._json.has(r.slot)) { this._json.set(r.slot, r.json); this._meta.set(r.slot, r.savedAt); }
|
|
115
111
|
}
|
|
116
112
|
} catch (e) { this._fail(e); }
|
|
117
113
|
}
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
* @template T
|
|
121
|
-
* @param {() => Promise<T>} fn
|
|
122
|
-
* @returns {Promise<T>}
|
|
123
|
-
*/
|
|
124
|
-
queue(fn) {
|
|
114
|
+
/** @internal Disk writes run in call order once storage is ready, and flush waits for them: the one place that order is kept */
|
|
115
|
+
_enqueue(fn) {
|
|
125
116
|
const p = this._queue.then(() => this.whenReady).then(fn);
|
|
126
117
|
this._queue = p.catch(() => {});
|
|
127
118
|
return p;
|
|
@@ -133,6 +124,36 @@ export class Saves {
|
|
|
133
124
|
else warnOnce(coded('save-write', `[saves] failed to write ${slot ? `slot "${slot}"` : 'save'}: ${err?.message ?? err}`));
|
|
134
125
|
toast(this.engine, why, { kind: 'error', ms: 5000 });
|
|
135
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Store a binary attachment outside the world save (a photo, a replay). It rides in the queue of save writes, so flush() waits for it, and exportFile() carries it.
|
|
129
|
+
* Pass a function to make the bytes when the write runs: flush() then waits for that too. Without IndexedDB it is not kept.
|
|
130
|
+
* @example await engine.saves.putAttachment('replay', 'run-1', blob, { score: 12 });
|
|
131
|
+
* @param {string} group what the attachment is for
|
|
132
|
+
* @param {string} id unique inside the group; the same id replaces
|
|
133
|
+
* @param {Blob | (() => Promise<Blob>)} blob
|
|
134
|
+
* @param {any} [meta] plain data kept with it
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
* @experimental
|
|
137
|
+
*/
|
|
138
|
+
putAttachment(group, id, blob, meta) {
|
|
139
|
+
return this._enqueue(async () => this.store.putBlob(group, id, typeof blob === 'function' ? await blob() : blob, meta));
|
|
140
|
+
}
|
|
141
|
+
/** Delete an attachment; no such id is fine @param {string} group @param {string} id @returns {Promise<void>} @experimental */
|
|
142
|
+
removeAttachment(group, id) { return this._enqueue(() => this.store.deleteBlob(group, id)); }
|
|
143
|
+
/**
|
|
144
|
+
* The attachments of a group, once storage is ready. Empty without IndexedDB.
|
|
145
|
+
* @param {string} group
|
|
146
|
+
* @returns {Promise<{ group: string, id: string, at: number, blob: Blob, meta: any }[]>}
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
149
|
+
async attachments(group) { await this.whenReady; return this.store.blobs(group); }
|
|
150
|
+
/**
|
|
151
|
+
* A localStorage key for what belongs to this game but is not a save (settings, a last-used tab): it shares the game's name, so two games on one site stay apart, and stays out of list().
|
|
152
|
+
* @example localStorage.setItem(engine.saves.storageKey('lastTab'), 'map');
|
|
153
|
+
* @param {string} name
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
storageKey(name) { return this._prefix.replace(/save-$/, '') + name; }
|
|
136
157
|
/** Wait for all queued disk writes to finish (for tests and before the page closes) @returns {Promise<void>} */
|
|
137
158
|
flush() { return this._queue; }
|
|
138
159
|
|
|
@@ -177,7 +198,7 @@ export class Saves {
|
|
|
177
198
|
const prev = this._json.get(slot), prevAt = this._meta.get(slot), rev = `${this._tab}:${++this._n}`;
|
|
178
199
|
this._json.set(slot, json); this._meta.set(slot, savedAt);
|
|
179
200
|
// expect is read when the write runs, not now: an earlier queued save of this tab moves _mine first
|
|
180
|
-
return this.
|
|
201
|
+
return this._enqueue(() => this.store.putSlot(slot, savedAt, json, rev, this._mine.get(slot) ?? null)).then(() => {
|
|
181
202
|
this._rev.set(slot, rev); this._mine.set(slot, rev);
|
|
182
203
|
this._tell(slot);
|
|
183
204
|
return true;
|
|
@@ -196,15 +217,15 @@ export class Saves {
|
|
|
196
217
|
this._fail(e, slot); return false;
|
|
197
218
|
});
|
|
198
219
|
}
|
|
199
|
-
/** @internal Memory shows a stored record (null = none); the rev this tab may overwrite
|
|
220
|
+
/** @internal Memory shows a stored record (null = none); a stored record leaves the rev this tab may overwrite as it was */
|
|
200
221
|
_show(slot, r) {
|
|
201
|
-
if (!r) { this._json.delete(slot); this._meta.delete(slot); this._rev.delete(slot); return; }
|
|
222
|
+
if (!r) { this._json.delete(slot); this._meta.delete(slot); this._rev.delete(slot); this._mine.delete(slot); return; } // deleted: no newer progress to protect, so the next save may write
|
|
202
223
|
this._json.set(slot, r.json); this._meta.set(slot, r.savedAt); this._rev.set(slot, r.rev ?? '');
|
|
203
224
|
}
|
|
204
225
|
/** @internal Another tab changed a slot: read it again (after this tab's queued writes, so a late note cannot undo a newer own write) */
|
|
205
226
|
_remote(slot) {
|
|
206
227
|
if (typeof slot !== 'string' || !this._bc) return;
|
|
207
|
-
this.
|
|
228
|
+
this._enqueue(() => this.store.getSlot(slot)).then(r => this._show(slot, r), () => {});
|
|
208
229
|
}
|
|
209
230
|
/** @internal Tell the other tabs a slot changed (they read it again from storage: the note carries no save text, which can be MBs) */
|
|
210
231
|
_tell(slot) { this._bc?.postMessage({ slot }); } // BroadcastChannel, not a worker
|
|
@@ -255,10 +276,10 @@ export class Saves {
|
|
|
255
276
|
this._json.delete(slot); this._meta.delete(slot);
|
|
256
277
|
// the revs are cleared when the delete runs, not now: a save queued before this remove sets _mine when its write lands,
|
|
257
278
|
// and a _mine left over for a deleted record would refuse every later save of this slot as "another tab saved"
|
|
258
|
-
return this.
|
|
279
|
+
return this._enqueue(async () => { await this.store.deleteSlot(slot); this._rev.delete(slot); this._mine.delete(slot); })
|
|
259
280
|
.then(() => this._tell(slot), e => this._fail(e, slot));
|
|
260
281
|
}
|
|
261
|
-
/** Export as a piece of text (can be copied as a backup; synchronous, without binary attachments) @param {string} [slot] @returns {string} */
|
|
282
|
+
/** Export as a piece of text (can be copied as a backup; synchronous, without binary attachments) @param {string} [slot] @returns {string} @experimental */
|
|
262
283
|
export(slot = 'auto') { try { return btoa(unescape(encodeURIComponent(this._json.get(slot) || ''))); } catch { return ''; } }
|
|
263
284
|
/**
|
|
264
285
|
* Import text from export() into a slot (default 'imported'); checked like importFile and written before it resolves.
|
|
@@ -277,6 +298,7 @@ export class Saves {
|
|
|
277
298
|
* @param {{ files?: boolean }} [opts]
|
|
278
299
|
* @returns {Promise<boolean>}
|
|
279
300
|
* @example engine.saves.exportFile('slot1');
|
|
301
|
+
* @experimental
|
|
280
302
|
*/
|
|
281
303
|
exportFile(slot = 'auto', opts = {}) { return exportSaveFile(this, slot, opts); }
|
|
282
304
|
/**
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
// overlapping loads were never sound anyway (the second one's rollback point is the first one's half-applied state). An unrelated listener that
|
|
11
11
|
// throws while a load is still settling fails that load too; gameplay is frozen while parts load, so that is rare, and the error is reported.
|
|
12
12
|
// The rollback point is a copy (structuredClone of every part's save()): save() may return the live object, which load() then writes into.
|
|
13
|
-
import { toast } from '
|
|
14
|
-
import { fmt, warnOnce } from '
|
|
15
|
-
import { reportError } from '
|
|
16
|
-
import { codedError, coded } from '
|
|
13
|
+
import { toast } from '../../ui/UI.js';
|
|
14
|
+
import { fmt, warnOnce } from '../base/validate.js';
|
|
15
|
+
import { reportError } from '../base/errors.js';
|
|
16
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
17
17
|
import { FORMAT, readSave, parseSave, upgradePart } from './saveVersions.js';
|
|
18
|
-
import { PARTS_LOADING } from '
|
|
18
|
+
import { PARTS_LOADING } from '../ops/opsFail.js';
|
|
19
|
+
import { isObject } from '../base/util.js';
|
|
19
20
|
|
|
20
21
|
const DEV_STRINGS = {
|
|
21
22
|
loadThrew: "load() of save part '{k}' threw ({msg}); the game was rolled back to how it was before loading '{slot}'",
|
|
@@ -59,7 +60,7 @@ function applyParts(s, e, r, slot, before, foreign0, scope) {
|
|
|
59
60
|
e.commits.invalidate(); e.ops._mark('(load)'); // old background results die with the old world; the op log shows where the load cut in
|
|
60
61
|
s._foreign = r.foreign;
|
|
61
62
|
const fail = err => {
|
|
62
|
-
// a malformed save (
|
|
63
|
+
// a malformed save (refuseSave, save-bad-record) is the save's fault, not the game's: refused like a corrupt save (warning + toast), so it
|
|
63
64
|
// does not freeze gameplay as a code error would; a load() / listener / afterLoad that throws is a bug and goes through the error tiers
|
|
64
65
|
if (err?.cause?.code === 'save-bad-record') { warnOnce(err.message); toast(e, e.t('saves.corrupt'), { kind: 'error', ms: 5000 }); }
|
|
65
66
|
else reportError(e, err, err?.part ? fmt(DEV_STRINGS.partAt, { k: err.part }) : `saves.apply('${slot}')`);
|
|
@@ -67,12 +68,15 @@ function applyParts(s, e, r, slot, before, foreign0, scope) {
|
|
|
67
68
|
const back = readSave(before, s.providers, '(rollback)');
|
|
68
69
|
// every part reloads its pre-load state; a part that throws again is reported (once) and the rest still roll back
|
|
69
70
|
const onPart = er => reportError(e, er, fmt(DEV_STRINGS.rollback, { k: er.part }), { soft: true });
|
|
70
|
-
|
|
71
|
+
const undone = 'list' in back ? e.ops.allow(() => runParts(e, back.list, '(rollback)', scope, onPart)) : true;
|
|
72
|
+
// a rollback that waits on an async part holds gameplay too, whichever way the load failed (the load's own hold may be gone or never taken)
|
|
73
|
+
const fz = undone !== true ? e.freeze(PARTS_LOADING) : null;
|
|
74
|
+
return Promise.resolve(undone).then(() => false).finally(() => fz?.remove());
|
|
71
75
|
};
|
|
72
76
|
let out;
|
|
73
77
|
try { out = e.ops.allow(() => runParts(e, r.list, slot, scope)); } catch (err) { return fail(err); } // loading writes state outside ops on purpose (guard allows it)
|
|
74
78
|
// a part still loading (its load() returned a Promise): gameplay waits until every part is applied -- no fixed step, no op (opsFail.js
|
|
75
|
-
// PARTS_LOADING).
|
|
79
|
+
// PARTS_LOADING). A fully sync load never takes it.
|
|
76
80
|
const fz = out !== true ? e.freeze(PARTS_LOADING) : null;
|
|
77
81
|
const partsDone = () => { fz?.remove(); };
|
|
78
82
|
// a load is a state change: ops.revision moves. afterLoad belongs to the load (Saves.apply doc): a hook that throws fails it like a part's load()
|
|
@@ -160,7 +164,7 @@ export function loadSlot(s, slot, base) {
|
|
|
160
164
|
if (base && data != null) {
|
|
161
165
|
try {
|
|
162
166
|
const sv = parseSave(data);
|
|
163
|
-
if (sv?.parts
|
|
167
|
+
if (isObject(sv?.parts)) {
|
|
164
168
|
const own = Object.fromEntries(Object.keys(sv.parts).map(k => [k, sv.versions?.[k] ?? 1])); // a part without a version is version 1, not base's
|
|
165
169
|
data = { ...sv, parts: { ...base.parts, ...sv.parts }, versions: { ...base.versions, ...own } };
|
|
166
170
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Save files (.json download / restore), split out of Saves.js: the world save plus every binary attachment, for backups that survive wiped browser data.
|
|
2
2
|
// File shape: { threedog: 'save', format: FILE_FORMAT, game, slot, savedAt, data: <the save envelope>, files: [{ group, id, at, meta, type, url: 'data:...' }] }.
|
|
3
3
|
// Import is offline: attachments must be data: URLs and are decoded in place, never fetched.
|
|
4
|
-
import { toast } from '
|
|
5
|
-
import { coded } from '
|
|
6
|
-
import { fmt, warnOnce } from '
|
|
4
|
+
import { toast } from '../../ui/UI.js';
|
|
5
|
+
import { coded } from '../base/errorHints.js';
|
|
6
|
+
import { fmt, warnOnce } from '../base/validate.js';
|
|
7
7
|
import { readSave, parseSave } from './saveVersions.js';
|
|
8
8
|
|
|
9
9
|
/** Version of the export file wrapper (the save inside carries its own format) */
|
|
@@ -31,12 +31,14 @@ const STRINGS = {
|
|
|
31
31
|
/** Blob -> data: URL (attachments are stored as text in the export file) */
|
|
32
32
|
const toDataURL = blob => new Promise((res, rej) => { const r = new FileReader(); r.onload = () => res(r.result); r.onerror = () => rej(r.error); r.readAsDataURL(blob); });
|
|
33
33
|
|
|
34
|
-
/** data: URL -> Blob without the network; null when it is not a data: URL */
|
|
34
|
+
/** data: URL -> Blob without the network; null when it is not a readable data: URL */
|
|
35
35
|
function dataUrlBlob(url, type) {
|
|
36
36
|
const m = typeof url === 'string' && /^data:([^,]*?)(;base64)?,(.*)$/s.exec(url);
|
|
37
37
|
if (!m) return null;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
try {
|
|
39
|
+
const bytes = m[2] ? Uint8Array.from(atob(m[3]), c => c.charCodeAt(0)) : new TextEncoder().encode(decodeURIComponent(m[3]));
|
|
40
|
+
return new Blob([bytes], { type: typeof type === 'string' ? type : m[1].split(';')[0] });
|
|
41
|
+
} catch { return null; } // a hand-edited file: bad base64 or a bad % escape
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/**
|
|
@@ -54,10 +56,10 @@ export async function exportSaveFile(s, slot, { files = true } = {}) {
|
|
|
54
56
|
const list = [];
|
|
55
57
|
if (files) for (const b of await s.store.blobs()) list.push({ group: b.group, id: b.id, at: b.at, meta: b.meta, type: b.blob.type, url: await toDataURL(b.blob) });
|
|
56
58
|
// splice the world save's JSON text in directly instead of parsing it again (halves memory at tens of MB)
|
|
57
|
-
const head = `{"threedog":"save","format":${FILE_FORMAT},"game":${JSON.stringify(s.
|
|
59
|
+
const head = `{"threedog":"save","format":${FILE_FORMAT},"game":${JSON.stringify(s._prefix)},"slot":${JSON.stringify(slot)},"savedAt":${JSON.stringify(s._meta.get(slot) ?? 0)},"data":`;
|
|
58
60
|
const blob = new Blob([head, json, ',"files":', JSON.stringify(list), '}'], { type: 'application/json' });
|
|
59
61
|
const a = document.createElement('a'), url = URL.createObjectURL(blob);
|
|
60
|
-
a.href = url; a.download = `${s.
|
|
62
|
+
a.href = url; a.download = `${s._prefix.replace(/-save-$/, '')}-${slot}-${new Date().toISOString().slice(0, 10)}.json`;
|
|
61
63
|
document.body.appendChild(a); a.click(); a.remove();
|
|
62
64
|
setTimeout(() => URL.revokeObjectURL(url), 10000); // presentation: release only after the browser has started the download
|
|
63
65
|
return true;
|
|
@@ -75,22 +77,22 @@ export async function importSaveFile(s, file, slot = 'imported') {
|
|
|
75
77
|
file ??= await pick();
|
|
76
78
|
if (!file) return null;
|
|
77
79
|
const refuse = why => { warnOnce(coded('save-import', why)); toast(s.engine, s.engine.t('saves.badFile'), { kind: 'save' }); return null; }; // handled: the player is told, nothing changed
|
|
78
|
-
if (file.size > MAX_BYTES) return refuse(STRINGS.bad
|
|
80
|
+
if (file.size > MAX_BYTES) return refuse(fmt(STRINGS.bad, { why: `${Math.round(file.size / 1e6)} MB` }));
|
|
79
81
|
let obj;
|
|
80
|
-
try { obj = JSON.parse(await file.text()); } catch (e) { return refuse(STRINGS.bad
|
|
81
|
-
if (obj?.threedog !== 'save') return refuse(STRINGS.bad
|
|
82
|
-
if ((obj.format ?? 1) > FILE_FORMAT) return refuse(STRINGS.bad
|
|
82
|
+
try { obj = JSON.parse(await file.text()); } catch (e) { return refuse(fmt(STRINGS.bad, { why: e.message })); }
|
|
83
|
+
if (obj?.threedog !== 'save') return refuse(fmt(STRINGS.bad, { why: 'no "threedog": "save" marker' }));
|
|
84
|
+
if ((obj.format ?? 1) > FILE_FORMAT) return refuse(fmt(STRINGS.bad, { why: `file format ${obj.format}, this build reads up to ${FILE_FORMAT}` }));
|
|
83
85
|
const blobs = [];
|
|
84
86
|
for (const [i, p] of (Array.isArray(obj.files) ? obj.files : []).entries()) {
|
|
85
87
|
const blob = typeof p?.group === 'string' && typeof p.id === 'string' ? dataUrlBlob(p.url, p.type) : null;
|
|
86
|
-
if (!blob) return refuse(STRINGS.attachment
|
|
88
|
+
if (!blob) return refuse(fmt(STRINGS.attachment, { i: String(i) }));
|
|
87
89
|
blobs.push([p, blob]);
|
|
88
90
|
}
|
|
89
91
|
const r = await importData(s, obj.data, slot);
|
|
90
|
-
if (r !== true) return r === 'write' ? null : refuse(STRINGS.bad
|
|
92
|
+
if (r !== true) return r === 'write' ? null : refuse(fmt(STRINGS.bad, { why: r })); // a failed write already showed its toast
|
|
91
93
|
let ok = true;
|
|
92
94
|
for (const [p, blob] of blobs) {
|
|
93
|
-
try { await s.
|
|
95
|
+
try { await s._enqueue(() => s.store.putBlob(p.group, p.id, blob, p.meta, p.at)); } catch (e) { ok = false; s._fail(e); }
|
|
94
96
|
}
|
|
95
97
|
if (!ok) return null;
|
|
96
98
|
s.engine.events.emit('save:imported', slot);
|
|
@@ -7,13 +7,30 @@
|
|
|
7
7
|
// const v = saveValues('clock');
|
|
8
8
|
// this._now = v.num(d?.now, 'now', { min: 0, fallback: 0 });
|
|
9
9
|
// v.done(); // one warning for the part, only when something was fixed
|
|
10
|
-
import { warnOnce } from '
|
|
11
|
-
import { coded } from '
|
|
10
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
11
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
12
12
|
|
|
13
13
|
const STRINGS = {
|
|
14
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
15
|
};
|
|
16
16
|
|
|
17
|
+
/** Positions and speeds beyond this are damage, not a big world: float32 models are already centimetres off at 1e5 and useless far before 1e7 */
|
|
18
|
+
export const SAVE_MAX = 1e7;
|
|
19
|
+
/** A saved number the running game can take. Past SAVE_MAX the ground loops around it never end, or a step later a position goes out of range */
|
|
20
|
+
export const saveNumberOk = v => Number.isFinite(v) && Math.abs(v) <= SAVE_MAX;
|
|
21
|
+
/**
|
|
22
|
+
* 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.
|
|
23
|
+
* @param {string} part 'world', 'scene'...
|
|
24
|
+
* @param {string} path where in the part
|
|
25
|
+
* @param {string} why 'must be ...'
|
|
26
|
+
* @param {any} got
|
|
27
|
+
* @returns {never}
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function refuseSave(part, path, why, got) {
|
|
31
|
+
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`);
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
/**
|
|
18
35
|
* A checker for one part's load: num() clamps / replaces, done() warns once when anything was fixed.
|
|
19
36
|
* @param {string} part
|
|
@@ -39,7 +56,7 @@ export function saveValues(part) {
|
|
|
39
56
|
drop(path, v) { fixed.push(`${path} ${String(JSON.stringify(v)).slice(0, 60)} dropped`); },
|
|
40
57
|
/** One warning for the part when anything was fixed; returns how many */
|
|
41
58
|
done() {
|
|
42
|
-
if (fixed.length) warnOnce(coded('save-value', STRINGS.warn
|
|
59
|
+
if (fixed.length) warnOnce(coded('save-value', fmt(STRINGS.warn, { part, n: fixed.length, list: fixed.slice(0, 6).join('; ') + (fixed.length > 6 ? '; …' : '') })));
|
|
43
60
|
return fixed.length;
|
|
44
61
|
},
|
|
45
62
|
};
|