@wildshard/sdk 0.0.1 → 0.2.4
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/GUIDE.md +895 -0
- package/README.md +13 -5
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +365 -3
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +47 -0
- package/src/.oxfmtrc.json +50 -0
- package/src/.oxlintrc.json +173 -0
- package/src/cli/account/account.ts +199 -0
- package/src/cli/account/command.ts +193 -0
- package/src/cli/account/key.ts +154 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/audio/audio.ts +39 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +204 -0
- package/src/cli/hero/adopt.ts +103 -0
- package/src/cli/hero/hero.ts +112 -0
- package/src/cli/hero/stamp.ts +298 -0
- package/src/cli/main.ts +291 -0
- package/src/cli/report.ts +20 -0
- package/src/cli/shardfile/command.ts +49 -0
- package/src/cli/shardfile/shardfile.ts +192 -0
- package/src/cli/upload/api.ts +246 -0
- package/src/cli/upload/compress.ts +55 -0
- package/src/cli/upload/hero.ts +62 -0
- package/src/cli/upload/placement.ts +115 -0
- package/src/cli/upload/provenance.ts +192 -0
- package/src/cli/upload/signature.ts +30 -0
- package/src/cli/upload/upload.ts +269 -0
- package/src/cli/upload/validate.ts +74 -0
- package/src/cli/upload/wire.ts +147 -0
- package/src/cli/version.ts +63 -0
- package/src/commons/bake/portableMath.ts +187 -0
- package/src/commons/catalogue.ts +10 -0
- package/src/commons/courseProgram.ts +32 -0
- package/src/commons/practiceCourse.ts +16 -0
- package/src/commons/scripts/abi.as +14 -0
- package/src/commons/scripts/bridge.as +14 -0
- package/src/commons/scripts/course.as +63 -0
- package/src/scripts/ask-new.sh +29 -0
- package/src/scripts/asks.mjs +141 -0
- package/src/scripts/herdr-prompt.sh +34 -0
- package/src/scripts/herdr-question-open.sh +67 -0
- package/src/scripts/md-wrap.mjs +229 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/admission.ts +7 -0
- package/src/sharddev/agentFiles.ts +127 -0
- package/src/sharddev/arenaView.ts +15 -0
- package/src/sharddev/as/groupBankV2.ts +36 -0
- package/src/sharddev/as/groupStepV2.ts +13 -0
- package/src/sharddev/as/ws.ts +30 -0
- package/src/sharddev/as/wsV2.ts +180 -0
- package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
- package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
- package/src/sharddev/assetHandle.ts +84 -0
- package/src/sharddev/assetOwner.ts +70 -0
- package/src/sharddev/assetScope.ts +30 -0
- package/src/sharddev/assets.ts +21 -0
- package/src/sharddev/audio.ts +9 -0
- package/src/sharddev/audioEncode.ts +211 -0
- package/src/sharddev/author.ts +3 -0
- package/src/sharddev/authorError.ts +28 -0
- package/src/sharddev/authorManifest.ts +39 -0
- package/src/sharddev/bake/annulus.ts +19 -0
- package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
- package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
- package/src/sharddev/bake/authoredWorld.ts +201 -0
- package/src/sharddev/bake/basisEncoder.ts +95 -0
- package/src/sharddev/bake/basisGlb.ts +85 -0
- package/src/sharddev/bake/basisTool.ts +74 -0
- package/src/sharddev/bake/basisToolInputs.ts +476 -0
- package/src/sharddev/bake/byteCodec.ts +33 -0
- package/src/sharddev/bake/canvasAtlas.ts +406 -0
- package/src/sharddev/bake/coarseCopy.ts +59 -0
- package/src/sharddev/bake/colliders.ts +87 -0
- package/src/sharddev/bake/compactGlb.ts +224 -0
- package/src/sharddev/bake/compileScript.ts +119 -0
- package/src/sharddev/bake/compileScriptV2.ts +75 -0
- package/src/sharddev/bake/contactRows.ts +84 -0
- package/src/sharddev/bake/creaturePlacement.ts +117 -0
- package/src/sharddev/bake/export.ts +67 -0
- package/src/sharddev/bake/facetedGeometry.ts +379 -0
- package/src/sharddev/bake/farImpostor.ts +120 -0
- package/src/sharddev/bake/forest.ts +100 -0
- package/src/sharddev/bake/format-hook.mjs +2 -0
- package/src/sharddev/bake/generatorGlb.ts +23 -0
- package/src/sharddev/bake/geometryBounds.ts +77 -0
- package/src/sharddev/bake/geometryError.ts +48 -0
- package/src/sharddev/bake/glb.ts +355 -0
- package/src/sharddev/bake/glbCompression.ts +143 -0
- package/src/sharddev/bake/gltfSource.ts +59 -0
- package/src/sharddev/bake/groundMap.ts +142 -0
- package/src/sharddev/bake/image.ts +20 -0
- package/src/sharddev/bake/isleMap.ts +64 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/keyedSky.ts +47 -0
- package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
- package/src/sharddev/bake/kinds.ts +137 -0
- package/src/sharddev/bake/lightSources.ts +31 -0
- package/src/sharddev/bake/mapAssembly.ts +84 -0
- package/src/sharddev/bake/mapRaster.ts +173 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/mapScenes.ts +234 -0
- package/src/sharddev/bake/materialGraph.ts +32 -0
- package/src/sharddev/bake/meadow.ts +27 -0
- package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
- package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
- package/src/sharddev/bake/nativeLattice.ts +178 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/nativeTerrainField.ts +11 -0
- package/src/sharddev/bake/navigation-json.mjs +38 -0
- package/src/sharddev/bake/navigation.ts +113 -0
- package/src/sharddev/bake/navigationAsset.ts +18 -0
- package/src/sharddev/bake/nearPlaceholder.ts +206 -0
- package/src/sharddev/bake/normalizeRig.ts +80 -0
- package/src/sharddev/bake/phoneAstc.ts +93 -0
- package/src/sharddev/bake/placeholders.ts +581 -0
- package/src/sharddev/bake/placement.ts +80 -0
- package/src/sharddev/bake/portableBytes.ts +18 -0
- package/src/sharddev/bake/portableBytesMemo.ts +50 -0
- package/src/sharddev/bake/practiceCourse.ts +49 -0
- package/src/sharddev/bake/primitives.ts +96 -0
- package/src/sharddev/bake/props.ts +443 -0
- package/src/sharddev/bake/questPlacement.ts +98 -0
- package/src/sharddev/bake/rawTexture.ts +26 -0
- package/src/sharddev/bake/riderArms.ts +97 -0
- package/src/sharddev/bake/rig.ts +95 -0
- package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
- package/src/sharddev/bake/signPlacements.ts +25 -0
- package/src/sharddev/bake/simplifier.ts +52 -0
- package/src/sharddev/bake/skinned.ts +312 -0
- package/src/sharddev/bake/slabChunks.ts +149 -0
- package/src/sharddev/bake/slabs.ts +263 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/sourceMetadata.ts +54 -0
- package/src/sharddev/bake/species.ts +368 -0
- package/src/sharddev/bake/specimenCatalogue.ts +47 -0
- package/src/sharddev/bake/splatGround.ts +141 -0
- package/src/sharddev/bake/staticMaterials.ts +171 -0
- package/src/sharddev/bake/terrain.ts +195 -0
- package/src/sharddev/bake/texture.ts +33 -0
- package/src/sharddev/bake/textureWasm.ts +81 -0
- package/src/sharddev/bake/tileEncoder.ts +11 -0
- package/src/sharddev/bake/tileGrid.ts +62 -0
- package/src/sharddev/bake/v2Finite.ts +160 -0
- package/src/sharddev/bake/v2Fuel.ts +71 -0
- package/src/sharddev/bake/wholePartition.ts +74 -0
- package/src/sharddev/bake/wholePieceJoin.ts +147 -0
- package/src/sharddev/bake/world.ts +173 -0
- package/src/sharddev/bake/worldCollision.ts +128 -0
- package/src/sharddev/bake/worldGeometry.ts +237 -0
- package/src/sharddev/bake/worldGlb.ts +123 -0
- package/src/sharddev/bake/worldImage.ts +12 -0
- package/src/sharddev/bake/worldLod.ts +128 -0
- package/src/sharddev/bake/worldRows.ts +102 -0
- package/src/sharddev/bake/worldTextureMemo.ts +63 -0
- package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
- package/src/sharddev/bake.ts +193 -0
- package/src/sharddev/bakePublication.ts +31 -0
- package/src/sharddev/behaviourSource.ts +94 -0
- package/src/sharddev/bin/wildshard.mjs +7 -0
- package/src/sharddev/blobBytes.ts +65 -0
- package/src/sharddev/blobs.ts +138 -0
- package/src/sharddev/bootInventory.ts +129 -0
- package/src/sharddev/bossProfiles.ts +18 -0
- package/src/sharddev/buildBehaviour.ts +77 -0
- package/src/sharddev/buildCacheMetrics.ts +17 -0
- package/src/sharddev/buildDecisionScripts.ts +122 -0
- package/src/sharddev/check.ts +118 -0
- package/src/sharddev/checkProject.ts +127 -0
- package/src/sharddev/cli.ts +200 -0
- package/src/sharddev/clientChannels.ts +169 -0
- package/src/sharddev/clientScripts.ts +10 -0
- package/src/sharddev/commons.ts +77 -0
- package/src/sharddev/commonsCosts.ts +11 -0
- package/src/sharddev/compileMovers.ts +11 -0
- package/src/sharddev/configBoundary.ts +6 -0
- package/src/sharddev/cookInput.ts +40 -0
- package/src/sharddev/crowds.ts +6 -0
- package/src/sharddev/decisionBindingMap.ts +11 -0
- package/src/sharddev/decisionScriptBindings.ts +117 -0
- package/src/sharddev/decisionScripts.ts +28 -0
- package/src/sharddev/decisionSource.ts +51 -0
- package/src/sharddev/dev.ts +113 -0
- package/src/sharddev/director.ts +26 -0
- package/src/sharddev/directorAbi.ts +77 -0
- package/src/sharddev/discoveryDocument.ts +97 -0
- package/src/sharddev/draft.ts +11 -0
- package/src/sharddev/eliteEntryRows.ts +29 -0
- package/src/sharddev/entries.ts +76 -0
- package/src/sharddev/entryReads.ts +73 -0
- package/src/sharddev/executeBundle.ts +55 -0
- package/src/sharddev/finds.ts +5 -0
- package/src/sharddev/formatJsonSchema.ts +3 -0
- package/src/sharddev/generationCache.ts +257 -0
- package/src/sharddev/generationRecipe.ts +94 -0
- package/src/sharddev/handwritten.ts +110 -0
- package/src/sharddev/immutable.ts +14 -0
- package/src/sharddev/interactions.ts +38 -0
- package/src/sharddev/kit/bakedGeometry.ts +16 -0
- package/src/sharddev/kit/geometryPack.ts +110 -0
- package/src/sharddev/ledger.ts +13 -0
- package/src/sharddev/looks/tileField.ts +67 -0
- package/src/sharddev/materialGraphFiles.ts +57 -0
- package/src/sharddev/materials.ts +574 -0
- package/src/sharddev/measure.ts +18 -0
- package/src/sharddev/modes.ts +115 -0
- package/src/sharddev/moverPrograms.ts +213 -0
- package/src/sharddev/movers.ts +75 -0
- package/src/sharddev/nativePopulationRows.ts +46 -0
- package/src/sharddev/newProject.ts +226 -0
- package/src/sharddev/noise.ts +54 -0
- package/src/sharddev/outputProduct.ts +188 -0
- package/src/sharddev/outputRuntime.ts +66 -0
- package/src/sharddev/performancePolicy.ts +29 -0
- package/src/sharddev/phasedBoss.ts +34 -0
- package/src/sharddev/physics.ts +194 -0
- package/src/sharddev/platformSections.ts +42 -0
- package/src/sharddev/plumbing.ts +8 -0
- package/src/sharddev/productOutput.ts +128 -0
- package/src/sharddev/project.ts +337 -0
- package/src/sharddev/projectCompilerIdentity.ts +94 -0
- package/src/sharddev/projectDecisions.ts +66 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/projectGeneration.ts +219 -0
- package/src/sharddev/projectInputFiles.ts +47 -0
- package/src/sharddev/projectManifest.ts +108 -0
- package/src/sharddev/projectMap.ts +35 -0
- package/src/sharddev/projectOutput.ts +242 -0
- package/src/sharddev/projectPolicy.ts +17 -0
- package/src/sharddev/projectSections.ts +27 -0
- package/src/sharddev/questGraph.ts +25 -0
- package/src/sharddev/quests.ts +65 -0
- package/src/sharddev/random.ts +61 -0
- package/src/sharddev/refusals.ts +304 -0
- package/src/sharddev/reportCard.ts +13 -0
- package/src/sharddev/returnProjectionV2.ts +81 -0
- package/src/sharddev/rows.ts +192 -0
- package/src/sharddev/runtimeImports.ts +38 -0
- package/src/sharddev/runtimeMirrors.ts +39 -0
- package/src/sharddev/runtimePerformance.ts +38 -0
- package/src/sharddev/scene.ts +321 -0
- package/src/sharddev/sceneAnimation.ts +54 -0
- package/src/sharddev/sceneAudio.ts +64 -0
- package/src/sharddev/sceneDeclarations.ts +100 -0
- package/src/sharddev/sceneGraph.ts +139 -0
- package/src/sharddev/sceneTransform.ts +12 -0
- package/src/sharddev/schemaValidation.ts +61 -0
- package/src/sharddev/sections.ts +47 -0
- package/src/sharddev/shardSource.ts +59 -0
- package/src/sharddev/sourceReader.ts +26 -0
- package/src/sharddev/spawns.ts +38 -0
- package/src/sharddev/species/clips.ts +24 -0
- package/src/sharddev/species.ts +29 -0
- package/src/sharddev/speciesBrains.ts +19 -0
- package/src/sharddev/synth.ts +66 -0
- package/src/sharddev/test/compileDualScriptV2.ts +71 -0
- package/src/sharddev/test/compileSimV2.ts +21 -0
- package/src/sharddev/test/diskScriptScenario.ts +86 -0
- package/src/sharddev/test/scriptScenario.ts +249 -0
- package/src/sharddev/test/scriptSource.ts +12 -0
- package/src/sharddev/version.ts +4 -0
- package/src/sharddev/weapons/bowProfile.ts +20 -0
- package/src/sharddev/weapons/firearmRows.ts +11 -0
- package/src/sharddev/weapons/meleeProfile.ts +71 -0
- package/src/sharddev/weapons/thrownProfile.ts +10 -0
- package/src/sharddev/worldScenes.ts +308 -0
- package/src/sharddev/worldSource.ts +82 -0
- package/src/shards/_template/README.md +78 -0
- package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
- package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
- package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
- package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
- package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
- package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
- package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
- package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
- package/src/shards/_template/behaviour/boss.as +39 -0
- package/src/shards/_template/behaviour/door.as +32 -0
- package/src/shards/_template/behaviour/hooks.json +129 -0
- package/src/shards/_template/behaviour/idle.as +75 -0
- package/src/shards/_template/behaviour/items.as +22 -0
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/audio.json +45 -0
- package/src/shards/_template/data/bossDecision.json +83 -0
- package/src/shards/_template/data/budgets.json +70 -0
- package/src/shards/_template/data/card.json +281 -0
- package/src/shards/_template/data/clientScripts.json +987 -0
- package/src/shards/_template/data/creatures.json +65 -0
- package/src/shards/_template/data/director.json +39 -0
- package/src/shards/_template/data/encounters.json +96 -0
- package/src/shards/_template/data/items.json +172 -0
- package/src/shards/_template/data/layout.json +66 -0
- package/src/shards/_template/data/ledger.json +32 -0
- package/src/shards/_template/data/look.json +521 -0
- package/src/shards/_template/data/map.json +64 -0
- package/src/shards/_template/data/moves.json +16 -0
- package/src/shards/_template/data/placeholder.json +8 -0
- package/src/shards/_template/data/plumbing.json +32 -0
- package/src/shards/_template/data/quests.json +223 -0
- package/src/shards/_template/data/rows.json +423 -0
- package/src/shards/_template/data/skins.json +66 -0
- package/src/shards/_template/data/spawn.json +6 -0
- package/src/shards/_template/data/targets.json +150 -0
- package/src/shards/_template/data/text.json +12 -0
- package/src/shards/_template/data/ui.json +33 -0
- package/src/shards/_template/data/water.json +13 -0
- package/src/shards/_template/generators/behaviour.ts +34 -0
- package/src/shards/_template/generators/boss.ts +29 -0
- package/src/shards/_template/generators/buildOptions.ts +2 -0
- package/src/shards/_template/generators/cell.ts +224 -0
- package/src/shards/_template/generators/districts.ts +215 -0
- package/src/shards/_template/generators/farLook.ts +15 -0
- package/src/shards/_template/generators/generate.ts +27 -0
- package/src/shards/_template/generators/ground.ts +15 -0
- package/src/shards/_template/generators/kit.ts +69 -0
- package/src/shards/_template/generators/landscape.ts +59 -0
- package/src/shards/_template/generators/landscapeNoise.ts +62 -0
- package/src/shards/_template/generators/mapInputs.ts +10 -0
- package/src/shards/_template/generators/product.ts +100 -0
- package/src/shards/_template/generators/productOutput.ts +18 -0
- package/src/shards/_template/generators/props.ts +9 -0
- package/src/shards/_template/generators/templatePropsSource.ts +58 -0
- package/src/shards/_template/generators/terrain.ts +17 -0
- package/src/shards/_template/generators/world.ts +630 -0
- package/src/shards/_template/hero.json +10 -0
- package/src/shards/_template/look/entry-reads.json +20 -0
- package/src/shards/_template/manifest.json +281 -0
- package/src/shards/_template/shard.config.ts +10 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/tsconfig.json +30 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/src/web/tsconfig.json +13 -0
- package/tsconfig.author.json +23 -0
- package/tsconfig.commons.json +21 -0
- package/tsconfig.json +47 -0
- package/tsconfig.sharddev.json +20 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { assertConfigBoundary } from './configBoundary';
|
|
2
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Author inputs must remain within the project.
|
|
3
|
+
import { realpathSync } from 'node:fs';
|
|
4
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Author inputs must remain within the project.
|
|
5
|
+
import { resolve, sep } from 'node:path';
|
|
6
|
+
import { executeBundle } from './executeBundle';
|
|
7
|
+
import { build } from 'vite';
|
|
8
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Resolve the defining reader into the same author bundle.
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import type { Object3D } from 'three';
|
|
11
|
+
import { readScene, type SceneDescription } from './scene';
|
|
12
|
+
import { confined, publishScene, type SynthResult } from './bake';
|
|
13
|
+
|
|
14
|
+
/** Inspect an ordinary three.js graph and publish canonical scene.json, with an immutable content-hash copy.
|
|
15
|
+
* Graph generation still executes on each synth; expensive producers use the verified native bake cache separately.
|
|
16
|
+
* No client, rendering, physics service, wire-format admission or generated source file is involved. */
|
|
17
|
+
export function synthScene(scene: Object3D, project: string, slug: string): SynthResult {
|
|
18
|
+
if (!/^[a-z][a-z0-9-]{0,127}$/u.test(slug)) throw new Error('Scene synth requires a bounded shard slug');
|
|
19
|
+
return publishScene(readScene(scene), project, slug);
|
|
20
|
+
}
|
|
21
|
+
/** Execute a local author config in Node and synthesize its named scene and identity exports.
|
|
22
|
+
* This transitional declaration composes real three.js objects; the existing default shardfile declaration is optional.
|
|
23
|
+
* Only the scene reader's supported features enter JSON; missing scenes refuse instead of synthesizing a fake world. */
|
|
24
|
+
export async function synthProject(project: string): Promise<SynthResult> {
|
|
25
|
+
const root = realpathSync(project), entry = confined(root, 'shard.config.ts');
|
|
26
|
+
const three = import.meta.resolve('three'), reader = fileURLToPath(import.meta.resolve('@wildshard/sdk/scene'));
|
|
27
|
+
// Reader and SDK declarations must share one module graph, not just the same three.js constructors.
|
|
28
|
+
const virtual = resolve(root, '.wildshard-synth-entry.ts');
|
|
29
|
+
const wrapper = `import * as input from ${JSON.stringify(entry)};
|
|
30
|
+
import { Object3D } from 'three';
|
|
31
|
+
import { readScene } from ${JSON.stringify(reader)};
|
|
32
|
+
if (!(input.scene instanceof Object3D)) throw new Error('Scene config must export a real three.js scene');
|
|
33
|
+
if (typeof input.identity?.slug !== 'string') throw new Error('Scene config must export identity.slug');
|
|
34
|
+
export default { scene: readScene(input.scene), slug: input.identity.slug };`;
|
|
35
|
+
const result = await build({ configFile: false, publicDir: false, logLevel: 'silent',
|
|
36
|
+
plugins: [{ name: 'author-scene-three-identity', enforce: 'pre', resolveId(id, importer) {
|
|
37
|
+
if (id === virtual) return virtual;
|
|
38
|
+
const author = importer?.startsWith(root + sep) === true && !importer.startsWith(resolve(root, 'node_modules') + sep);
|
|
39
|
+
if (author && (/^@wildshard\/(?:game|engine)\//u.test(id) || /^@wildshard\/(?:sdk|sharddev)\/runtime\//u.test(id))) throw new Error('Scene synth cannot import trusted runtime');
|
|
40
|
+
return id === 'three' ? { id: three, external: true } : null;
|
|
41
|
+
}, load(id) {
|
|
42
|
+
if (id === virtual) return wrapper;
|
|
43
|
+
const file = id.split('?')[0] ?? id;
|
|
44
|
+
if (!file.startsWith(root + sep)) return null;
|
|
45
|
+
const relative = file.slice(root.length + 1).split(sep).join('/');
|
|
46
|
+
if (relative.startsWith('node_modules/')) return null;
|
|
47
|
+
if (relative !== 'shard.config.ts' && !/^(?:generators|data|quests|assets|behaviour|blender)\//u.test(relative)) throw new Error('Scene synth source is outside authoring folders');
|
|
48
|
+
if (realpathSync(file) !== file) throw new Error('Scene synth author source must not be a symlink');
|
|
49
|
+
return null;
|
|
50
|
+
} }],
|
|
51
|
+
build: { write: false, minify: false, target: 'esnext', lib: { entry: virtual, formats: ['es'], fileName: 'scene' },
|
|
52
|
+
rolldownOptions: { platform: 'node', external: [/^node:/u, 'assemblyscript/dist/asc.js'] } },
|
|
53
|
+
});
|
|
54
|
+
const built = Array.isArray(result) ? result[0] : result;
|
|
55
|
+
if (built === undefined || !('output' in built) || Array.isArray(result) && result.length !== 1) throw new Error('Scene config produced unexpected output');
|
|
56
|
+
const chunks = built.output.filter(output => output.type === 'chunk'), chunk = chunks[0];
|
|
57
|
+
if (chunks.length !== 1 || chunk === undefined) throw new Error('Scene config must compile as one module');
|
|
58
|
+
assertConfigBoundary([...chunk.imports, ...chunk.dynamicImports]);
|
|
59
|
+
const loaded: unknown = await executeBundle(chunk.code, root);
|
|
60
|
+
if (typeof loaded !== 'object' || loaded === null || !('default' in loaded)) throw new Error('Scene config produced no reader result');
|
|
61
|
+
const data = loaded.default;
|
|
62
|
+
if (typeof data !== 'object' || data === null || !('slug' in data) || typeof data.slug !== 'string'
|
|
63
|
+
|| !('scene' in data) || typeof data.scene !== 'object' || data.scene === null || !('version' in data.scene) || data.scene.version !== 1) throw new Error('Invalid scene reader result');
|
|
64
|
+
// Only the defining readScene inside this trusted author bundle creates this result. Wire admission is separate.
|
|
65
|
+
return publishScene(data.scene as SceneDescription, root, data.slug);
|
|
66
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Test-only setup for the retained real ABI2 protocol contracts.
|
|
2
|
+
/** H13's unshipped dual-admission artifacts. Both wrappers receive the same
|
|
3
|
+
* authored closure; neither artifact replaces the public v0/v1 product. */
|
|
4
|
+
import { admitScriptContract } from '@wildshard/format/scriptContract';
|
|
5
|
+
import { admitScriptV2,parseScriptArtifactV2,SCRIPT_V2_REVISIONS,type ScriptArtifactV2 } from '@wildshard/format/scriptAdmissionV2';
|
|
6
|
+
import type { V2Lane } from '@wildshard/format/scriptFuelV2';
|
|
7
|
+
import { inspectDecisionSource } from '../decisionSource';
|
|
8
|
+
import { hashImmutableBytes } from '../immutable';
|
|
9
|
+
import { compileScript } from '../bake/compileScript';
|
|
10
|
+
import { compileScriptV2 } from '../bake/compileScriptV2';
|
|
11
|
+
|
|
12
|
+
interface Wrapper { readonly source: string; readonly sources?: Readonly<Record<string,string>> }
|
|
13
|
+
function checkSource(path: string,text: string): void {
|
|
14
|
+
if (path === 'main.ts' || !/^(?:[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\.ts$/u.test(path) || typeof text !== 'string') throw new Error('Invalid dual script virtual source');
|
|
15
|
+
}
|
|
16
|
+
function resolve(from: string,specifier: string): string {
|
|
17
|
+
if (!specifier.startsWith('.')) throw new Error('Dual script imports must be captured and relative');
|
|
18
|
+
const parts = from.split('/');parts.pop();
|
|
19
|
+
for (const part of specifier.split('/')) {
|
|
20
|
+
if (part === '.' || part.length === 0) continue;
|
|
21
|
+
if (part === '..') { if (parts.length === 0) throw new Error('Dual script import escapes its closure');parts.pop(); }
|
|
22
|
+
else parts.push(part);
|
|
23
|
+
}
|
|
24
|
+
return `${parts.join('/').replace(/\.(?:as|ts)$/u,'')}.ts`;
|
|
25
|
+
}
|
|
26
|
+
function capture(authors: ReadonlyMap<string,string>,wrapper: Wrapper): Readonly<Record<string,string>> {
|
|
27
|
+
const sources: Record<string,string> = Object.fromEntries(authors);
|
|
28
|
+
for (const [path,text] of Object.entries(wrapper.sources ?? {})) {
|
|
29
|
+
checkSource(path,text);
|
|
30
|
+
if (authors.has(path)) throw new Error('Dual wrapper overrides an authored source');sources[path] = text;
|
|
31
|
+
}
|
|
32
|
+
if (Object.keys(sources).length > 64) throw new Error('Too many dual script virtual sources');
|
|
33
|
+
return sources;
|
|
34
|
+
}
|
|
35
|
+
async function reachable(source: string,sources: Readonly<Record<string,string>>,authors: ReadonlyMap<string,string>): Promise<void> {
|
|
36
|
+
const pending = ['main.ts'], seen = new Set<string>();
|
|
37
|
+
while (pending.length > 0) {
|
|
38
|
+
const path = pending.pop();if (path === undefined || seen.has(path)) continue;seen.add(path);
|
|
39
|
+
const text = path === 'main.ts' ? source : sources[path];if (text === undefined) throw new Error('Missing dual script source');
|
|
40
|
+
const info = await inspectDecisionSource(text,path);
|
|
41
|
+
for (const name of info.imports) pending.push(resolve(path,name));
|
|
42
|
+
}
|
|
43
|
+
for (const path of authors.keys()) if (!seen.has(path)) throw new Error(`Dual wrapper omits authored source: ${path}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Adapter sources may differ; authored bodies cannot. Full source reachability
|
|
47
|
+
* prevents a fake second wrapper from silently omitting a port's helper files.
|
|
48
|
+
* Callers publish only their explicitly selected candidate, never this v1
|
|
49
|
+
* shadow artifact. The existing public producer remains untouched. */
|
|
50
|
+
export async function compileDualScriptV2(input: {
|
|
51
|
+
readonly authored: ReadonlyMap<string,string>; readonly legacy: Wrapper;
|
|
52
|
+
readonly candidate: Wrapper & { readonly lane: V2Lane; readonly ioBytes: number };
|
|
53
|
+
readonly pages: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
readonly legacy: { readonly bytes: Uint8Array; readonly hash: string };
|
|
56
|
+
readonly candidate: { readonly bytes: Uint8Array; readonly artifact: ScriptArtifactV2 };
|
|
57
|
+
readonly authors: readonly { readonly path: string; readonly hash: string }[];
|
|
58
|
+
}> {
|
|
59
|
+
const authored = new Map(input.authored), legacy = input.legacy.source, candidate = input.candidate.source;
|
|
60
|
+
const pages = input.pages, ioBytes = input.candidate.ioBytes, lane = input.candidate.lane;
|
|
61
|
+
if (authored.size === 0 || authored.size > 64 || authored.has('main.ts')) throw new Error('Dual build requires a bounded authored closure outside its wrappers');
|
|
62
|
+
for (const [path,text] of authored) checkSource(path,text);
|
|
63
|
+
const oldSources = capture(authored,input.legacy), newSources = capture(authored,input.candidate);
|
|
64
|
+
await reachable(legacy,oldSources,authored);await reachable(candidate,newSources,authored);
|
|
65
|
+
const oldBytes = await compileScript(legacy,{ abi: 1,maximumPages: pages,sources: oldSources });admitScriptContract(oldBytes,{ abi: 1,pages });
|
|
66
|
+
const newBytes = await compileScriptV2(candidate,{ maximumPages: pages,ioBytes,lane,sources: newSources,compilerRevision: SCRIPT_V2_REVISIONS.compiler });
|
|
67
|
+
admitScriptV2(newBytes,{ ioBytes,lane,compilerRevision: SCRIPT_V2_REVISIONS.compiler,admissionRevision: SCRIPT_V2_REVISIONS.admission });
|
|
68
|
+
return { legacy: { bytes: oldBytes,hash: hashImmutableBytes(oldBytes) },candidate: {
|
|
69
|
+
bytes: newBytes,artifact: parseScriptArtifactV2({ abi: 2,minor: 0,compilerRevision: SCRIPT_V2_REVISIONS.compiler,admissionRevision: SCRIPT_V2_REVISIONS.admission,hash: hashImmutableBytes(newBytes),lane,pages,ioBytes }),
|
|
70
|
+
},authors: [...authored].sort(([a],[b]) => a < b ? -1 : a > b ? 1 : 0).map(([path,text]) => ({ path,hash: hashImmutableBytes(new TextEncoder().encode(text)) })) };
|
|
71
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Test-only setup for the retained real ABI2 protocol contracts.
|
|
2
|
+
/** Generate the module-sized sim loop. A binding program exports onBinding;
|
|
3
|
+
* it uses the same memory SDK and cannot import a JS callback or refill fuel. */
|
|
4
|
+
import { compileScriptV2 } from '../bake/compileScriptV2';
|
|
5
|
+
import { v2CoreSource } from '../as/wsV2';
|
|
6
|
+
|
|
7
|
+
export function compileSimV2(program: string,options: {
|
|
8
|
+
readonly io: number; readonly ioBytes: number; readonly maximumPages?: number;
|
|
9
|
+
readonly sources?: Readonly<Record<string,string>>;
|
|
10
|
+
}): Promise<Uint8Array> {
|
|
11
|
+
if (Object.hasOwn(options.sources ?? {},'program.ts') || Object.hasOwn(options.sources ?? {},'sdk/as/wsV2.ts')) throw new Error('Reserved v2 sim source');
|
|
12
|
+
const source = `import * as ws from './sdk/as/wsV2';import { onBinding } from './program';
|
|
13
|
+
export function ws_abi():i32{return 2;} export function ws_io():i32{return ws.io();}
|
|
14
|
+
export function ws_init(lo:i32,hi:i32,fuel:i32):i32{return 0;}
|
|
15
|
+
export function ws_step(tick:i32,fuel:i32):i32{
|
|
16
|
+
ws.beginState();for(let i=0;i<ws.count(1);i++){if(!ws.beginBinding(i))continue;onBinding();ws.endBinding();}return 0;
|
|
17
|
+
}`;
|
|
18
|
+
return compileScriptV2(source,{ lane: 'sim',ioBytes: options.ioBytes,...(options.maximumPages === undefined ? {} : { maximumPages: options.maximumPages }),
|
|
19
|
+
sources: { ...options.sources,'program.ts': program,'sdk/as/wsV2.ts': v2CoreSource(options.io) },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The author-only scenario consumes published disk output.
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- A validated output folder stays inside the explicit product root.
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { DecisionHost, type DecisionScript } from '@wildshard/engine/script/decision';
|
|
6
|
+
import { nativeRuntimeActorIds } from '@wildshard/format/nativeRuntimePlan';
|
|
7
|
+
import { buildDecisionRegistries, decisionBindingMap, decisionSpawnGroups } from '@wildshard/format/decisionBindings';
|
|
8
|
+
import { parseActorMoves } from '@wildshard/format/actorMoves';
|
|
9
|
+
import { readCreatureStrikes } from '@wildshard/format/creatures';
|
|
10
|
+
import { parseWorldTargets } from '@wildshard/format/worldTargets';
|
|
11
|
+
import { admitScriptContract, decisionScriptsFromSections } from '@wildshard/format/scriptContract';
|
|
12
|
+
import { SCRIPT_V1_READS, SCRIPT_V1_LISTS, type ScriptV1ReadName, type ScriptV1ListName } from '@wildshard/format/scriptAbiV1';
|
|
13
|
+
import { outputDescriptor } from '@wildshard/engine/game/shardfile/outputDescriptor';
|
|
14
|
+
import { loadHeadlessProduct } from '@wildshard/engine/host/headlessProduct';
|
|
15
|
+
import { createScriptScenario, type ScenarioActor, type DiskScenarioOptions, type DiskScriptScenario } from './scriptScenario';
|
|
16
|
+
|
|
17
|
+
/** Disk admission and the game use the same defining catalogue; the fixture never allocates actor ids. */
|
|
18
|
+
export async function readDiskScriptScenario(slug: string, id: string, options: DiskScenarioOptions): Promise<DiskScriptScenario> {
|
|
19
|
+
if (!/^_?[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(slug)) throw new Error('Invalid scenario output folder');
|
|
20
|
+
if (options.products !== undefined && options.productDirectory !== undefined) throw new Error('Scenario requires one product location');
|
|
21
|
+
const root = resolve(options.products ?? 'out'), directory = options.productDirectory === undefined ? resolve(root, slug) : resolve(options.productDirectory);
|
|
22
|
+
if (!existsSync(resolve(directory, 'shard.json'))) throw new Error(`Missing published scenario output ${slug}; run wildshard build first`);
|
|
23
|
+
const expected = options.productDirectory === undefined ? resolve(realpathSync(root), slug) : directory;
|
|
24
|
+
if (realpathSync(directory) !== expected) throw new Error('Scenario output cannot be a symlink');
|
|
25
|
+
const product = await loadHeadlessProduct(directory), shard = product.shardfile, descriptor = outputDescriptor(shard);
|
|
26
|
+
if (descriptor === undefined) throw new Error('Missing admitted scenario descriptor');
|
|
27
|
+
const { index, sections } = descriptor;
|
|
28
|
+
const rows = decisionScriptsFromSections(sections);
|
|
29
|
+
const row = rows.find(value => value.id === id), ordinal = rows.findIndex(value => value.id === id);
|
|
30
|
+
if (row === undefined) throw new Error(`Missing simulation scenario script ${id}`);
|
|
31
|
+
const moves = parseActorMoves(sections.get('actors/moves') ?? []), targets = sections.get('world/targets');
|
|
32
|
+
const nativePlan = sections.get('sim/runtime-plan');
|
|
33
|
+
const nativeActors = shard.runtime === null && nativePlan !== undefined ? nativeRuntimeActorIds(nativePlan) : [];
|
|
34
|
+
const registries = buildDecisionRegistries(shard, moves, targets === undefined ? undefined : parseWorldTargets(targets), readCreatureStrikes(sections.get('actors/strikes') ?? []), rows, nativeActors);
|
|
35
|
+
const map = decisionBindingMap(row, registries), handles = Object.values(map.ids.actors ?? {});
|
|
36
|
+
const script: DecisionScript = { ...row, ids: map.ids, state: [...row.state], reads: row.reads.filter((name): name is ScriptV1ReadName => Object.hasOwn(SCRIPT_V1_READS, name)),
|
|
37
|
+
lists: row.reads.filter((name): name is ScriptV1ListName => Object.hasOwn(SCRIPT_V1_LISTS, name)) };
|
|
38
|
+
const file = index.files.find(value => value.kind === 'wasm' && value.path === row.module);
|
|
39
|
+
if (file?.name === undefined) throw new Error('Scenario module requires an admitted logical blob name');
|
|
40
|
+
const bytes = await product.file(file.name);
|
|
41
|
+
admitScriptContract(bytes, { abi: 1, pages: row.pages });
|
|
42
|
+
const binding = row.binding;
|
|
43
|
+
const encounter = 'encounter' in binding ? shard.encounters.find(value => value.id === binding.encounter) : undefined;
|
|
44
|
+
if ('encounter' in binding && encounter === undefined) throw new Error('Missing scenario encounter binding');
|
|
45
|
+
if ('quest' in binding && !shard.quests.quests.some(quest => quest.id === binding.quest)) throw new Error('Missing scenario quest binding');
|
|
46
|
+
if ('zone' in binding && registries.zones?.has(binding.zone) !== true) throw new Error('Missing scenario zone binding');
|
|
47
|
+
const self = encounter === undefined ? ('spawnGroup' in binding ? handles[0] : 0) : registries.actors?.get(encounter.entity);
|
|
48
|
+
if (self === undefined || self > 0 && !handles.includes(self)) throw new Error('Scenario encounter actor is not owned');
|
|
49
|
+
const fields = shard.state.shared.filter(field => field.privacy === 'public' && field.type !== 'string');
|
|
50
|
+
const fieldValues = Object.fromEntries(fields.map(field => [field.id, Number(field.default)]));
|
|
51
|
+
const bounds = Object.fromEntries(fields.map(field => {
|
|
52
|
+
const low = field.type === 'bool' ? 0 : field.type === 'i32' ? -2147483648 : -Number.MAX_VALUE;
|
|
53
|
+
const high = field.type === 'bool' ? 1 : field.type === 'i32' ? 2147483647 : Number.MAX_VALUE;
|
|
54
|
+
return [field.id, { min: Math.max(field.min ?? low, low), max: Math.min(field.max ?? high, high), integer: field.type !== 'f64' }];
|
|
55
|
+
}));
|
|
56
|
+
const overrides = new Map<number, NonNullable<DiskScenarioOptions['actors']>[number]>();
|
|
57
|
+
for (const actor of options.actors ?? []) {
|
|
58
|
+
const alias = typeof actor.id === 'string' && Object.hasOwn(map.ids.actors ?? {}, actor.id) ? map.ids.actors?.[actor.id] : undefined;
|
|
59
|
+
const handle = typeof actor.id === 'number' ? actor.id : alias ?? registries.actors?.get(actor.id);
|
|
60
|
+
if (handle === undefined || ![...registries.actors?.values() ?? []].includes(handle) || overrides.has(handle)) throw new Error('Unknown or duplicate scenario actor override');
|
|
61
|
+
if (Object.keys(actor.fields ?? {}).some(key => !Object.hasOwn(fieldValues, key))) throw new Error('Unknown scenario public field');
|
|
62
|
+
overrides.set(handle, actor);
|
|
63
|
+
}
|
|
64
|
+
const actors: ScenarioActor[] = [];
|
|
65
|
+
for (const handle of new Set([...handles, ...overrides.keys()])) {
|
|
66
|
+
const name = [...registries.actors ?? []].find(([, value]) => value === handle)?.[0], authored = shard.creatures.spawns.find(actor => actor.id === name);
|
|
67
|
+
const override = overrides.get(handle), runtime = shard.runtime?.spawns;
|
|
68
|
+
const retained = [...runtime?.homes ?? [], ...runtime?.bosses ?? [], ...runtime?.actors ?? []].find(actor => actor.id === name);
|
|
69
|
+
if (override === undefined && authored === undefined) throw new Error(`Runtime actor ${name ?? handle} requires explicit scenario XYZ`);
|
|
70
|
+
const at = override?.at ?? authored?.at; if (at === undefined) throw new Error('Missing scenario actor position');
|
|
71
|
+
actors.push({ ...override, id: handle, at, yaw: override?.yaw ?? authored?.yaw ?? retained?.yaw ?? 0,
|
|
72
|
+
fields: { ...fieldValues, ...override?.fields }, fieldBounds: bounds });
|
|
73
|
+
}
|
|
74
|
+
const groups = decisionSpawnGroups(shard, rows);
|
|
75
|
+
const spawnGroups = [...registries.spawns ?? []].map(([name, groupId]) => {
|
|
76
|
+
const members = groups.get(name) ?? [name];
|
|
77
|
+
return { id: groupId, members: members.map(member => { const actor = registries.actors?.get(member); if (actor === undefined) throw new Error('Missing scenario group member'); return actor; }) };
|
|
78
|
+
});
|
|
79
|
+
const bindings = 'spawnGroup' in binding ? handles.map((actor, ordinalIndex) => ({ id: ordinalIndex + 1, script: row.id, self: actor, actors: [actor], instance: 0 }))
|
|
80
|
+
: [{ id: ordinal + 1, script: row.id, self, actors: handles, instance: 0 }];
|
|
81
|
+
const primary = bindings[0]; if (primary === undefined) throw new Error('Empty scenario binding');
|
|
82
|
+
const made = createScriptScenario(DecisionHost, { ...options, actors, spawnGroups, seed: options.seed, script, bytes, binding: primary, bindings });
|
|
83
|
+
const entry = index.sections.find(value => value.name === 'sim/scripts'); if (entry === undefined) throw new Error('Missing scenario section');
|
|
84
|
+
return Object.assign(made, { product: Object.freeze({ slug, script: row.id, sectionHash: entry.hash,
|
|
85
|
+
indexHash: descriptor.indexHash }) });
|
|
86
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { SCRIPT_V1_COMMANDS as commands, SCRIPT_V1_EVENTS as events, SCRIPT_V1_LAYOUT as layout, SCRIPT_V1_LISTS as lists, SCRIPT_V1_READS as reads, type ScriptV1Command, type ScriptV1Event, type ScriptV1EventName } from '@wildshard/format/scriptAbiV1';
|
|
2
|
+
import type { DecisionBinding, DecisionCommit, DecisionContext, DecisionHost, DecisionHostOptions, DecisionIdKind, DecisionScript, DecisionSnapshot, DecisionTrace, DecisionWorld } from '@wildshard/engine/script/decision';
|
|
3
|
+
|
|
4
|
+
/** Small declared world, not a second mechanics implementation. Tests explicitly supply completion events. */
|
|
5
|
+
export interface ScenarioActor {
|
|
6
|
+
id: number; at: readonly [number, number, number]; yaw?: number; hpShare?: number; alive?: boolean;
|
|
7
|
+
fields?: Readonly<Record<number, number>>; fieldBounds?: Readonly<Record<number, { min: number; max: number; integer?: boolean }>>; moving?: boolean; strikeState?: number; spawn?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ScenarioWorldInput {
|
|
10
|
+
actors?: readonly ScenarioActor[]; players?: readonly ScenarioActor[];
|
|
11
|
+
spawnGroups?: readonly { id: number; members: readonly number[] }[];
|
|
12
|
+
flags?: Readonly<Record<number, boolean>>; playerFlags?: Readonly<Record<number, Readonly<Record<number, boolean>>>>;
|
|
13
|
+
zones?: readonly { id: number; min: readonly [number, number, number]; max: readonly [number, number, number] }[];
|
|
14
|
+
/** Explicit answers for physics/navigation queries; missing fixtures refuse instead of inventing terrain. */
|
|
15
|
+
lists?: readonly { op: number; a: number; b: number; result: readonly number[] }[];
|
|
16
|
+
}
|
|
17
|
+
/** Only the actual DecisionHost constructor implements this port; the harness never interprets Wasm. */
|
|
18
|
+
export type ScenarioHostConstructor = new(options: DecisionHostOptions) => DecisionHost;
|
|
19
|
+
export interface ScriptScenarioInput extends ScenarioWorldInput {
|
|
20
|
+
script: DecisionScript; binding: DecisionBinding; bytes: Uint8Array; seed: number;
|
|
21
|
+
bindings?: readonly DecisionBinding[];
|
|
22
|
+
}
|
|
23
|
+
export interface ScenarioSnapshot { host: DecisionSnapshot; world: ScenarioWorldInput }
|
|
24
|
+
export type ScenarioCommand = readonly (string | number)[];
|
|
25
|
+
/** Disk fixtures name actor aliases or real platform ids; numeric handles must already be registered. */
|
|
26
|
+
export interface DiskScenarioOptions extends Omit<ScenarioWorldInput, 'actors'> {
|
|
27
|
+
seed: number;
|
|
28
|
+
/** Published output root, defaulting to out/ in the caller's working directory. */
|
|
29
|
+
products?: string;
|
|
30
|
+
/** Explicit read-only product directory, including a verified immutable cache entry.
|
|
31
|
+
* Mutually exclusive with products; normal product admission still checks every byte. */
|
|
32
|
+
productDirectory?: string;
|
|
33
|
+
actors?: readonly (Omit<ScenarioActor, 'id' | 'fieldBounds'> & { id: string | number })[];
|
|
34
|
+
}
|
|
35
|
+
export type DiskScriptScenario = ScriptScenario & { readonly product: {
|
|
36
|
+
readonly slug: string; readonly script: string; readonly sectionHash: string; readonly indexHash: string;
|
|
37
|
+
} };
|
|
38
|
+
/** Load a published format-2 product and run its declared Wasm on the real DecisionHost.
|
|
39
|
+
* Missing output refuses: the harness never builds, compiles, or imports author/runtime modules. */
|
|
40
|
+
export async function scenario(slug: string, id: string, options: DiskScenarioOptions): Promise<DiskScriptScenario> {
|
|
41
|
+
const { readDiskScriptScenario } = await import('./diskScriptScenario');
|
|
42
|
+
return readDiskScriptScenario(slug, id, options);
|
|
43
|
+
}
|
|
44
|
+
function finite(values: readonly number[]): void { if (!values.every(Number.isFinite)) throw new Error('Non-finite scenario value'); }
|
|
45
|
+
function actorCopy(actor: ScenarioActor): ScenarioActor {
|
|
46
|
+
for (const [key, bound] of Object.entries(actor.fieldBounds ?? {})) {
|
|
47
|
+
finite([bound.min, bound.max]); const value = actor.fields?.[Number(key)];
|
|
48
|
+
if (bound.min > bound.max || value === undefined || value < bound.min || value > bound.max || (bound.integer === true && !Number.isInteger(value))) throw new Error('Invalid scenario field bounds');
|
|
49
|
+
}
|
|
50
|
+
return { ...actor, at: [...actor.at], fields: { ...actor.fields }, fieldBounds: structuredClone(actor.fieldBounds ?? {}) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Deterministic read-only query adapter. Commands are recorded by the host; it owns validation and timers/RNG. */
|
|
54
|
+
export class ScenarioWorld implements DecisionWorld {
|
|
55
|
+
private actors = new Map<number, ScenarioActor>();
|
|
56
|
+
private players = new Set<number>();
|
|
57
|
+
private input: ScenarioWorldInput;
|
|
58
|
+
constructor(input: ScenarioWorldInput = {}) { this.input = {}; this.restore(input); }
|
|
59
|
+
private actor(id: number): ScenarioActor {
|
|
60
|
+
const actor = this.actors.get(id); if (actor === undefined) throw new Error(`Unknown scenario actor ${id}`); return actor;
|
|
61
|
+
}
|
|
62
|
+
private inside(actor: ScenarioActor, zoneId: number): boolean {
|
|
63
|
+
const zone = this.input.zones?.find(value => value.id === zoneId);
|
|
64
|
+
if (zone === undefined) throw new Error(`Unknown scenario zone ${zoneId}`);
|
|
65
|
+
return actor.at.every((value, index) => value >= (zone.min[index] ?? 0) && value <= (zone.max[index] ?? 0));
|
|
66
|
+
}
|
|
67
|
+
private nearby(actor: number, radius: number): ScenarioActor[] {
|
|
68
|
+
const origin = this.actor(actor).at;
|
|
69
|
+
return [...this.players].map(id => this.actor(id)).filter(value => value.alive !== false)
|
|
70
|
+
.map(value => ({ actor: value, distance: Math.hypot(value.at[0] - origin[0], value.at[2] - origin[2]) }))
|
|
71
|
+
.filter(value => value.distance <= radius).sort((a, b) => a.distance - b.distance || a.actor.id - b.actor.id).map(value => value.actor);
|
|
72
|
+
}
|
|
73
|
+
read(op: number, a: number, b: number, _context: DecisionContext): number {
|
|
74
|
+
finite([a, b]);
|
|
75
|
+
if (op === reads.flag) return this.input.flags?.[a] === true ? 1 : 0;
|
|
76
|
+
if (op === reads.playerFlag) { if (!this.players.has(a)) throw new Error('Unknown scenario player'); return this.input.playerFlags?.[a]?.[b] === true ? 1 : 0; }
|
|
77
|
+
if (op === reads.nearestPlayer) return this.nearby(a, Number.POSITIVE_INFINITY)[0]?.id ?? 0;
|
|
78
|
+
if (op === reads.playersInZone) return [...this.players].filter(id => this.actor(id).alive !== false && this.inside(this.actor(id), a)).length;
|
|
79
|
+
if (op === reads.spawnGroupAlive) {
|
|
80
|
+
const group = this.input.spawnGroups?.find(value => value.id === a);
|
|
81
|
+
return group === undefined ? [...this.actors.values()].filter(actor => actor.spawn === a && actor.alive !== false).length
|
|
82
|
+
: group.members.filter(id => { const actor = this.actors.get(id); return actor !== undefined && actor.alive !== false; }).length;
|
|
83
|
+
}
|
|
84
|
+
if (op === reads.distance || op === reads.bearing) {
|
|
85
|
+
const from = this.actor(a).at, to = this.actor(b).at;
|
|
86
|
+
return op === reads.distance ? Math.hypot(to[0] - from[0], to[2] - from[2]) : Math.atan2(to[0] - from[0], to[2] - from[2]);
|
|
87
|
+
}
|
|
88
|
+
if (op === reads.actorInZone) return this.inside(this.actor(a), b) ? 1 : 0;
|
|
89
|
+
if (op === reads.field) {
|
|
90
|
+
const value = this.actor(a).fields?.[b]; if (value === undefined) throw new Error('Missing scenario field'); return value;
|
|
91
|
+
}
|
|
92
|
+
if (op === reads.x) return this.actor(a).at[0];
|
|
93
|
+
if (op === reads.y) return this.actor(a).at[1];
|
|
94
|
+
if (op === reads.z) return this.actor(a).at[2];
|
|
95
|
+
if (op === reads.yaw) return this.actor(a).yaw ?? 0;
|
|
96
|
+
if (op === reads.hpShare) return this.actor(a).hpShare ?? 1;
|
|
97
|
+
if (op === reads.alive) return this.actor(a).alive === false ? 0 : 1;
|
|
98
|
+
if (op === reads.moving) return this.actor(a).moving === true ? 1 : 0;
|
|
99
|
+
if (op === reads.strikeState) return this.actor(a).strikeState ?? 0;
|
|
100
|
+
throw new Error(`Unanswered scenario read ${op}; timers and random belong to DecisionHost`);
|
|
101
|
+
}
|
|
102
|
+
list(op: number, a: number, b: number, output: Float64Array, _context: DecisionContext): number {
|
|
103
|
+
finite([a, b]);
|
|
104
|
+
let values: readonly number[];
|
|
105
|
+
if (op === lists.playersWithin) {
|
|
106
|
+
if (b < 0) throw new Error('Negative scenario radius'); values = this.nearby(a, b).map(actor => actor.id);
|
|
107
|
+
} else if (op === lists.actorsInZone) values = [...this.actors.values()].filter(actor => this.inside(actor, a)).map(actor => actor.id).sort((x, y) => x - y);
|
|
108
|
+
else {
|
|
109
|
+
const answer = this.input.lists?.find(value => value.op === op && value.a === a && value.b === b);
|
|
110
|
+
if (answer === undefined) throw new Error(`Missing scenario list ${op}`); values = answer.result;
|
|
111
|
+
}
|
|
112
|
+
const count = Math.min(values.length, output.length); output.set(values.slice(0, count)); return count;
|
|
113
|
+
}
|
|
114
|
+
prepare(batch: readonly ScriptV1Command[], _context: DecisionContext): DecisionCommit {
|
|
115
|
+
// The host validates capabilities/known handles/quotas; the world knows actual actor kinds and ownership.
|
|
116
|
+
const player = (id: number): boolean => this.players.has(id) && _context.observed.has(id);
|
|
117
|
+
const owned = (id: number): ScenarioActor => {
|
|
118
|
+
if (!_context.binding.actors.includes(id) || this.players.has(id)) throw new Error('Scenario actor ownership refused');
|
|
119
|
+
return this.actor(id);
|
|
120
|
+
};
|
|
121
|
+
for (const [op, target, a, b] of batch) {
|
|
122
|
+
if ([commands.field, commands.move, commands.stop, commands.strike, commands.despawn].some(value => value === op)) {
|
|
123
|
+
const actor = owned(target);
|
|
124
|
+
if (op === commands.field) {
|
|
125
|
+
const bound = actor.fieldBounds?.[a];
|
|
126
|
+
if (actor.fields?.[a] === undefined || !Number.isFinite(b) || (bound !== undefined && (b < bound.min || b > bound.max || (bound.integer === true && !Number.isInteger(b))))) throw new Error('Scenario field declaration or bounds refused');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if ([commands.grant, commands.reward, commands.flag].some(value => value === op) && target !== 0 && !player(target)) throw new Error('Scenario target is not an observed player');
|
|
130
|
+
if ((op === commands.impulse || (op === commands.cue && target !== 0)) && !player(target)) owned(target);
|
|
131
|
+
if (op === commands.flag && b !== 0 && b !== 1) throw new Error('Scenario flag value refused');
|
|
132
|
+
}
|
|
133
|
+
const copy = batch.map((command): ScriptV1Command => [command[0], command[1], command[2], command[3], command[4]]);
|
|
134
|
+
return { commit: () => {
|
|
135
|
+
for (const [op, target, a, b] of copy) {
|
|
136
|
+
if (op === commands.flag) this.input = target === 0
|
|
137
|
+
? { ...this.input, flags: { ...this.input.flags, [a]: b === 1 } }
|
|
138
|
+
: { ...this.input, playerFlags: { ...this.input.playerFlags, [target]: { ...this.input.playerFlags?.[target], [a]: b === 1 } } };
|
|
139
|
+
const actor = this.actors.get(target); if (actor === undefined) continue;
|
|
140
|
+
if (op === commands.field) this.actors.set(target, { ...actor, fields: { ...actor.fields, [a]: b } });
|
|
141
|
+
if (op === commands.move || op === commands.stop) this.actors.set(target, { ...actor, moving: op === commands.move });
|
|
142
|
+
if (op === commands.strike) this.actors.set(target, { ...actor, strikeState: 1 });
|
|
143
|
+
if (op === commands.despawn) this.actors.set(target, { ...actor, alive: false });
|
|
144
|
+
}
|
|
145
|
+
} };
|
|
146
|
+
}
|
|
147
|
+
failed(_mode: DecisionScript['onFail'], _context: DecisionContext, _reason: string): void { /* Host metrics/trace retain the refusal; no invented fight reset. */ }
|
|
148
|
+
/** Explicit observation changes, e.g. a completed native move. No mechanics clock is simulated here. */
|
|
149
|
+
setActor(actor: ScenarioActor): void { this.actor(actor.id); finite([...actor.at, actor.yaw ?? 0, actor.hpShare ?? 1, ...Object.values(actor.fields ?? {})]); this.actors.set(actor.id, actorCopy(actor)); }
|
|
150
|
+
snapshot(): ScenarioWorldInput {
|
|
151
|
+
return structuredClone({ ...this.input, actors: [...this.actors.values()].filter(actor => !this.players.has(actor.id)), players: [...this.players].map(id => this.actor(id)) });
|
|
152
|
+
}
|
|
153
|
+
restore(input: ScenarioWorldInput): void {
|
|
154
|
+
const copy = structuredClone({ actors: input.actors ?? [], players: input.players ?? [], spawnGroups: input.spawnGroups ?? [], flags: input.flags ?? {}, playerFlags: input.playerFlags ?? {}, zones: input.zones ?? [], lists: input.lists ?? [] }), actors = new Map<number, ScenarioActor>();
|
|
155
|
+
for (const actor of [...copy.actors, ...copy.players]) {
|
|
156
|
+
if (!Number.isSafeInteger(actor.id) || actor.id <= 0 || actors.has(actor.id)) throw new Error('Invalid or duplicate scenario actor');
|
|
157
|
+
finite([...actor.at, actor.yaw ?? 0, actor.hpShare ?? 1, ...Object.values(actor.fields ?? {})]); actors.set(actor.id, actorCopy(actor));
|
|
158
|
+
}
|
|
159
|
+
for (const zone of copy.zones) { finite([...zone.min, ...zone.max]); if (zone.min.some((value, index) => value > (zone.max[index] ?? 0))) throw new Error('Invalid scenario zone'); }
|
|
160
|
+
for (const list of copy.lists) finite([list.op, list.a, list.b, ...list.result]);
|
|
161
|
+
this.input = copy; this.actors = actors; this.players = new Set(copy.players.map(actor => actor.id));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Translate validated wire commands back to the script's authored labels for readable expectations. */
|
|
166
|
+
export function scenarioCommand(script: DecisionScript, [op, target, a, b, c]: ScriptV1Command): ScenarioCommand {
|
|
167
|
+
const name = (kind: DecisionIdKind, id: number): string => {
|
|
168
|
+
const found = Object.entries(script.ids[kind] ?? {}).find(([, value]) => value === id)?.[0];
|
|
169
|
+
if (found === undefined) throw new Error(`Unknown scenario ${kind} id ${id}`); return found;
|
|
170
|
+
};
|
|
171
|
+
const actor = (id: number): string | number => Object.entries(script.ids.actors ?? {}).find(([, value]) => value === id)?.[0] ?? id;
|
|
172
|
+
if (op === commands.move || op === commands.strike) return [op === commands.move ? 'move' : 'strike', actor(target), name(op === commands.move ? 'moves' : 'strikes', a), ...(b === 0 ? [] : [actor(b)])];
|
|
173
|
+
if (op === commands.stop || op === commands.despawn) return [op === commands.stop ? 'stop' : 'despawn', actor(target)];
|
|
174
|
+
if (op === commands.field) return ['field', actor(target), name('fields', a), b];
|
|
175
|
+
if (op === commands.spawn) return ['spawn', name('spawns', a)];
|
|
176
|
+
if (op === commands.timer) return ['timer', name('timers', a), b];
|
|
177
|
+
if (op === commands.cue) return ['cue', ...(target === 0 ? [] : [actor(target)]), name('cues', a)];
|
|
178
|
+
if (op === commands.flag) return ['flag', name('flags', a), b];
|
|
179
|
+
if (op === commands.signal) return ['signal', name('signals', a), b];
|
|
180
|
+
if (op === commands.channel) return ['channel', name('channels', a), b];
|
|
181
|
+
if (op === commands.grant || op === commands.reward) return [op === commands.grant ? 'grant' : 'reward', actor(target), name(op === commands.grant ? 'facts' : 'rewards', a)];
|
|
182
|
+
if (op === commands.impulse) return ['impulse', actor(target), name('impulses', a)];
|
|
183
|
+
if (op === commands.weather) return ['weather', name('weather', a)];
|
|
184
|
+
if (op === commands.encounter) { const verb = ['phase', 'win', 'fail'][a - 1]; if (verb === undefined) throw new Error('Unknown encounter verb'); return ['encounter', verb, b]; }
|
|
185
|
+
const view = Object.entries(commands).find(([key, value]) => key.startsWith('view.') && value === op)?.[0];
|
|
186
|
+
if (view !== undefined) return [view, target, a, b, c];
|
|
187
|
+
throw new Error(`Unknown scenario command ${op}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Simulation-only driver. Scheduling, RNG, timers, validation, fuel and saves are always the real host's. */
|
|
191
|
+
export class ScriptScenario {
|
|
192
|
+
private tick = 0;
|
|
193
|
+
private cursor = 0;
|
|
194
|
+
private saved: ScenarioSnapshot | undefined;
|
|
195
|
+
constructor(readonly host: DecisionHost, readonly world: ScenarioWorld, private readonly script: DecisionScript, private readonly binding: number, private readonly entries: DecisionTrace[],
|
|
196
|
+
private readonly bindings: readonly number[] = [binding]) {}
|
|
197
|
+
private advanceTicks(count: number): void { for (let index = 0; index < count; index++) this.host.step(++this.tick); }
|
|
198
|
+
/** Queue a raw ABI event, then reach its decision and following atomic commit step. */
|
|
199
|
+
sendRaw(event: ScriptV1Event): void {
|
|
200
|
+
this.cursor = this.entries.length;
|
|
201
|
+
for (const binding of event[0] === events.start || event[0] === events.stop ? this.bindings : [this.binding]) this.host.enqueue(binding, event);
|
|
202
|
+
this.advanceTicks(layout.decisionDivisor - this.tick % layout.decisionDivisor + 1);
|
|
203
|
+
}
|
|
204
|
+
/** Named event arguments follow the ABI: subject first, then a/b/c/d. */
|
|
205
|
+
send(event: ScriptV1EventName, ...args: readonly (string | number | boolean)[]): void {
|
|
206
|
+
if (args.length > 5) throw new Error('Too many scenario event arguments');
|
|
207
|
+
const kinds: Partial<Record<ScriptV1EventName, readonly (DecisionIdKind | null)[]>> = {
|
|
208
|
+
timer: ['timers'], 'zone.enter': ['zones', 'actors'], 'zone.leave': ['zones', 'actors'],
|
|
209
|
+
interact: ['spots', 'actors'], hit: ['actors', 'actors'], threshold: ['actors'], death: ['actors', 'actors'],
|
|
210
|
+
'move.done': ['actors', 'moves'], 'strike.done': ['actors', 'strikes'], flag: ['flags'], signal: ['signals'],
|
|
211
|
+
'strike.target': ['targets', 'actors'], 'player.join': ['actors'], 'player.leave': ['actors'], spawned: ['actors', 'spawns'],
|
|
212
|
+
};
|
|
213
|
+
const values = args.map((value, index) => {
|
|
214
|
+
if (typeof value === 'number') { finite([value]); return value; }
|
|
215
|
+
if (typeof value === 'boolean') return value ? 1 : 0;
|
|
216
|
+
const kind = kinds[event]?.[index], id = kind === undefined || kind === null ? undefined : this.script.ids[kind]?.[value];
|
|
217
|
+
if (id === undefined) throw new Error(`Unknown scenario event argument ${value}`); return id;
|
|
218
|
+
});
|
|
219
|
+
this.sendRaw([events[event], values[0] ?? 0, values[1] ?? 0, values[2] ?? 0, values[3] ?? 0, values[4] ?? 0]);
|
|
220
|
+
}
|
|
221
|
+
advance(seconds: number): void {
|
|
222
|
+
const count = seconds * layout.fixedHz;
|
|
223
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > 1_000_000) throw new Error('Scenario time must be bounded whole simulation ticks');
|
|
224
|
+
this.cursor = this.entries.length; this.advanceTicks(count);
|
|
225
|
+
}
|
|
226
|
+
commands(): readonly ScenarioCommand[] {
|
|
227
|
+
return this.entries.slice(this.cursor).flatMap(entry => entry.kind === 'call' && entry.binding === this.binding && entry.ok ? entry.commands.map(command => scenarioCommand(this.script, command)) : []);
|
|
228
|
+
}
|
|
229
|
+
trace(): readonly DecisionTrace[] { return structuredClone(this.entries); }
|
|
230
|
+
state(): Readonly<Record<string, number | boolean>> { return this.host.state(this.binding); }
|
|
231
|
+
maxFuel(): number { const metrics = this.host.metrics().find(value => value.binding === this.binding); if (metrics === undefined || metrics.calls === 0) throw new Error('No scenario calls'); return metrics.maxFuel; }
|
|
232
|
+
save(): ScenarioSnapshot { const saved = { host: this.host.snapshot(), world: this.world.snapshot() }; this.saved = structuredClone(saved); return saved; }
|
|
233
|
+
restore(snapshot: ScenarioSnapshot | undefined = this.saved): void {
|
|
234
|
+
if (snapshot === undefined) throw new Error('No scenario save');
|
|
235
|
+
// Validate fixture data before changing either owner, then let the host validate its complete continuation.
|
|
236
|
+
const world = new ScenarioWorld(snapshot.world), before = this.world.snapshot(); this.world.restore(world.snapshot());
|
|
237
|
+
try { this.host.restore(snapshot.host); } catch (error) { this.world.restore(before); throw error; }
|
|
238
|
+
this.tick = snapshot.host.tick; this.cursor = this.entries.length;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Core constructor seam for the real KA2 host and built module bytes. No Wasm compiler or alternate host. */
|
|
243
|
+
export function createScriptScenario(Host: ScenarioHostConstructor, input: ScriptScenarioInput): ScriptScenario {
|
|
244
|
+
if (!Number.isSafeInteger(input.seed) || input.seed < 0 || input.seed > 0xffffffff) throw new Error('Invalid scenario seed');
|
|
245
|
+
const world = new ScenarioWorld(input), entries: DecisionTrace[] = [];
|
|
246
|
+
const host = new Host({ scripts: [input.script], bindings: input.bindings ?? [input.binding], modules: new Map([[input.script.module, input.bytes]]), seed: [input.seed, 0], world,
|
|
247
|
+
trace: entry => { entries.push(structuredClone(entry)); } });
|
|
248
|
+
return new ScriptScenario(host, world, input.script, input.binding.id, entries, input.bindings?.map(binding => binding.id));
|
|
249
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Data-only ABI fixture: input/effect storage is disjoint from the compiler's heap. */
|
|
2
|
+
export function scriptSource(body = '', extra = '', count = '0'): string {
|
|
3
|
+
return `${extra}
|
|
4
|
+
export function abi_version():i32 { return 0; }
|
|
5
|
+
export function init(lo:i32, hi:i32):void {}
|
|
6
|
+
export function in_ptr():i32 { return 16384; }
|
|
7
|
+
export function in_cap():i32 { return 4096; }
|
|
8
|
+
export function out_ptr():i32 { return 24576; }
|
|
9
|
+
export function out_cap():i32 { return 32; }
|
|
10
|
+
export function out_count():i32 { return ${count}; }
|
|
11
|
+
export function on_tick():void { ${body} }`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parse, type InferOutput } from 'valibot';
|
|
2
|
+
import { BowWeaponProfileSchema, HeldBowFileSchema, type HeldBowFileRows } from '@wildshard/format/weaponProfiles';
|
|
3
|
+
import STARTER_BOW from '@wildshard/engine/game/weapons/starterBow.json' with { type: 'json' };
|
|
4
|
+
import type { BowStyle as PlatformBowStyle } from '@wildshard/engine/combat/view/bowProfile';
|
|
5
|
+
|
|
6
|
+
/** Named transitional bow view strategy styles. */
|
|
7
|
+
export type BowStyle = PlatformBowStyle;
|
|
8
|
+
|
|
9
|
+
/** Admit a complete authored bow file before its pool or display strategy is borrowed. */
|
|
10
|
+
export function parseHeldBowFile(input: unknown): HeldBowFileRows { return parse(HeldBowFileSchema, input); }
|
|
11
|
+
|
|
12
|
+
/** Admit numeric draw, flight, spread and ammunition policy without a weapon or view service. */
|
|
13
|
+
export function parseBowProfile(input: unknown): InferOutput<typeof BowWeaponProfileSchema> { return parse(BowWeaponProfileSchema, input); }
|
|
14
|
+
|
|
15
|
+
/** Compile an independent shared numeric bow base from its defining committed author table.
|
|
16
|
+
* No wind owner, runtime profile object or view service enters the author result. */
|
|
17
|
+
export function sharedBowAuthorBase(): Omit<typeof STARTER_BOW, 'family'> & { family: 'bow' } {
|
|
18
|
+
if (STARTER_BOW.family !== 'bow') throw new Error('Shared bow author base requires the bow family');
|
|
19
|
+
return structuredClone({ ...STARTER_BOW, family: STARTER_BOW.family });
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { FirearmWeaponProfileSchema, parseHeldFirearmRows as parseRows, parseHeldFirearmView as parseView } from '@wildshard/format/weaponProfiles';
|
|
3
|
+
|
|
4
|
+
/** Admit numeric firearm timing, action, ammunition and range policy through its defining strict schema. */
|
|
5
|
+
export function parseFirearmProfile(input: unknown): v.InferOutput<typeof FirearmWeaponProfileSchema> {
|
|
6
|
+
return v.parse(FirearmWeaponProfileSchema, input);
|
|
7
|
+
}
|
|
8
|
+
/** Admit owned firearm model, mount and playback metadata without a renderer or weapon service. */
|
|
9
|
+
export function parseHeldFirearmRows(input: unknown): ReturnType<typeof parseRows> { return parseRows(input); }
|
|
10
|
+
/** Admit native presentation clocks and transforms without installing a view. */
|
|
11
|
+
export function parseHeldFirearmView(input: unknown): ReturnType<typeof parseView> { return parseView(input); }
|