threedog 0.0.0-stage → 0.2.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Jobs.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/**
|
|
3
|
+
* engine.jobs queues build work in a binary heap (higher priority first, FIFO within a priority).
|
|
4
|
+
* In the real-time loop each frame spends at most budgetMs; engine.step() and headless loading ignore real time and drain the queue each frame (reproducible results).
|
|
5
|
+
*/
|
|
6
|
+
export class Jobs {
|
|
7
|
+
/** Milliseconds allowed per frame, default 3 */
|
|
8
|
+
budgetMs: number;
|
|
9
|
+
/** Milliseconds allowed per frame while the loading screen is up, default 12 */
|
|
10
|
+
loadingMs: number;
|
|
11
|
+
/** Max steps per deterministic run (stops jobs that keep adding jobs from hanging), default 100000 */
|
|
12
|
+
maxSteps: number;
|
|
13
|
+
/** A step slower than this many ms warns in dev (default 8) */
|
|
14
|
+
slowStepMs: number;
|
|
15
|
+
/** Number of jobs not yet finished @returns {number} */
|
|
16
|
+
get pending(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Add a job: a plain function runs in one go, a generator may pause at each yield until the next frame; higher priority runs first; returns the job's result.
|
|
19
|
+
* A job that changes gameplay state passes apply: the result takes effect on a fixed tick via engine.commits (lag fixed steps later, default 30), and is finished on the spot if not done by then, so machine speed does not affect gameplay.
|
|
20
|
+
* Such a job must be a plain function or generator (it cannot return a Promise). With apply, the returned Promise resolves when the work finishes, before apply may have run; put logic that needs "state already changed" inside apply. A step over slowStepMs warns in dev to slice it with yield.
|
|
21
|
+
* @template [T=any]
|
|
22
|
+
* @param {(() => T) | (() => Generator<any, T, any>) | Generator<any, T, any>} work
|
|
23
|
+
* valid (with apply): still wanted when due? Default: dropped when a save load or level change happened since add.
|
|
24
|
+
* @param {{ priority?: number, apply?: ((result: T) => void) | null, lag?: number, valid?: () => boolean }} [opts]
|
|
25
|
+
* @returns {Promise<T>}
|
|
26
|
+
* @example await engine.jobs.add(function* () { for (const p of props) { place(p); yield; } }, { priority: 10 });
|
|
27
|
+
*/
|
|
28
|
+
add<T = any>(work: (() => T) | (() => Generator<any, T, any>) | Generator<any, T, any>, opts?: {
|
|
29
|
+
priority?: number;
|
|
30
|
+
apply?: ((result: T) => void) | null;
|
|
31
|
+
lag?: number;
|
|
32
|
+
valid?: () => boolean;
|
|
33
|
+
}): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Run the queue (the engine calls this each frame): by millisecond budget by default; deterministic: true ignores real time and drains it (used by step)
|
|
36
|
+
* @param {{ deterministic?: boolean }} [opts]
|
|
37
|
+
*/
|
|
38
|
+
run(opts?: {
|
|
39
|
+
deterministic?: boolean;
|
|
40
|
+
}): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Ops.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/**
|
|
3
|
+
* engine.ops: one entry point for the discrete things players and NPCs decide to do. define registers, run executes (sync, logged), can only asks, list says what exists / what is possible now, recent reads the log.
|
|
4
|
+
* Inside an op use ctx.actor (world record id, default engine.actor = 'player'), never engine.player: NPCs and network peers run the same op as themselves.
|
|
5
|
+
*/
|
|
6
|
+
export class Ops {
|
|
7
|
+
/** Counter bumped on each committed op (an op that failed or rolled back does not bump it); every run result carries it, so "did anything change since I looked" is one compare */
|
|
8
|
+
revision: number;
|
|
9
|
+
set historySize(n: number);
|
|
10
|
+
/** History entries kept (ring, default 256); setting it clears the history */
|
|
11
|
+
get historySize(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Register an op. Name it noun.verb. run changes state; can (optional) is read-only and returns true or a reason string; offers (optional) lists the arg sets possible now (for list / describe / the dev bridge `ops` command).
|
|
14
|
+
* args shape types: string number int bool position id any, suffix ? for optional. net: 'peer' lets remote players request it (default: host only);
|
|
15
|
+
* or { type, default, min, max, values, desc } (default is filled in, engine.catalog shows it).
|
|
16
|
+
* atomic: true = world records, inventory containers and vars written by run are rolled back if run fails or throws (events and other state are not; see recipe 23); after(e, args, value, ctx): sound / animation, runs only once the op committed.
|
|
17
|
+
* run (and can) may fail with { ok: false, code, facts, nextActions } (facts: object or list [{ id, field, actual, expected? }]); nextActions are the game's own suggestions.
|
|
18
|
+
* owner (optional, checked by net() for peer requests): args => world record id whose `owner` field must equal the requesting actor.
|
|
19
|
+
* @param {string} name
|
|
20
|
+
* targets (optional): the thing ids, kinds or template names this op is for; engine.thing(id).explain().ops lists it ('*' = any thing).
|
|
21
|
+
* @param {{ run: (e: any, args: any, ctx: OpContext) => any, can?: (e: any, args: any, ctx: OpContext) => true | string | { code: string, facts?: object, nextActions?: { op: string, args?: object }[] }, targets?: string | string[], args?: Record<string, string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean }>, offers?: (e: any, ctx: OpContext) => object[], reasons?: Record<string, string>, desc?: string, undo?: (e: any, args: any, value: any) => void, net?: 'peer' | 'local', owner?: (args: any) => string, atomic?: boolean, after?: (e: any, args: any, value: any, ctx: OpContext) => void }} def
|
|
22
|
+
* @returns {{ remove(): void }}
|
|
23
|
+
* @example
|
|
24
|
+
* const PRICE = { bread: 5 };
|
|
25
|
+
* engine.ops.define('shop.buy', {
|
|
26
|
+
* desc: 'Buy from a shop shelf',
|
|
27
|
+
* args: { shop: 'string', item: 'string', n: 'int?' },
|
|
28
|
+
* can(e, { shop, item, n = 1 }, ctx) {
|
|
29
|
+
* if (!e.inventory.container(shop).has(item, n)) return 'soldOut';
|
|
30
|
+
* if (e.inventory.container(ctx.actor).count('gold') < PRICE[item] * n) return 'noMoney';
|
|
31
|
+
* return true;
|
|
32
|
+
* },
|
|
33
|
+
* run(e, { shop, item, n = 1 }, ctx) {
|
|
34
|
+
* const got = e.inventory.transfer(shop, ctx.actor, item, n);
|
|
35
|
+
* e.inventory.container(ctx.actor).remove('gold', PRICE[item] * got);
|
|
36
|
+
* return got;
|
|
37
|
+
* },
|
|
38
|
+
* reasons: { soldOut: 'Shelf is empty', noMoney: 'Not enough gold' },
|
|
39
|
+
* });
|
|
40
|
+
*/
|
|
41
|
+
define(name: string, def: {
|
|
42
|
+
run: (e: any, args: any, ctx: OpContext) => any;
|
|
43
|
+
can?: (e: any, args: any, ctx: OpContext) => true | string | {
|
|
44
|
+
code: string;
|
|
45
|
+
facts?: object;
|
|
46
|
+
nextActions?: {
|
|
47
|
+
op: string;
|
|
48
|
+
args?: object;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
targets?: string | string[];
|
|
52
|
+
args?: Record<string, string | {
|
|
53
|
+
type: string;
|
|
54
|
+
default?: any;
|
|
55
|
+
min?: number;
|
|
56
|
+
max?: number;
|
|
57
|
+
values?: any[];
|
|
58
|
+
desc?: string;
|
|
59
|
+
optional?: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
offers?: (e: any, ctx: OpContext) => object[];
|
|
62
|
+
reasons?: Record<string, string>;
|
|
63
|
+
desc?: string;
|
|
64
|
+
undo?: (e: any, args: any, value: any) => void;
|
|
65
|
+
net?: "peer" | "local";
|
|
66
|
+
owner?: (args: any) => string;
|
|
67
|
+
atomic?: boolean;
|
|
68
|
+
after?: (e: any, args: any, value: any, ctx: OpContext) => void;
|
|
69
|
+
}): {
|
|
70
|
+
remove(): void;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Run an op now (synchronously): checks args (dev), calls can, then run, and logs it. Returns { ok: true, value, revision } or { ok: false, code, facts, nextActions, revision } (revision = ops.revision, counts committed ops); can may also return { code, facts?, nextActions? }.
|
|
74
|
+
* Pass a fresh args object each call (it is kept in the history; in dev it is frozen). opts.source: 'player' | 'game' | 'bridge' | 'test' | 'replay' | 'net'
|
|
75
|
+
* (default: 'game' inside a fixed step, 'player' between steps); opts.actor: who does it (world record id, default engine.actor, which is 'player' unless the game hands control elsewhere).
|
|
76
|
+
* @param {string} name
|
|
77
|
+
* @param {object} [args]
|
|
78
|
+
* @param {{ source?: string, actor?: string }} [opts]
|
|
79
|
+
* @returns {{ ok: boolean, value?: any, revision: number, code?: string, facts?: object, nextActions?: { op: string, args?: object }[] }}
|
|
80
|
+
* @example
|
|
81
|
+
* const r = engine.ops.run('shop.buy', { shop: 'bakery', item: 'bread' });
|
|
82
|
+
* if (!r.ok) showHint(engine.t('op.shop.buy.' + r.code));
|
|
83
|
+
* // from a fixed step, for an input-driven action: e.ops.run('combat.roll', { dir }, { source: 'player' })
|
|
84
|
+
*/
|
|
85
|
+
run(name: string, args?: object, opts?: {
|
|
86
|
+
source?: string;
|
|
87
|
+
actor?: string;
|
|
88
|
+
}): {
|
|
89
|
+
ok: boolean;
|
|
90
|
+
value?: any;
|
|
91
|
+
revision: number;
|
|
92
|
+
code?: string;
|
|
93
|
+
facts?: object;
|
|
94
|
+
nextActions?: {
|
|
95
|
+
op: string;
|
|
96
|
+
args?: object;
|
|
97
|
+
}[];
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Reverse a finished op with the undo(e, args, value) its definition declared: pass the same args and the value run returned.
|
|
101
|
+
* Returns { ok: true }, or { ok: false, code: 'noUndo', facts: { op }, nextActions } when the op did not declare undo. The undo runs as an op write (the dev guard stays quiet).
|
|
102
|
+
* @example const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value);
|
|
103
|
+
* @param {string} name
|
|
104
|
+
* @param {object} args
|
|
105
|
+
* @param {any} value
|
|
106
|
+
* @param {{ actor?: string }} [opts]
|
|
107
|
+
* @returns {{ ok: boolean, code?: string, facts?: object, nextActions?: { op: string, args?: object }[] }}
|
|
108
|
+
*/
|
|
109
|
+
undo(name: string, args: object, value: any, opts?: {
|
|
110
|
+
actor?: string;
|
|
111
|
+
}): {
|
|
112
|
+
ok: boolean;
|
|
113
|
+
code?: string;
|
|
114
|
+
facts?: object;
|
|
115
|
+
nextActions?: {
|
|
116
|
+
op: string;
|
|
117
|
+
args?: object;
|
|
118
|
+
}[];
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Ask without doing: runs only can (no state change, no history). For greying out buttons and input buffers.
|
|
122
|
+
* @param {string} name
|
|
123
|
+
* @param {object} [args]
|
|
124
|
+
* @param {{ actor?: string, source?: string }} [opts]
|
|
125
|
+
* @returns {{ ok: boolean, code?: string, facts?: object, nextActions?: { op: string, args?: object }[] }}
|
|
126
|
+
* @example const { ok, code } = engine.ops.can('shop.buy', { shop: 'bakery', item: 'bread' });
|
|
127
|
+
* button.disabled = !ok;
|
|
128
|
+
*/
|
|
129
|
+
can(name: string, args?: object, opts?: {
|
|
130
|
+
actor?: string;
|
|
131
|
+
source?: string;
|
|
132
|
+
}): {
|
|
133
|
+
ok: boolean;
|
|
134
|
+
code?: string;
|
|
135
|
+
facts?: object;
|
|
136
|
+
nextActions?: {
|
|
137
|
+
op: string;
|
|
138
|
+
args?: object;
|
|
139
|
+
}[];
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* What exists, or with { available: true } what is possible now: every arg set from each op's offers checked with can
|
|
143
|
+
* (an op with neither offers nor args is checked once with {}; one with args but no offers is skipped, since its args are free-form).
|
|
144
|
+
* @param {{ available?: boolean, actor?: string }} [opts]
|
|
145
|
+
* @returns {{ name: string, desc?: string, args?: any, atomic: boolean, ok?: boolean, code?: string }[]}
|
|
146
|
+
* @example engine.ops.list({ available: true }); // [{ name: 'shop.buy', args: { shop: 'bakery', item: 'bread' }, ok: false, code: 'noMoney' }, ...]
|
|
147
|
+
*/
|
|
148
|
+
list({ available, actor }?: {
|
|
149
|
+
available?: boolean;
|
|
150
|
+
actor?: string;
|
|
151
|
+
}): {
|
|
152
|
+
name: string;
|
|
153
|
+
desc?: string;
|
|
154
|
+
args?: any;
|
|
155
|
+
atomic: boolean;
|
|
156
|
+
ok?: boolean;
|
|
157
|
+
code?: string;
|
|
158
|
+
}[];
|
|
159
|
+
/**
|
|
160
|
+
* Recent history (old -> new), optionally of one op: { seq, tick, phase: 'fixed' | 'between', name, args, source, actor, ok, code, depth, count }.
|
|
161
|
+
* Consecutive identical failures (same actor, op and code) merge into one entry with count.
|
|
162
|
+
* @param {string} [name]
|
|
163
|
+
* @returns {{ seq: number, tick: number, phase: string, name: string, args: any, source: string, actor: string, ok: boolean, code: string | null, depth: number, count: number }[]}
|
|
164
|
+
* @example engine.ops.recent('shop.buy').at(-1); // { tick: 812, phase: 'between', ok: false, code: 'noMoney', ... }
|
|
165
|
+
*/
|
|
166
|
+
recent(name?: string): {
|
|
167
|
+
seq: number;
|
|
168
|
+
tick: number;
|
|
169
|
+
phase: string;
|
|
170
|
+
name: string;
|
|
171
|
+
args: any;
|
|
172
|
+
source: string;
|
|
173
|
+
actor: string;
|
|
174
|
+
ok: boolean;
|
|
175
|
+
code: string | null;
|
|
176
|
+
depth: number;
|
|
177
|
+
count: number;
|
|
178
|
+
}[];
|
|
179
|
+
/**
|
|
180
|
+
* Dev guard for a module that owns saved gameplay state: call it at the top of every method that writes that state. In development it warns once per call site
|
|
181
|
+
* when the write happens outside a fixed step, an op or an allow() window (before ready everything is allowed); in a production build it is a no-op, so just call `engine.ops.guard(...)` (no DEV check needed).
|
|
182
|
+
* @experimental
|
|
183
|
+
* @example set(k, v) { this.engine.ops.guard('myStore.set'); this.data[k] = v; }
|
|
184
|
+
* @param {string} where label shown in the warning, e.g. 'vars.setFlag'
|
|
185
|
+
* @returns {void}
|
|
186
|
+
*/
|
|
187
|
+
guard(where: string): void;
|
|
188
|
+
/**
|
|
189
|
+
* Run fn with guarded writes allowed (loading a save, applying a scenario, net sync); works for an async fn too (allowed until its Promise settles). Returns what fn returns.
|
|
190
|
+
* @experimental
|
|
191
|
+
* @example engine.ops.allow(() => store.load(data));
|
|
192
|
+
* @template T
|
|
193
|
+
* @param {() => T} fn
|
|
194
|
+
* @returns {T}
|
|
195
|
+
*/
|
|
196
|
+
allow<T>(fn: () => T): T;
|
|
197
|
+
}
|
|
198
|
+
export type OpContext = {
|
|
199
|
+
source: string;
|
|
200
|
+
actor: string;
|
|
201
|
+
tick: number;
|
|
202
|
+
frozen: boolean;
|
|
203
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Random.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/** engine.random is the seeded random generator. Gameplay randomness (auto weather, lightning, drops, spawning) uses it so step / tests are reproducible and the state is saved with the save. */
|
|
3
|
+
export class Random {
|
|
4
|
+
/** @param {number} [seed] Seed, default 1 */
|
|
5
|
+
constructor(seed?: number);
|
|
6
|
+
/**
|
|
7
|
+
* Reseed: the sequence afterwards is determined by seed.
|
|
8
|
+
* @param {number} seed
|
|
9
|
+
* @returns {this}
|
|
10
|
+
* @example engine.random.setSeed(42);
|
|
11
|
+
*/
|
|
12
|
+
setSeed(seed: number): this;
|
|
13
|
+
seed: number;
|
|
14
|
+
state: number;
|
|
15
|
+
/** A number from 0 (inclusive) to 1 (exclusive) @returns {number} */
|
|
16
|
+
next(): number;
|
|
17
|
+
/** A decimal between a and b @param {number} a @param {number} b @returns {number} */
|
|
18
|
+
range(a: number, b: number): number;
|
|
19
|
+
/** An integer between a and b (inclusive) @param {number} a @param {number} b @returns {number} @example const dice = engine.random.int(1, 6); */
|
|
20
|
+
int(a: number, b: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* Pick one element of the array at random (undefined for an empty array).
|
|
23
|
+
* @template T
|
|
24
|
+
* @param {readonly T[]} list
|
|
25
|
+
* @returns {T | undefined}
|
|
26
|
+
*/
|
|
27
|
+
pick<T>(list: readonly T[]): T | undefined;
|
|
28
|
+
/** True with probability p (0-1) @param {number} p @returns {boolean} */
|
|
29
|
+
chance(p: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Create an independent deterministic generator: the same seed always gives the same sequence, without touching engine.random's state or the save.
|
|
32
|
+
* For placing world initial data (the same things must be laid out on every start, and loading a save must not overwrite them with the saved engine.random).
|
|
33
|
+
* Gameplay randomness (drops, lightning) still uses engine.random (saved with the save).
|
|
34
|
+
* @param {number} seed
|
|
35
|
+
* @returns {Random}
|
|
36
|
+
* @example const rnd = engine.random.seeded(7); const x = rnd.range(-20, 20);
|
|
37
|
+
*/
|
|
38
|
+
seeded(seed: number): Random;
|
|
39
|
+
/** For saving: { seed, state } @returns {{ seed: number, state: number }} */
|
|
40
|
+
toJSON(): {
|
|
41
|
+
seed: number;
|
|
42
|
+
state: number;
|
|
43
|
+
};
|
|
44
|
+
/** For loading @param {{ seed: number, state: number } | null | undefined} d */
|
|
45
|
+
fromJSON(d: {
|
|
46
|
+
seed: number;
|
|
47
|
+
state: number;
|
|
48
|
+
} | null | undefined): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Rays.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/** engine.rays is the ray registry (engine.raycast hits whatever is registered here). */
|
|
3
|
+
export class Rays {
|
|
4
|
+
/** Registered mesh -> { refs: registration count, occ: camera-blocker registration count } @type {Map<THREE.Object3D, { refs: number, occ: number }>} */
|
|
5
|
+
statics: Map<THREE.Object3D, {
|
|
6
|
+
refs: number;
|
|
7
|
+
occ: number;
|
|
8
|
+
}>;
|
|
9
|
+
/** The three.js Raycaster (firstHitOnly is on) @type {any} */
|
|
10
|
+
ray: any;
|
|
11
|
+
/**
|
|
12
|
+
* Register a static object and every mesh under it (an array also works; meshes over 256 triangles get a BVH); occluder: true also blocks the camera. Returns a handle { remove() }.
|
|
13
|
+
* Only visible objects are hit; hiding that just swaps in something else on screen (such as the far-away hlod original) is marked userData.rayVisible = true and is still hit.
|
|
14
|
+
* Unregisters automatically on geometry dispose or engine.remove.
|
|
15
|
+
* @param {THREE.Object3D | THREE.Object3D[]} obj
|
|
16
|
+
* @param {{ occluder?: boolean }} [opts]
|
|
17
|
+
* @returns {Handle}
|
|
18
|
+
* @example engine.rays.addStatic(house, { occluder: true });
|
|
19
|
+
*/
|
|
20
|
+
addStatic(obj: THREE.Object3D | THREE.Object3D[], opts?: {
|
|
21
|
+
occluder?: boolean;
|
|
22
|
+
}): Handle;
|
|
23
|
+
/** Unregister every mesh under the object (engine.remove calls this automatically) @param {THREE.Object3D} obj */
|
|
24
|
+
forget(obj: THREE.Object3D): void;
|
|
25
|
+
/** A module merges its own hits (rigid adds rigid bodies; asked only when targets is 'all'). Returns a handle { remove() } @param {RayProvider} fn @returns {Handle} */
|
|
26
|
+
addProvider(fn: RayProvider): Handle;
|
|
27
|
+
/**
|
|
28
|
+
* Cast a ray from origin along dir and return the nearest hit or null (same as engine.raycast).
|
|
29
|
+
* @param {Vec3Like} origin
|
|
30
|
+
* @param {Vec3Like} dir
|
|
31
|
+
* @param {RaycastOptions} [opts]
|
|
32
|
+
* @returns {RayHit | null}
|
|
33
|
+
*/
|
|
34
|
+
cast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions): RayHit | null;
|
|
35
|
+
/**
|
|
36
|
+
* Cast from screen coordinates (-1..1) through the camera (same as engine.pick).
|
|
37
|
+
* @param {number} ndcX
|
|
38
|
+
* @param {number} ndcY
|
|
39
|
+
* @param {RaycastOptions} [opts]
|
|
40
|
+
* @returns {RayHit | null}
|
|
41
|
+
*/
|
|
42
|
+
pick(ndcX: number, ndcY: number, opts?: RaycastOptions): RayHit | null;
|
|
43
|
+
}
|
|
44
|
+
import * as THREE from 'three';
|
|
45
|
+
import type { Handle } from '../../common';
|
|
46
|
+
import type { RayProvider } from '../../core';
|
|
47
|
+
import type { Vec3Like } from '../../common';
|
|
48
|
+
import type { RaycastOptions } from '../../core';
|
|
49
|
+
import type { RayHit } from '../../core';
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Saves.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/** engine.saves handles saving. Each module registers "how to save and load"; supports multiple slots, autosave and export / import. */
|
|
3
|
+
export class Saves {
|
|
4
|
+
/** Save name prefix (start of the key names in the localStorage fallback, and of the IndexedDB database name) */
|
|
5
|
+
prefix: string;
|
|
6
|
+
/**
|
|
7
|
+
* Storage layer: saves in the IndexedDB slots store, attachments (by group, e.g. 'photo') in the blobs store; mode 'localStorage' without IndexedDB.
|
|
8
|
+
* @type {{ mode: 'idb' | 'localStorage', blobs(group?: string): Promise<{ group: string, id: string, at: number, blob: Blob, meta: any }[]>,
|
|
9
|
+
* putBlob(group: string, id: string, blob: Blob, meta?: any, at?: number): Promise<void>, deleteBlob(group: string, id: string): Promise<void> }}
|
|
10
|
+
*/
|
|
11
|
+
store: {
|
|
12
|
+
mode: "idb" | "localStorage";
|
|
13
|
+
blobs(group?: string): Promise<{
|
|
14
|
+
group: string;
|
|
15
|
+
id: string;
|
|
16
|
+
at: number;
|
|
17
|
+
blob: Blob;
|
|
18
|
+
meta: any;
|
|
19
|
+
}[]>;
|
|
20
|
+
putBlob(group: string, id: string, blob: Blob, meta?: any, at?: number): Promise<void>;
|
|
21
|
+
deleteBlob(group: string, id: string): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
/** Has the save index been read into memory? (start() waits for it; game code rarely needs to care) */
|
|
24
|
+
ready: boolean;
|
|
25
|
+
/** Resolves once the save index is in memory; await it only to list / load before start() @type {Promise<void>} */
|
|
26
|
+
whenReady: Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Register "how to save and load"; key is this part's name in the save. Parts with first: true load first (the level); a load returning a Promise makes later
|
|
29
|
+
* parts wait.
|
|
30
|
+
* version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current
|
|
31
|
+
* shape.
|
|
32
|
+
* A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept).
|
|
33
|
+
* A part registered after a save was loaded (a module installed later) is handed its data from that save at once.
|
|
34
|
+
* 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).
|
|
35
|
+
* @param {string} key
|
|
36
|
+
* @param {SaveProvider} provider
|
|
37
|
+
* @example
|
|
38
|
+
* engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) });
|
|
39
|
+
* // later the format gains beds: version 2, and a step that upgrades version-1 data
|
|
40
|
+
* engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });
|
|
41
|
+
*/
|
|
42
|
+
register(key: string, provider: SaveProvider): void;
|
|
43
|
+
/**
|
|
44
|
+
* The save versions this build reads, per part: { world: 1, clock: 1, ... }. A save whose part is newer is refused; an older one is migrated.
|
|
45
|
+
* @returns {Record<string, number>}
|
|
46
|
+
*/
|
|
47
|
+
get versions(): Record<string, number>;
|
|
48
|
+
/**
|
|
49
|
+
* Queue a disk write (runs in call order once storage is ready; flush waits for it; used by attachments such as photos).
|
|
50
|
+
* @template T
|
|
51
|
+
* @param {() => Promise<T>} fn
|
|
52
|
+
* @returns {Promise<T>}
|
|
53
|
+
*/
|
|
54
|
+
queue<T>(fn: () => Promise<T>): Promise<T>;
|
|
55
|
+
/** Wait for all queued disk writes to finish (for tests and before the page closes) @returns {Promise<void>} */
|
|
56
|
+
flush(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Collect the data of every part (does not write to the browser): { format, savedAt, versions, parts }.
|
|
59
|
+
* A part whose save() throws is left out and reported (engine.error in dev); save() instead refuses to write such a save.
|
|
60
|
+
* @returns {{ format: number, savedAt: number, versions: Record<string, number>, parts: Record<string, any> }}
|
|
61
|
+
*/
|
|
62
|
+
collect(): {
|
|
63
|
+
format: number;
|
|
64
|
+
savedAt: number;
|
|
65
|
+
versions: Record<string, number>;
|
|
66
|
+
parts: Record<string, any>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Can this slot be loaded? null when it can, else why not (checked without touching the game):
|
|
70
|
+
* 'missing' | 'corrupt' (unreadable) | 'tooNew' (a newer save format or part) | 'migrate' (an upgrade step is missing or throws).
|
|
71
|
+
* @param {string} [slot]
|
|
72
|
+
* @returns {null | 'missing' | 'corrupt' | 'tooNew' | 'migrate'}
|
|
73
|
+
* @example if (engine.saves.check('slot1') === 'tooNew') showUpdateHint();
|
|
74
|
+
*/
|
|
75
|
+
check(slot?: string): null | "missing" | "corrupt" | "tooNew" | "migrate";
|
|
76
|
+
/**
|
|
77
|
+
* Apply a save's data (an object from collect(), or save text) onto the running game. Resolves true when every part loaded.
|
|
78
|
+
* Refused before anything changes (false, toast) when the data is corrupt, from a newer build or cannot be migrated.
|
|
79
|
+
* After every part loaded it runs the modules' afterLoad hooks (gameplay frozen until they resolve), for saves.load, session.newGame / quit and direct calls
|
|
80
|
+
* alike.
|
|
81
|
+
* If a part's load throws, the game is rolled back to how it was before (every part reloads its pre-load state) and it resolves false; the error goes through
|
|
82
|
+
* the error tiers.
|
|
83
|
+
* The state changes synchronously unless a part's load is async; only the result is a Promise.
|
|
84
|
+
* @param {any} data
|
|
85
|
+
* @param {string} [slot] for messages only
|
|
86
|
+
* @returns {Promise<boolean>}
|
|
87
|
+
*/
|
|
88
|
+
apply(data: any, slot?: string): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Save into a slot (default 'auto'). Returns Promise<boolean>
|
|
91
|
+
* (resolves after the write to IndexedDB: true on success, false with a toast and console error on failure).
|
|
92
|
+
* The in-memory save updates immediately, so a following load / list / export sees it at once; the 'save:written' event fires only after the write succeeds.
|
|
93
|
+
* If any part's save() throws, nothing is written and the slot keeps its previous save (false). A failed write keeps the previous save too.
|
|
94
|
+
* Show "saved" only after the result is true.
|
|
95
|
+
* @param {string} [slot]
|
|
96
|
+
* @returns {Promise<boolean>}
|
|
97
|
+
* @example if (await engine.saves.save('slot1')) toast(engine, 'Saved'); // on false the engine already showed why
|
|
98
|
+
*/
|
|
99
|
+
save(slot?: string): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Load a slot onto the running playthrough (a quick load: what the game added during play stays) and resolve true on success; the 'save:loaded' event fires
|
|
102
|
+
* on success.
|
|
103
|
+
* A missing slot resolves false; a corrupt / too new / unmigratable save resolves false with a toast and changes nothing; a part whose load throws rolls the
|
|
104
|
+
* game back.
|
|
105
|
+
* To continue or retry with nothing of the current playthrough left over, use engine.session.load(slot).
|
|
106
|
+
* @param {string} [slot]
|
|
107
|
+
* @returns {Promise<boolean>}
|
|
108
|
+
* @example if (!(await engine.saves.load('quick'))) toast(engine, 'No quick save');
|
|
109
|
+
*/
|
|
110
|
+
load(slot?: string): Promise<boolean>;
|
|
111
|
+
/** All slots, newest first (synchronous, reads the in-memory index) @returns {{ slot: string, savedAt: number }[]} */
|
|
112
|
+
list(): {
|
|
113
|
+
slot: string;
|
|
114
|
+
savedAt: number;
|
|
115
|
+
}[];
|
|
116
|
+
/** Delete a slot. Returns a Promise (disk write done); awaiting is optional @param {string} slot @returns {Promise<void>} */
|
|
117
|
+
remove(slot: string): Promise<void>;
|
|
118
|
+
/** Export as a piece of text (can be copied as a backup; synchronous, without binary attachments) @param {string} [slot] @returns {string} */
|
|
119
|
+
export(slot?: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* Import text from export() into a slot (default 'imported'); checked like importFile and written before it resolves.
|
|
122
|
+
* Resolves true once stored (save:imported fires), false when the text is not a save or the write failed. It does not load the slot.
|
|
123
|
+
* @param {string} text
|
|
124
|
+
* @param {string} [slot]
|
|
125
|
+
* @returns {Promise<boolean>}
|
|
126
|
+
*/
|
|
127
|
+
import(text: string, slot?: string): Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Download a save file (.json): the save plus every binary attachment (as data: text, so the file is larger; { files: false } exports the save only).
|
|
130
|
+
* Restores everything when browser data is wiped on a phone. Returns Promise<boolean>.
|
|
131
|
+
* @param {string} [slot]
|
|
132
|
+
* @param {{ files?: boolean }} [opts]
|
|
133
|
+
* @returns {Promise<boolean>}
|
|
134
|
+
* @example engine.saves.exportFile('slot1');
|
|
135
|
+
*/
|
|
136
|
+
exportFile(slot?: string, opts?: {
|
|
137
|
+
files?: boolean;
|
|
138
|
+
}): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Restore from a save file into slot (default 'imported', so a shared file never overwrites 'auto'). file is a File / Blob; omit it to open a file picker.
|
|
141
|
+
* Everything is checked first (file marker and format, the save inside, attachments must be data: URLs: nothing is fetched).
|
|
142
|
+
* Returns the slot name on success, and null if cancelled, the file is invalid or the write failed (a toast was already shown). It restores the slot only and
|
|
143
|
+
* does not load it.
|
|
144
|
+
* @param {Blob} [file]
|
|
145
|
+
* @param {string} [slot]
|
|
146
|
+
* @returns {Promise<string | null>}
|
|
147
|
+
*/
|
|
148
|
+
importFile(file?: Blob, slot?: string): Promise<string | null>;
|
|
149
|
+
/**
|
|
150
|
+
* Autosave into 'auto' every `minutes` minutes of play: counted in fixed seconds, so it waits while paused, frozen or in a menu that freezes the game,
|
|
151
|
+
* and it never saves while no playthrough runs (the title screen, during newGame / load / quit) or after a gameplay error. Returns a handle; remove() stops
|
|
152
|
+
* it.
|
|
153
|
+
* Calling it again replaces the previous autosave.
|
|
154
|
+
* @param {number} [minutes]
|
|
155
|
+
* @returns {{ remove(): void }}
|
|
156
|
+
* @example engine.saves.autosave(3); // once at boot: it waits by itself while no playthrough runs
|
|
157
|
+
*/
|
|
158
|
+
autosave(minutes?: number): {
|
|
159
|
+
remove(): void;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
import type { SaveProvider } from '../../core';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/Stream.js (edit the JSDoc in the source, then run npm run map)
|
|
2
|
+
/** engine.stream builds on demand by space: only entries near the focus get built. */
|
|
3
|
+
export class Stream {
|
|
4
|
+
/**
|
|
5
|
+
* Build radius in meters around each full-detail stream source (a source radius caps it); null = follow the terrain view distance (the fog distance
|
|
6
|
+
* engine.fogFar without terrain) @type {number | null}
|
|
7
|
+
*/
|
|
8
|
+
radius: number | null;
|
|
9
|
+
/** Grid cell edge in meters, shared with hlod, default 64 */
|
|
10
|
+
cellSize: number;
|
|
11
|
+
/** Unload only beyond radius x this (walking back and forth does not rebuild), default 1.25 */
|
|
12
|
+
unloadFactor: number;
|
|
13
|
+
/** Built-in source at the gameplay anchor (world.anchor, else the player, else engine.focus): full detail and physics @type {StreamSource} */
|
|
14
|
+
player: StreamSource;
|
|
15
|
+
/** Built-in source at the camera focus engine.focus: full detail, no physics @type {StreamSource} */
|
|
16
|
+
camera: StreamSource;
|
|
17
|
+
/** The build radius actually in use, in meters @returns {number} */
|
|
18
|
+
get activeRadius(): number;
|
|
19
|
+
/**
|
|
20
|
+
* Register something to stream in (not built at once); an object returned by build with no parent is added to the scene automatically.
|
|
21
|
+
* @param {StreamEntryOptions} def
|
|
22
|
+
* @returns {StreamHandle}
|
|
23
|
+
* @example engine.stream.add({ position: [40, 0, 12], radius: 6, build: () => makeHouse() });
|
|
24
|
+
*/
|
|
25
|
+
add(def: StreamEntryOptions): StreamHandle;
|
|
26
|
+
/** Set the build radius in meters @param {number} m */
|
|
27
|
+
setRadius(m: number): void;
|
|
28
|
+
/** Everything registered within radius is built (start() waits for it before the loading screen goes away) @returns {boolean} */
|
|
29
|
+
get ready(): boolean;
|
|
30
|
+
/** entries is the registered count, built the built count, queued the queued count @returns {{ entries: number, built: number, queued: number }} */
|
|
31
|
+
get stats(): {
|
|
32
|
+
entries: number;
|
|
33
|
+
built: number;
|
|
34
|
+
queued: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Add a stream source: the world around position is loaded (terrain chunks, colliders, nearby models, stream entries) until remove() or until.
|
|
38
|
+
* position may be live (an Object3D or Vector3 that moves) or a function. detail 'simple' loads only terrain and hlod proxies (a far view);
|
|
39
|
+
* physics defaults to true for 'full'; pass false for a camera that only needs a picture. radius caps every loader's range (default: each loader's own
|
|
40
|
+
* range).
|
|
41
|
+
* until: a Promise (removed when it settles) or a function checked every frame (removed when it returns true).
|
|
42
|
+
* @example const dest = engine.stream.source([800, 0, 300], { radius: 64 }); await dest.whenReady; engine.player.placeAt([800, 0, 300]); dest.remove();
|
|
43
|
+
* @example engine.stream.source(photoCam, { physics: false, until: () => !photoMode.active }); // follows a camera, no colliders
|
|
44
|
+
* @param {any} position
|
|
45
|
+
* @param {StreamSourceOptions} [opts]
|
|
46
|
+
* @returns {StreamSource}
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
source(position: any, opts?: StreamSourceOptions): StreamSource;
|
|
50
|
+
/**
|
|
51
|
+
* Load the destination first, then move: resolves after the player (engine.focus without one) is placed. Until the destination is ready
|
|
52
|
+
* (terrain chunks, collision, nearby models) the player stays where it is. move replaces the default placement (for a vehicle or a custom character).
|
|
53
|
+
* timeout (seconds of frame time, default 60; Infinity waits forever): when the destination is still not ready, the Promise rejects (code stream-timeout,
|
|
54
|
+
* naming the loaders still waiting) and the player is not moved.
|
|
55
|
+
* @example await engine.stream.teleport([800, 0, 300]);
|
|
56
|
+
* @example await engine.stream.teleport(door.target, { radius: 40, move: p => engine.player.placeAt(p) });
|
|
57
|
+
* @param {any} position
|
|
58
|
+
* @param {{ radius?: number, move?: (position: any) => void, timeout?: number }} [opts]
|
|
59
|
+
* @returns {Promise<void>}
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
62
|
+
teleport(position: any, opts?: {
|
|
63
|
+
radius?: number;
|
|
64
|
+
move?: (position: any) => void;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Register a readiness check for loaders: fn(source) returns whether this loader finished what that source asks for.
|
|
69
|
+
* For module authors whose loader reads stream sources; games only read source.ready.
|
|
70
|
+
* @example engine.stream.readyCheck('props', s => s.detail !== 'full' || props.queued === 0)
|
|
71
|
+
* @param {string} name
|
|
72
|
+
* @param {(source: StreamSource) => boolean} fn
|
|
73
|
+
* @returns {{ remove(): void }}
|
|
74
|
+
* @experimental
|
|
75
|
+
*/
|
|
76
|
+
readyCheck(name: string, fn: (source: StreamSource) => boolean): {
|
|
77
|
+
remove(): void;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Sources with fresh positions, filtered: { detail: 'full' } for models and stream entries, { physics: true } for colliders, no filter for terrain
|
|
81
|
+
* @param {{ detail?: 'full' | 'simple', physics?: boolean }} [pick]
|
|
82
|
+
* @returns {StreamSource[]}
|
|
83
|
+
* @experimental
|
|
84
|
+
*/
|
|
85
|
+
sources(pick?: {
|
|
86
|
+
detail?: "full" | "simple";
|
|
87
|
+
physics?: boolean;
|
|
88
|
+
}): StreamSource[];
|
|
89
|
+
}
|
|
90
|
+
import type { StreamSource } from '../../core';
|
|
91
|
+
import type { StreamEntryOptions } from '../../core';
|
|
92
|
+
import type { StreamHandle } from '../../core';
|
|
93
|
+
import type { StreamSourceOptions } from '../../core';
|