@wildshard/sdk 0.0.1 → 0.2.3
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 +790 -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 +46 -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 +24 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +196 -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 +292 -0
- package/src/cli/report.ts +16 -0
- package/src/cli/shardfile/command.ts +50 -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/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 +117 -0
- package/src/sharddev/checkProject.ts +126 -0
- package/src/sharddev/cli.ts +191 -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 +247 -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 +18 -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 +234 -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,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Keep staged CLI/CI paths in the scaffold lane. pnpm appends arguments to
|
|
3
|
+
// the last command of an && script, which incorrectly sent them to author lint.
|
|
4
|
+
import {spawnSync} from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
const files=process.argv.slice(2).filter(file=>file!=='--');
|
|
7
|
+
const author=file=>/^src\/(?:sharddev|commons|shards)\//u.test(file);
|
|
8
|
+
const jobs=files.length===0?[['lint:kit',[]],['lint:author',[]]]:
|
|
9
|
+
[['lint:kit',files.filter(file=>!author(file))],['lint:author',files.filter(author)]].filter(([,paths])=>paths.length>0);
|
|
10
|
+
for(const [name,paths] of jobs){
|
|
11
|
+
const run=spawnSync('pnpm',['run',name,...paths],{stdio:'inherit'});
|
|
12
|
+
if(run.error!==undefined)throw run.error;
|
|
13
|
+
if(run.status!==0){process.exitCode=run.status??1;break;}
|
|
14
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type {JSHandle} from 'playwright';
|
|
2
|
+
import type {ByteSinkPage} from '@wildshard/engine/scripts/bake-output.mjs';
|
|
3
|
+
/** Save native map passes and always retire their owned handles/routes. */
|
|
4
|
+
export function saveMapFrames<T extends {colour:HTMLCanvasElement;height:HTMLCanvasElement|null}>(page:ByteSinkPage,handle:JSHandle<T>,colourFile:string,heightFile:string):Promise<Omit<T,'colour'|'height'>&{hasHeight:boolean}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { saveCanvasPng } from '@wildshard/engine/scripts/parity/canvas-bytes.mjs';
|
|
2
|
+
|
|
3
|
+
/** Retain colour/height snapshots locally; only map metadata crosses JSON.
|
|
4
|
+
* @template {{colour:HTMLCanvasElement,height:HTMLCanvasElement|null}} T
|
|
5
|
+
* @param {import('@wildshard/engine/scripts/bake-output.mjs').ByteSinkPage} page
|
|
6
|
+
* @param {import('playwright').JSHandle<T>} handle
|
|
7
|
+
* @param {string} colourFile
|
|
8
|
+
* @param {string} heightFile
|
|
9
|
+
* @returns {Promise<Omit<T,'colour'|'height'>&{hasHeight:boolean}>} */
|
|
10
|
+
export async function saveMapFrames(page, handle, colourFile, heightFile) {
|
|
11
|
+
try {
|
|
12
|
+
const metadata = await handle.evaluate(({ colour: _colour, height, ...rest }) => ({ ...rest, hasHeight: height !== null }));
|
|
13
|
+
await saveCanvasPng(page, await handle.getProperty('colour'), colourFile);
|
|
14
|
+
if (metadata.hasHeight) {
|
|
15
|
+
const height = await handle.evaluateHandle(frame => {
|
|
16
|
+
if (frame.height === null) throw new Error('Missing map height canvas');
|
|
17
|
+
return frame.height;
|
|
18
|
+
});
|
|
19
|
+
await saveCanvasPng(page, height, heightFile);
|
|
20
|
+
}
|
|
21
|
+
return metadata;
|
|
22
|
+
} finally { await handle.dispose(); }
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BufferGeometry } from 'three';
|
|
2
|
+
import type { MapAssembly as OwnedMapAssembly } from '../src/sharddev/bake/mapAssembly';
|
|
3
|
+
|
|
4
|
+
export function readMapJson(file: string): unknown;
|
|
5
|
+
export function mapModel(file: string | Uint8Array, slot?: number, world?: boolean): Promise<BufferGeometry>;
|
|
6
|
+
export class MapAssembly extends OwnedMapAssembly {
|
|
7
|
+
encode(): { json: Uint8Array<ArrayBuffer>; binary: Uint8Array<ArrayBuffer> };
|
|
8
|
+
write(file: string): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Build-only map geometry: no forest, level or runtime services are imported.
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { deflateSync } from 'node:zlib';
|
|
5
|
+
import { MapAssembly as OwnedMapAssembly, mapModelBytes } from '../src/sharddev/bake/mapAssembly.ts';
|
|
6
|
+
|
|
7
|
+
export const readMapJson = file => JSON.parse(readFileSync(file, 'utf8'), (_key, value) => value === '-0' ? -0 : value === 'Infinity' ? Infinity : value === '-Infinity' ? -Infinity : value);
|
|
8
|
+
|
|
9
|
+
/** Prepared specimens borrow local geometry, ignoring the source node's pose.
|
|
10
|
+
* Raw sculpts explicitly opt into the node transform, as their live loader does. */
|
|
11
|
+
export async function mapModel(file, slot = 0, world = false) {
|
|
12
|
+
const geometry = await mapModelBytes(file instanceof Uint8Array ? file : new Uint8Array(readFileSync(file)), slot, world);
|
|
13
|
+
return geometry;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class MapAssembly extends OwnedMapAssembly {
|
|
17
|
+
/** Encode the same ordered scene and geometry without publishing source files. */
|
|
18
|
+
encode() {
|
|
19
|
+
const { json, binary } = this.pack();
|
|
20
|
+
return { json, binary: new Uint8Array(deflateSync(binary)) };
|
|
21
|
+
}
|
|
22
|
+
write(file) {
|
|
23
|
+
const { json, binary } = this.encode();
|
|
24
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
25
|
+
writeFileSync(`${file}.bin`, binary);
|
|
26
|
+
writeFileSync(`${file}.json`, json);
|
|
27
|
+
for (const shape of this.shapes) { shape.geometry.dispose(); shape.material.dispose(); }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Build-only rest assembly of admitted model, private-scene and frozen-weld data.
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { inflateSync } from 'node:zlib';
|
|
5
|
+
import { readBakedGeometry } from '../src/sharddev/kit/bakedGeometry.ts';
|
|
6
|
+
import { _applyChunkConstants } from '@wildshard/engine/core/config';
|
|
7
|
+
import { configureLevel } from '@wildshard/engine/level/selection';
|
|
8
|
+
import { placeForest } from '@wildshard/engine/world/forest/placement';
|
|
9
|
+
|
|
10
|
+
import { BufferGeometry, Euler, Float32BufferAttribute, Matrix4, Quaternion, Vector3 } from 'three';
|
|
11
|
+
import { MapRaster } from '../src/sharddev/bake/mapRaster.ts';
|
|
12
|
+
import { readMapGeometry } from '@wildshard/engine/scripts/map-painter.mjs';
|
|
13
|
+
import { mapModel, readMapJson } from './map-geometry.mjs';
|
|
14
|
+
|
|
15
|
+
export const mapPose = pose => pose.matrix === undefined ? new Matrix4().compose(new Vector3(pose.x, pose.y, pose.z),
|
|
16
|
+
new Quaternion().setFromEuler(new Euler(pose.yxz.pitch ?? 0, pose.yxz.yawAtan2 === undefined ? pose.yxz.yaw : Math.atan2(...pose.yxz.yawAtan2), pose.yxz.roll ?? 0, 'YXZ')),
|
|
17
|
+
new Vector3().setScalar(pose.yxz.scale)) : new Matrix4().fromArray(pose.matrix);
|
|
18
|
+
const words = (values, wide = false) => wide ? new Float64Array(Uint32Array.from(values).buffer) : new Float32Array(Uint32Array.from(values).buffer);
|
|
19
|
+
const localMatrix = node => node.transformBits !== undefined && node.matrixAutoUpdate !== false ? (() => {
|
|
20
|
+
const f = words(node.transformBits, true);
|
|
21
|
+
return new Matrix4().compose(new Vector3().fromArray(f), new Quaternion().fromArray(f, 3), new Vector3().fromArray(f, 7));
|
|
22
|
+
})() : node.matrixBits === undefined ? new Matrix4() : new Matrix4().fromArray(words(node.matrixBits, true));
|
|
23
|
+
|
|
24
|
+
export class MapWorld {
|
|
25
|
+
constructor(assembly, base, section, catalogue, blobs) {
|
|
26
|
+
this.assembly = assembly; this.base = base; this.section = section; this.catalogue = catalogue;
|
|
27
|
+
this.files = new Map(blobs.map(row => row.file === undefined ? [row.name, resolve(base, row.source)] : [row.file.name, (row.file.kind ?? 'json') === 'json' ? JSON.parse(new TextDecoder().decode(row.bytes)) : row.bytes]));
|
|
28
|
+
this.geometry = new Map(); this.frames = new Map();
|
|
29
|
+
}
|
|
30
|
+
json(file) { const source = this.files.get(file); if (source === undefined || source instanceof Uint8Array) throw new Error(`Missing map world JSON ${file}`); return typeof source === 'string' ? readMapJson(source) : source; }
|
|
31
|
+
/** A scene part's instance matrices: an instanceMatrix row (inline or a float32 product packet), else the recipe's. */
|
|
32
|
+
matrices(step, id, node) {
|
|
33
|
+
const row = (step.instanceAttributes ?? []).find(entry => entry.part === id && entry.target === 'instanceMatrix');
|
|
34
|
+
if (row === undefined) return node.matrices; if (row.values !== undefined) return row.values;
|
|
35
|
+
const bytes = this.files.get(row.packet.file); if (!(bytes instanceof Uint8Array)) throw new Error(`Missing map world packet ${row.packet.file}`);
|
|
36
|
+
return new Float32Array(bytes.buffer.slice(bytes.byteOffset + row.packet.byteOffset, bytes.byteOffset + row.packet.byteOffset + row.packet.count * 64));
|
|
37
|
+
}
|
|
38
|
+
async shape(ref) {
|
|
39
|
+
const key = `${ref.library}/${ref.model}`;
|
|
40
|
+
let geometry = this.geometry.get(key);
|
|
41
|
+
if (geometry !== undefined) return geometry.clone();
|
|
42
|
+
const library = this.section.libraries.find(row => row.id === ref.library);
|
|
43
|
+
const model = library?.models.find(row => row.id === ref.model), file = this.files.get(typeof model?.file === 'string' ? model.file : model?.file?.desktop);
|
|
44
|
+
if (typeof file !== 'string' && !(file instanceof Uint8Array)) throw new Error(`Missing map world geometry ${key}`);
|
|
45
|
+
geometry = await mapModel(file); this.geometry.set(key, geometry); return geometry.clone();
|
|
46
|
+
}
|
|
47
|
+
ghost(id, locals = []) {
|
|
48
|
+
if (id === '$shadow') return true;
|
|
49
|
+
const material = locals.find(row => row.id === id) ?? this.section.materials.find(row => row.id === id);
|
|
50
|
+
return material?.properties?.depthWrite === false || material?.properties?.colorWrite === false;
|
|
51
|
+
}
|
|
52
|
+
async placement(row) {
|
|
53
|
+
if (row.drawnInto !== undefined) return;
|
|
54
|
+
const model = this.catalogue.models.find(entry => entry.key === row.model);
|
|
55
|
+
if (model === undefined) throw new Error(`Missing map world model ${row.model}`);
|
|
56
|
+
const groups = new Map();
|
|
57
|
+
for (const pose of row.poses) {
|
|
58
|
+
const variant = (model.variants ?? []).find(entry => entry.id === pose.variant);
|
|
59
|
+
const params = { ...model.defaults, ...variant?.params, ...pose.params };
|
|
60
|
+
const choice = model.choices.find(entry => Object.entries(entry.params).every(([key, value]) => JSON.stringify(params[key]) === JSON.stringify(value)));
|
|
61
|
+
if (choice === undefined) throw new Error(`Missing map choice ${row.id}`);
|
|
62
|
+
if (choice.scene !== undefined) throw new Error(`Placed frozen scene needs an explicit map rest graph: ${row.id}`);
|
|
63
|
+
const matrices = groups.get(choice) ?? []; matrices.push(mapPose(pose)); groups.set(choice, matrices);
|
|
64
|
+
}
|
|
65
|
+
for (const [choice, matrices] of groups) for (const draw of choice.draws) {
|
|
66
|
+
if (draw.depthOnly === true || this.ghost(draw.material)) continue;
|
|
67
|
+
this.assembly.add(`place:${row.id}:${draw.id}`, await this.shape(draw), matrices);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async batch(row) {
|
|
71
|
+
for (const [i, copy] of row.fixed.entries()) this.assembly.add(`batch:${row.id}:${i}`, await this.shape(row.geometry[copy.lod0]), [new Matrix4().fromArray(copy.matrix)]);
|
|
72
|
+
}
|
|
73
|
+
async weld(graph) {
|
|
74
|
+
const frames = new Map([[graph.root, this.frames.get(graph.root) ?? new Matrix4()]]), visible = new Map([[graph.root, true]]);
|
|
75
|
+
for (const node of graph.nodes) {
|
|
76
|
+
const parent = frames.get(node.parent) ?? this.frames.get(node.parent);
|
|
77
|
+
if (parent === undefined) throw new Error(`Missing map weld parent ${node.parent}`);
|
|
78
|
+
const matrix = new Matrix4().multiplyMatrices(parent, localMatrix(node)); frames.set(node.id, matrix); this.frames.set(node.id, matrix);
|
|
79
|
+
const live = (visible.get(node.parent) ?? true) && node.visible !== false; visible.set(node.id, live);
|
|
80
|
+
// Views partition a batch's bounds; the batch already contains all draws.
|
|
81
|
+
if (!live || !['mesh', 'batch', 'instances'].includes(node.kind) || this.ghost(node.material, graph.materials)) continue;
|
|
82
|
+
const matrices = node.kind === 'instances' ? Array.from({ length: node.count }, (_, i) => matrix.clone().multiply(new Matrix4().fromArray(words(node.matrixWords), i * 16))) : [matrix];
|
|
83
|
+
this.assembly.add(`weld:${graph.id}:${node.id}`, await this.shape(node.geometry), matrices);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async recipe(step, root = new Matrix4(), omitted = []) {
|
|
87
|
+
const recipe = this.json(step.scene), scene = recipe.scene ?? recipe;
|
|
88
|
+
if ((recipe.imports ?? []).length > 0) throw new Error(`Map world recipe imports need explicit rest data: ${step.id}`);
|
|
89
|
+
const nodes = new Map(scene.nodes.map(row => [row.id, row]));
|
|
90
|
+
const walk = async (id, parent, visible) => {
|
|
91
|
+
const node = nodes.get(id); if (node === undefined) throw new Error(`Missing map recipe node ${id}`);
|
|
92
|
+
const local = node.matrix === undefined ? new Matrix4().compose(new Vector3(...node.position ?? [0, 0, 0]), node.quaternion === undefined ? new Quaternion().setFromEuler(new Euler(...node.rotation ?? [0, 0, 0], node.order ?? 'XYZ')) : new Quaternion(...node.quaternion), new Vector3(...node.scale ?? [1, 1, 1])) : new Matrix4().fromArray(node.matrix);
|
|
93
|
+
const matrix = parent.clone().multiply(local), live = visible && node.visible !== false;
|
|
94
|
+
if (node.kind === 'mesh' && live && !omitted.includes(id) && !this.ghost(step.materials[node.material])) {
|
|
95
|
+
const ref = step.geometry[node.geometry]; if (ref === undefined) throw new Error(`Missing map recipe geometry ${node.geometry}`);
|
|
96
|
+
const instanced = this.matrices(step, id, node);
|
|
97
|
+
this.assembly.add(`scene:${step.id}:${id}`, await this.shape(ref), instanced === undefined ? [matrix] : Array.from({ length: node.instances }, (_, i) => matrix.clone().multiply(new Matrix4().fromArray(instanced, i * 16))));
|
|
98
|
+
} else if (!['mesh', 'group', 'anchor', 'light'].includes(node.kind)) throw new Error(`Unsupported map recipe ${node.kind}`);
|
|
99
|
+
for (const child of node.children ?? []) await walk(child, matrix, live);
|
|
100
|
+
};
|
|
101
|
+
await walk(scene.root, root, true);
|
|
102
|
+
}
|
|
103
|
+
dispose() { for (const geometry of this.geometry.values()) geometry.dispose(); }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Retain the renderer's original grid and float32 coordinates. Colour is a
|
|
107
|
+
* map palette only; the underlying triangle positions are never re-sampled. */
|
|
108
|
+
export function mapGround(source, resolution, size, palette, hole) {
|
|
109
|
+
// Same rotated PlaneGeometry lattice as Terrain. Plane's -Z row order matters.
|
|
110
|
+
const geometry = new BufferGeometry(), points = [], colours = [], indices = [];
|
|
111
|
+
for (let z = 0; z < resolution; z++) for (let x = 0; x < resolution; x++) {
|
|
112
|
+
const px = Math.fround(x * size / (resolution - 1) - size / 2), pz = Math.fround(z * size / (resolution - 1) - size / 2);
|
|
113
|
+
points.push(px, Math.fround(source.heightAt(px, pz)), pz);
|
|
114
|
+
const splat = source.splatAt(px, pz), rgb = [0, 0, 0];
|
|
115
|
+
for (let i = 0; i < 4; i++) for (let c = 0; c < 3; c++) rgb[c] += splat[i] * palette[i][c];
|
|
116
|
+
colours.push(...rgb);
|
|
117
|
+
}
|
|
118
|
+
for (let z = 0; z < resolution - 1; z++) for (let x = 0; x < resolution - 1; x++) {
|
|
119
|
+
const a = z * resolution + x;
|
|
120
|
+
for (const ids of [[a, a + resolution, a + 1], [a + resolution + 1, a + 1, a + resolution]]) if (hole === undefined || !hole(ids.map(i => points.slice(i * 3, i * 3 + 3)))) indices.push(...ids);
|
|
121
|
+
}
|
|
122
|
+
geometry.setAttribute('position', new Float32BufferAttribute(points, 3)); geometry.setAttribute('color', new Float32BufferAttribute(colours, 3)); geometry.setIndex(indices); return geometry;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Decode all local templates once; node transforms belong to their declared
|
|
126
|
+
* world placements, while raw imported scenes explicitly request world=true. */
|
|
127
|
+
export async function mapPool(file, world = false) {
|
|
128
|
+
const doc = await new MapRaster(1, {}, readMapGeometry).document(file), result = new Map();
|
|
129
|
+
for (const node of doc.getRoot().listNodes()) {
|
|
130
|
+
const mesh = node.getMesh(); if (mesh === null) continue;
|
|
131
|
+
if (mesh.listPrimitives().length !== 1) throw new Error(`Map pool requires one primitive ${file}`);
|
|
132
|
+
const primitive = mesh.listPrimitives()[0], geometry = new BufferGeometry();
|
|
133
|
+
for (const [semantic, name] of [['POSITION', 'position'], ['COLOR_0', 'color']]) {
|
|
134
|
+
const attribute = primitive.getAttribute(semantic); if (attribute === null) continue;
|
|
135
|
+
const data = []; for (let i = 0; i < attribute.getCount(); i++) data.push(...attribute.getElement(i, []).slice(0, 3));
|
|
136
|
+
geometry.setAttribute(name, new Float32BufferAttribute(data, 3));
|
|
137
|
+
}
|
|
138
|
+
const indices = primitive.getIndices(); if (indices !== null) geometry.setIndex(Array.from(indices.getArray()));
|
|
139
|
+
if (world) geometry.applyMatrix4(new Matrix4().fromArray(node.getWorldMatrix()));
|
|
140
|
+
const id = node.getName() === '' ? mesh.getName() : node.getName(); if (result.has(id)) throw new Error(`Duplicate map pool geometry ${id}`); result.set(id, geometry);
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function mapForest(constants, field, forest, variants) {
|
|
146
|
+
_applyChunkConstants(constants);
|
|
147
|
+
configureLevel({ id: constants.slug, ground: { terrain: field }, forest });
|
|
148
|
+
return placeForest(variants).trees;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function mapBinary(file, shuffled = false) {
|
|
152
|
+
const bytes = new Uint8Array(inflateSync(readFileSync(file)));
|
|
153
|
+
if (!shuffled) return bytes;
|
|
154
|
+
const out = new Uint8Array(bytes.length), n = bytes.length / 4;
|
|
155
|
+
for (let b = 0; b < 4; b++) for (let i = 0; i < n; i++) out[i * 4 + b] = bytes[b * n + i];
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
export function mapGeometry(bytes, offset, row) {
|
|
159
|
+
const geometry = readBakedGeometry(bytes, offset, row);
|
|
160
|
+
if (!row.expand || geometry.index === null) return geometry;
|
|
161
|
+
const expanded = geometry.toNonIndexed(); geometry.dispose(); return expanded;
|
|
162
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# mockup-local.sh — one mockup with LOCAL Qwen-Image-2.1 + the Viggle turbo LoRA (6 steps, ~20-35 s on the M5 Max),
|
|
3
|
+
# the fast alternative to codex image_gen (AGENTS.md "Mockups"). Edits the reference frame(s) the way codex does.
|
|
4
|
+
#
|
|
5
|
+
# scripts/mockup-local.sh --ref <frame.jpg> [--ref <style.png> ...] --prompt-file <p.txt> --out <out.png>
|
|
6
|
+
# [--mask <mask.png>] [--size WxH] [--seed N] [--steps40]
|
|
7
|
+
#
|
|
8
|
+
# --ref condition image(s); the FIRST is the frame being edited (a live capture, like the codex flow)
|
|
9
|
+
# --mask white = the only area that may change; the output is composited back over the untouched frame
|
|
10
|
+
# outside it (pixel-identical world). Use it for localised edits: move a button, add a chip / panel.
|
|
11
|
+
# --size output aspect (default: the first ref's); rendered at ~1 MP
|
|
12
|
+
# --steps40 the full 40-step model instead of turbo (~4x slower, same look)
|
|
13
|
+
#
|
|
14
|
+
# Runs under the machine-wide model lock (~/projects/localai/.model.lock), so it may queue behind music / SFX / 3D
|
|
15
|
+
# jobs from other agents. The shared run-locked launcher caps lock and memory admission at five minutes.
|
|
16
|
+
# Setup + traps: ~/projects/localai/docs/image-models.md. Weights: ~/projects/weights/manual/Qwen/.
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
IG="$HOME/ml/imagegen"
|
|
19
|
+
refs=(); prompt=""; out=""; mask=""; size=""; seed=42; turbo="--turbo"
|
|
20
|
+
while [ $# -gt 0 ]; do
|
|
21
|
+
case "$1" in
|
|
22
|
+
--ref) refs+=("$(cd "$(dirname "$2")" && pwd)/$(basename "$2")"); shift 2 ;;
|
|
23
|
+
--prompt-file) prompt="$2"; shift 2 ;;
|
|
24
|
+
--out) out="$2"; shift 2 ;;
|
|
25
|
+
--mask) mask="$(cd "$(dirname "$2")" && pwd)/$(basename "$2")"; shift 2 ;;
|
|
26
|
+
--size) size="$2"; shift 2 ;;
|
|
27
|
+
--seed) seed="$2"; shift 2 ;;
|
|
28
|
+
--steps40) turbo=""; shift ;;
|
|
29
|
+
-h|--help) sed -n '2,17p' "$0"; exit 0 ;;
|
|
30
|
+
*) echo "mockup-local: unknown arg $1" >&2; exit 2 ;;
|
|
31
|
+
esac
|
|
32
|
+
done
|
|
33
|
+
[ ${#refs[@]} -gt 0 ] && [ -n "$prompt" ] && [ -n "$out" ] || { sed -n '2,17p' "$0"; exit 2; }
|
|
34
|
+
if [ -z "$size" ]; then size="$(sips -g pixelWidth -g pixelHeight "${refs[0]}" | awk '/pixelWidth/{w=$2} /pixelHeight/{h=$2} END{print w "x" h}')"; fi
|
|
35
|
+
run="$IG/runs/$(date +%Y%m%d-%H%M%S)-$$"; mkdir -p "$run"
|
|
36
|
+
jq -n --rawfile p "$prompt" --arg w "${size%x*}" --arg h "${size#*x}" --args \
|
|
37
|
+
'[{id: "mockup", prompt: $p, inputs: $ARGS.positional, size: [($w|tonumber), ($h|tonumber)]}]' "${refs[@]}" \
|
|
38
|
+
| jq . > "$run/jobs.json"
|
|
39
|
+
args=(--jobs "$run/jobs.json" --repo / --out "$run" --res 1024 --seed "$seed" --vae-fp32 --kv auto)
|
|
40
|
+
[ -n "$turbo" ] && args+=(--turbo)
|
|
41
|
+
if [ -n "$mask" ]; then cp "$mask" "$run/mockup.mask.png"; args+=(--masks "$run"); fi
|
|
42
|
+
"$IG/run-locked.sh" "$run/log.txt" "$IG/.venv/bin/python" "$IG/gen_qwen21.py" "${args[@]}"
|
|
43
|
+
[ -f "$run/mockup.png" ] || { echo "mockup-local: no image — see $run/log.txt" >&2; exit 1; }
|
|
44
|
+
if jq -e '.black' "$run/mockup.json" >/dev/null; then echo "mockup-local: BLACK frame (NaN) — see $run/log.txt" >&2; exit 1; fi
|
|
45
|
+
mkdir -p "$(dirname "$out")"; cp "$run/mockup.png" "$out"
|
|
46
|
+
echo "mockup-local: $out ($(jq -r '"\(.size[0])x\(.size[1]), \(.seconds) s"' "$run/mockup.json"); run dir $run)"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The score (src/client/game/audio/theme.ts) → a standard MIDI file, one track per layer, for a composer to take further.
|
|
2
|
+
// node scripts/music/export-midi.mjs [theme|trailer30|trailer15] [out.mid] default: theme → scripts/music/wildshard-theme.mid
|
|
3
|
+
// drone and pad are derived from the chord track (root D2 + D3 held; the pad's four voices per chord); pulse is a GM drum
|
|
4
|
+
// track on channel 10 (36 kick · 35 four-on-the-floor kick · 38 tap · 42 shaker). Tempo changes per segment; the theme's
|
|
5
|
+
// loop (D → B) is written once, followed by the ring-out.
|
|
6
|
+
import { writeFileSync } from 'node:fs';
|
|
7
|
+
import { resolve } from 'node:path';
|
|
8
|
+
import { ARRANGEMENTS, CHORDS } from '@wildshard/engine/game/audio/theme';
|
|
9
|
+
|
|
10
|
+
const here = import.meta.dirname;
|
|
11
|
+
const name = process.argv[2] ?? 'theme';
|
|
12
|
+
const out = resolve(process.argv[3] ?? `${here}/wildshard-${name}.mid`);
|
|
13
|
+
|
|
14
|
+
// The defining score is pure author data; Node 24 strips its type-only declarations.
|
|
15
|
+
const arr = Object.entries(ARRANGEMENTS).find(([key]) => key === name)?.[1];
|
|
16
|
+
if (!arr) throw new Error(`no arrangement ${name}`);
|
|
17
|
+
|
|
18
|
+
const PPQ = 480;
|
|
19
|
+
const LAYERS = ['drone', 'pad', 'pluck', 'marimba', 'bass', 'pulse', 'bell'];
|
|
20
|
+
const PROGRAM = { drone: 89, pad: 88, pluck: 24, marimba: 12, bass: 38, bell: 14 }; // GM: pad 2 (warm), new age, nylon guitar, marimba, synth bass 1, tubular bells
|
|
21
|
+
const CHANNEL = { drone: 0, pad: 1, pluck: 2, marimba: 3, bass: 4, pulse: 9, bell: 5 };
|
|
22
|
+
|
|
23
|
+
// events per track: { tick, bytes }
|
|
24
|
+
const tracks = Object.fromEntries(LAYERS.map((l) => [l, []]));
|
|
25
|
+
const tempoTrack = [];
|
|
26
|
+
const vlq = (n) => { let v = n; const b = [v & 0x7f]; while ((v >>= 7) > 0) b.unshift((v & 0x7f) | 0x80); return b; };
|
|
27
|
+
const note = (layer, tick, dur, n, v = 0.8) => {
|
|
28
|
+
const ch = CHANNEL[layer], vel = Math.max(1, Math.min(127, Math.round(v * 110)));
|
|
29
|
+
tracks[layer].push({ tick, bytes: [0x90 | ch, n, vel] }, { tick: tick + Math.max(1, Math.round(dur)), bytes: [0x80 | ch, n, 0] });
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
let tick = 0;
|
|
33
|
+
const segs = arr.tailFrom !== undefined ? arr.segments : arr.segments; // the loop is written once
|
|
34
|
+
for (const seg of segs) {
|
|
35
|
+
const usPerBeat = Math.round(60e6 / seg.bpm);
|
|
36
|
+
tempoTrack.push({ tick, bytes: [0xff, 0x51, 0x03, (usPerBeat >> 16) & 0xff, (usPerBeat >> 8) & 0xff, usPerBeat & 0xff] });
|
|
37
|
+
const T = (b) => tick + Math.round(b * PPQ);
|
|
38
|
+
const segTicks = Math.round(seg.beats * PPQ);
|
|
39
|
+
// chords → pad (held to the next chord) and drone (root pedal for the segment)
|
|
40
|
+
seg.chords.forEach((c, i) => {
|
|
41
|
+
const end = i + 1 < seg.chords.length ? seg.chords[i + 1].t : seg.beats;
|
|
42
|
+
for (const p of CHORDS[c.chord]) note('pad', T(c.t), (end - c.t) * PPQ, p, 0.6);
|
|
43
|
+
});
|
|
44
|
+
if (seg.chords.length > 0 || seg.beats > 0) { note('drone', tick, segTicks, 38, 0.5); note('drone', tick, segTicks, 50, 0.4); }
|
|
45
|
+
for (const layer of ['pluck', 'marimba', 'bass', 'pulse', 'bell']) for (const n of seg.notes[layer] ?? []) note(layer, T(n.t), n.d * PPQ, n.n, n.v ?? 0.8);
|
|
46
|
+
tick += segTicks;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const str = (s) => [...Buffer.from(s, 'utf8')];
|
|
50
|
+
const meta = (type, data) => [0xff, type, ...vlq(data.length), ...data];
|
|
51
|
+
const chunk = (id, body) => [...str(id), (body.length >>> 24) & 0xff, (body.length >>> 16) & 0xff, (body.length >>> 8) & 0xff, body.length & 0xff, ...body];
|
|
52
|
+
const trackBytes = (events, head = []) => {
|
|
53
|
+
events.sort((a, b) => a.tick - b.tick || (a.bytes[0] & 0xf0) - (b.bytes[0] & 0xf0)); // note-offs before note-ons at the same tick
|
|
54
|
+
const body = [...head]; let last = 0;
|
|
55
|
+
for (const e of events) { body.push(...vlq(e.tick - last), ...e.bytes); last = e.tick; }
|
|
56
|
+
body.push(0x00, 0xff, 0x2f, 0x00);
|
|
57
|
+
return chunk('MTrk', body);
|
|
58
|
+
};
|
|
59
|
+
const file = [...chunk('MThd', [0, 1, 0, LAYERS.length + 1, (PPQ >> 8) & 0xff, PPQ & 0xff])];
|
|
60
|
+
file.push(...trackBytes(tempoTrack, [0x00, ...meta(0x03, str(`Wildshard — ${arr.name}`)), 0x00, ...meta(0x58, [4, 2, 24, 8])]));
|
|
61
|
+
for (const l of LAYERS) {
|
|
62
|
+
const head = [0x00, ...meta(0x03, str(l))];
|
|
63
|
+
if (PROGRAM[l] !== undefined) head.push(0x00, 0xc0 | CHANNEL[l], PROGRAM[l]);
|
|
64
|
+
file.push(...trackBytes(tracks[l], head));
|
|
65
|
+
}
|
|
66
|
+
writeFileSync(out, Buffer.from(file));
|
|
67
|
+
const notes = Object.values(tracks).reduce((a, t) => a + t.length / 2, 0);
|
|
68
|
+
console.log(`${arr.name}: ${segs.length} segments, ${notes} notes, ${(tick / PPQ).toFixed(0)} beats → ${out} (${file.length} bytes)`);
|