@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.
Files changed (688) hide show
  1. package/GUIDE.md +895 -0
  2. package/README.md +13 -5
  3. package/bin/wildshard.mjs +38 -0
  4. package/lint/declaration-config.d.mts +2 -0
  5. package/lint/declaration-config.mjs +19 -0
  6. package/lint/engine-plugin.d.mts +2 -0
  7. package/lint/engine-plugin.mjs +40 -0
  8. package/lint/host-callbacks.d.mts +6 -0
  9. package/lint/host-callbacks.mjs +123 -0
  10. package/lint/host-files.d.mts +1 -0
  11. package/lint/host-files.mjs +7 -0
  12. package/lint/layer-exports.d.mts +2 -0
  13. package/lint/layer-exports.mjs +21 -0
  14. package/lint/legacy-line-basis.json +995 -0
  15. package/lint/nine-tiling-baseline.json +35 -0
  16. package/lint/ratchet.json +11 -0
  17. package/lint/runtime-files.d.mts +12 -0
  18. package/lint/runtime-files.json +16 -0
  19. package/lint/runtime-files.mjs +69 -0
  20. package/lint/runtime-performance.d.mts +6 -0
  21. package/lint/runtime-performance.mjs +184 -0
  22. package/lint/sdk-plugin.d.mts +4 -0
  23. package/lint/sdk-plugin.mjs +134 -0
  24. package/lint/shardfile-boundaries.d.mts +10 -0
  25. package/lint/shardfile-boundaries.mjs +122 -0
  26. package/lint/tile-bake-debt.json +556 -0
  27. package/package.json +365 -3
  28. package/scripts/agent-parity.mjs +1524 -0
  29. package/scripts/agent-sync.mjs +518 -0
  30. package/scripts/apfs-clone.mjs +67 -0
  31. package/scripts/assert-store-layout.mjs +23 -0
  32. package/scripts/astc6-phone-cap.d.mts +3 -0
  33. package/scripts/astc6-phone-cap.mjs +137 -0
  34. package/scripts/audit-assets.d.mts +10 -0
  35. package/scripts/audit-assets.mjs +151 -0
  36. package/scripts/bake/coatFiles.d.mts +6 -0
  37. package/scripts/bake/coatFiles.mjs +37 -0
  38. package/scripts/bake/environment.d.mts +2 -0
  39. package/scripts/bake/environment.mjs +58 -0
  40. package/scripts/bake/far-proxies.mjs +45 -0
  41. package/scripts/bake/keyed-sky.d.mts +4 -0
  42. package/scripts/bake/keyed-sky.mjs +34 -0
  43. package/scripts/bake/movers.mjs +56 -0
  44. package/scripts/bake/nativeWorld.d.mts +6 -0
  45. package/scripts/bake/nativeWorld.mjs +43 -0
  46. package/scripts/bake/navmeshGround.ts +22 -0
  47. package/scripts/bake/near-placeholder.mjs +331 -0
  48. package/scripts/bake/placeholderShards.mjs +41 -0
  49. package/scripts/bake/skins.mjs +15 -0
  50. package/scripts/bake/template-skins.mjs +33 -0
  51. package/scripts/bake/viewmodelBytes.ts +26 -0
  52. package/scripts/bake/viewmodelPage.ts +11 -0
  53. package/scripts/bake/worldHost.d.mts +35 -0
  54. package/scripts/bake/worldHost.mjs +110 -0
  55. package/scripts/bake-astc6.cache.json +80 -0
  56. package/scripts/bake-astc6.far-reach.cache.json +23 -0
  57. package/scripts/bake-astc6.list.json +111 -0
  58. package/scripts/bake-astc6.mjs +279 -0
  59. package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
  60. package/scripts/bake-catalogue.mjs +44 -0
  61. package/scripts/bake-check.mjs +54 -0
  62. package/scripts/bake-chunk.mjs +124 -0
  63. package/scripts/bake-cloud-field.mjs +24 -0
  64. package/scripts/bake-coats.mjs +110 -0
  65. package/scripts/bake-data-maps.d.mts +24 -0
  66. package/scripts/bake-data-maps.mjs +72 -0
  67. package/scripts/bake-entry-programs.mjs +117 -0
  68. package/scripts/bake-geometry.mjs +106 -0
  69. package/scripts/bake-hybrid-tiles.mjs +28 -0
  70. package/scripts/bake-ktx2.cache.json +276 -0
  71. package/scripts/bake-ktx2.list.json +365 -0
  72. package/scripts/bake-ktx2.mjs +477 -0
  73. package/scripts/bake-map-glb.mjs +127 -0
  74. package/scripts/bake-map-rest.d.mts +7 -0
  75. package/scripts/bake-map-rest.mjs +50 -0
  76. package/scripts/bake-maps.mjs +200 -0
  77. package/scripts/bake-navmesh.mjs +259 -0
  78. package/scripts/bake-packs.mjs +129 -0
  79. package/scripts/bake-pickups.mjs +102 -0
  80. package/scripts/bake-query-terrain.mjs +64 -0
  81. package/scripts/bake-recurve-pool.mjs +16 -0
  82. package/scripts/bake-section-schemas.d.mts +3 -0
  83. package/scripts/bake-template-shardfile.mjs +32 -0
  84. package/scripts/bake-textures.mjs +80 -0
  85. package/scripts/bake-viewmodel-sets.json +45 -0
  86. package/scripts/bake-viewmodel-sets.mjs +137 -0
  87. package/scripts/bake-voxel-ao.mjs +119 -0
  88. package/scripts/bake-water-ripples.mjs +25 -0
  89. package/scripts/blender/README.md +129 -0
  90. package/scripts/blender/build.sh +166 -0
  91. package/scripts/blender/lib/export-scene.mjs +129 -0
  92. package/scripts/blender/lib/glb-digest.mjs +188 -0
  93. package/scripts/blender/lib/glb.py +68 -0
  94. package/scripts/blender/lib/save_blend.py +17 -0
  95. package/scripts/blender/lib/world_fixture.py +55 -0
  96. package/scripts/blender/targets.json +591 -0
  97. package/scripts/build-sdk.mjs +95 -0
  98. package/scripts/build-shardfiles.d.mts +7 -0
  99. package/scripts/build-shardfiles.mjs +206 -0
  100. package/scripts/capture-hero.mjs +137 -0
  101. package/scripts/check-lift-review.mjs +23 -0
  102. package/scripts/chromium-keychain-check.mjs +139 -0
  103. package/scripts/chromium-keychain.d.mts +1 -0
  104. package/scripts/chromium-keychain.mjs +5 -0
  105. package/scripts/compile-script.d.mts +3 -0
  106. package/scripts/compile-script.mjs +8 -0
  107. package/scripts/creature-color.mjs +255 -0
  108. package/scripts/decide/calibrate.py +127 -0
  109. package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
  110. package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
  111. package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
  112. package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
  113. package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
  114. package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
  115. package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
  116. package/scripts/decide/decide.py +262 -0
  117. package/scripts/decide/decide.sh +50 -0
  118. package/scripts/decide/layer-purity-pilot.mjs +41 -0
  119. package/scripts/decide/sets/capture-status.json +46 -0
  120. package/scripts/decide/sets/layer-purity.json +28 -0
  121. package/scripts/decide/sets/text-garbled.json +17 -0
  122. package/scripts/decide/test_decide.py +37 -0
  123. package/scripts/docs.mjs +15 -0
  124. package/scripts/entry-reads/crawl.ts +152 -0
  125. package/scripts/entry-reads/tsconfig.json +25 -0
  126. package/scripts/gen-format-schema.d.mts +2 -0
  127. package/scripts/gen-format-schema.mjs +21 -0
  128. package/scripts/gen-host-catalogue.d.mts +14 -0
  129. package/scripts/gen-host-catalogue.mjs +108 -0
  130. package/scripts/gen-shard-layout-doc.d.mts +4 -0
  131. package/scripts/gen-shard-layout-doc.mjs +55 -0
  132. package/scripts/gen-shards.d.mts +17 -0
  133. package/scripts/gen-shards.mjs +311 -0
  134. package/scripts/goldens/capture-inputs.d.mts +4 -0
  135. package/scripts/goldens/capture-inputs.mjs +34 -0
  136. package/scripts/goldens/colour_shift.py +27 -0
  137. package/scripts/goldens/native-residency.d.mts +10 -0
  138. package/scripts/goldens/native-residency.mjs +104 -0
  139. package/scripts/goldens/plot-inputs.d.mts +12 -0
  140. package/scripts/goldens/plot-inputs.mjs +46 -0
  141. package/scripts/gpu-texmem.mjs +98 -0
  142. package/scripts/horizon-matte/config.py +24 -0
  143. package/scripts/horizon-matte/encode.py +91 -0
  144. package/scripts/horizon-matte/key.py +141 -0
  145. package/scripts/horizon-matte/mkjobs.py +33 -0
  146. package/scripts/horizon-matte/mkjobs_day2.py +11 -0
  147. package/scripts/horizon-matte/overlap.py +80 -0
  148. package/scripts/horizon-matte/run_codex.py +57 -0
  149. package/scripts/horizon-matte/stitch.py +133 -0
  150. package/scripts/img2mesh/CC0.md +105 -0
  151. package/scripts/img2mesh/README.md +209 -0
  152. package/scripts/img2mesh/ab_board.py +102 -0
  153. package/scripts/img2mesh/birds/birds.json +255 -0
  154. package/scripts/img2mesh/birds/birds_atlas.py +150 -0
  155. package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
  156. package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
  157. package/scripts/img2mesh/birds/birds_pack.py +110 -0
  158. package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
  159. package/scripts/img2mesh/birds/birds_post.py +550 -0
  160. package/scripts/img2mesh/birds/birds_render.py +125 -0
  161. package/scripts/img2mesh/birds/birds_sheet.py +33 -0
  162. package/scripts/img2mesh/birds/birds_view.py +60 -0
  163. package/scripts/img2mesh/board.py +100 -0
  164. package/scripts/img2mesh/build_cc0.sh +52 -0
  165. package/scripts/img2mesh/build_driftwood.sh +12 -0
  166. package/scripts/img2mesh/build_faces.sh +53 -0
  167. package/scripts/img2mesh/build_props.py +81 -0
  168. package/scripts/img2mesh/cc0_export.py +186 -0
  169. package/scripts/img2mesh/driftwood_post.py +571 -0
  170. package/scripts/img2mesh/e304_faces.sh +67 -0
  171. package/scripts/img2mesh/face_remaster.py +911 -0
  172. package/scripts/img2mesh/face_views.py +95 -0
  173. package/scripts/img2mesh/faces-e304.json +9 -0
  174. package/scripts/img2mesh/faces.json +30 -0
  175. package/scripts/img2mesh/head_cut.py +100 -0
  176. package/scripts/img2mesh/hi3d_paint.py +94 -0
  177. package/scripts/img2mesh/hi3d_refine.py +161 -0
  178. package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
  179. package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
  180. package/scripts/img2mesh/props/coral-arch.json +32 -0
  181. package/scripts/img2mesh/props/ember-furnace.json +30 -0
  182. package/scripts/img2mesh/props/night-market-gate.json +10 -0
  183. package/scripts/img2mesh/render_still.py +86 -0
  184. package/scripts/img2mesh/rig_strip.mjs +46 -0
  185. package/scripts/img2mesh/rig_transfer.mjs +104 -0
  186. package/scripts/img2mesh/split_sheet.py +48 -0
  187. package/scripts/img2mesh/trellis_batch.py +110 -0
  188. package/scripts/img2mesh/versus_board.py +114 -0
  189. package/scripts/import-bundle.d.mts +2 -0
  190. package/scripts/import-bundle.mjs +20 -0
  191. package/scripts/ktx2-ab-board.py +133 -0
  192. package/scripts/ktx2-ab.mjs +111 -0
  193. package/scripts/ktx2-settings.mjs +18 -0
  194. package/scripts/land.d.mts +14 -0
  195. package/scripts/land.mjs +809 -0
  196. package/scripts/lint-dispatch.mjs +14 -0
  197. package/scripts/map-bake-frames.d.mts +4 -0
  198. package/scripts/map-bake-frames.mjs +23 -0
  199. package/scripts/map-geometry.d.mts +9 -0
  200. package/scripts/map-geometry.mjs +29 -0
  201. package/scripts/map-world.mjs +162 -0
  202. package/scripts/mockup-local.sh +46 -0
  203. package/scripts/music/export-midi.mjs +68 -0
  204. package/scripts/music/gen/analyze.py +308 -0
  205. package/scripts/music/gen/audio_jobs.py +46 -0
  206. package/scripts/music/gen/briefs.json +51 -0
  207. package/scripts/music/gen/build_page.py +334 -0
  208. package/scripts/music/gen/folk.json +3187 -0
  209. package/scripts/music/gen/gen_ace_step.py +156 -0
  210. package/scripts/music/gen/gen_heartmula.py +187 -0
  211. package/scripts/music/gen/gen_minimax.py +143 -0
  212. package/scripts/music/gen/gen_sao.py +122 -0
  213. package/scripts/music/gen/gen_sao_small.py +104 -0
  214. package/scripts/music/gen/gen_sfx.py +98 -0
  215. package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
  216. package/scripts/music/gen/gen_sfx_moss.py +112 -0
  217. package/scripts/music/gen/models.json +61 -0
  218. package/scripts/music/gen/nalati-jobs.json +104 -0
  219. package/scripts/music/gen/nalati-score-build.json +119 -0
  220. package/scripts/music/gen/nalati-score.json +3448 -0
  221. package/scripts/music/gen/ob7-fit-decisions.json +38 -0
  222. package/scripts/music/gen/ob7-score-jobs.json +152 -0
  223. package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
  224. package/scripts/music/gen/ob7_build.py +469 -0
  225. package/scripts/music/gen/ob7_generate.py +67 -0
  226. package/scripts/music/gen/ob7_run.sh +42 -0
  227. package/scripts/music/gen/orchestral.json +3187 -0
  228. package/scripts/music/gen/own_score.py +486 -0
  229. package/scripts/music/gen/ph-jobs.json +27 -0
  230. package/scripts/music/gen/ph_page.py +222 -0
  231. package/scripts/music/gen/piano.json +3175 -0
  232. package/scripts/music/gen/rank_v3.py +248 -0
  233. package/scripts/music/gen/sfx-best.json +2486 -0
  234. package/scripts/music/gen/sfx-ezaudio.json +4082 -0
  235. package/scripts/music/gen/sfx-jobs.json +57 -0
  236. package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
  237. package/scripts/music/gen/sfx-minimax.json +289 -0
  238. package/scripts/music/gen/sfx-moss.json +4082 -0
  239. package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
  240. package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
  241. package/scripts/music/gen/sfx-nalati.json +11202 -0
  242. package/scripts/music/gen/sfx-nd-jobs.json +57 -0
  243. package/scripts/music/gen/sfx-nd-moss.json +2097 -0
  244. package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
  245. package/scripts/music/gen/sfx-nd-summary.json +38 -0
  246. package/scripts/music/gen/sfx-peaks.json +7 -0
  247. package/scripts/music/gen/sfx-ph-jobs.json +169 -0
  248. package/scripts/music/gen/sfx-ph-moss.json +6564 -0
  249. package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
  250. package/scripts/music/gen/sfx-ph-summary.json +63 -0
  251. package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
  252. package/scripts/music/gen/sfx-sa3.json +4082 -0
  253. package/scripts/music/gen/sfx-summary.json +107 -0
  254. package/scripts/music/gen/sfx_build.py +332 -0
  255. package/scripts/music/gen/sfx_merge.py +255 -0
  256. package/scripts/music/gen/sfx_minimax.py +61 -0
  257. package/scripts/music/gen/sfx_nalati.py +331 -0
  258. package/scripts/music/gen/sfx_sprite.py +424 -0
  259. package/scripts/music/gen/stems.py +539 -0
  260. package/scripts/music/gen/test_loop_meter.py +29 -0
  261. package/scripts/music/gen/test_ob7_provenance.py +77 -0
  262. package/scripts/music/gen/v3-folk-build.json +148 -0
  263. package/scripts/music/gen/v3-folk.json +1818 -0
  264. package/scripts/music/gen/v3-jobs.json +145 -0
  265. package/scripts/music/gen/v3-orchestral-build.json +148 -0
  266. package/scripts/music/gen/v3-orchestral.json +1813 -0
  267. package/scripts/music/gen/v3-ph-folk-build.json +94 -0
  268. package/scripts/music/gen/v3-ph-folk.json +1806 -0
  269. package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
  270. package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
  271. package/scripts/music/gen/v3-ph-piano-build.json +94 -0
  272. package/scripts/music/gen/v3-ph-piano.json +1818 -0
  273. package/scripts/music/gen/v3-piano-build.json +148 -0
  274. package/scripts/music/gen/v3-piano.json +1813 -0
  275. package/scripts/music/wildshard-theme.mid +0 -0
  276. package/scripts/music/wildshard-trailer30.mid +0 -0
  277. package/scripts/named-blob-output.d.mts +8 -0
  278. package/scripts/named-blob-output.mjs +48 -0
  279. package/scripts/pack-all.mjs +15 -0
  280. package/scripts/pid-lock.d.mts +1 -0
  281. package/scripts/pid-lock.mjs +63 -0
  282. package/scripts/practice/bake_dummy.py +53 -0
  283. package/scripts/practice/build_dummies.sh +43 -0
  284. package/scripts/practice/dummy_parts.py +568 -0
  285. package/scripts/practice/dummy_rig_gate.py +139 -0
  286. package/scripts/practice/gate_sheet.py +36 -0
  287. package/scripts/practice/generate_dummy_unimate.py +132 -0
  288. package/scripts/practice/pack_dummy.mjs +59 -0
  289. package/scripts/practice/repair_dummy_weights.mjs +68 -0
  290. package/scripts/practice/rig_dummy.py +828 -0
  291. package/scripts/practice/verify_unimate_skin.mjs +356 -0
  292. package/scripts/preparation-seed.mjs +15 -0
  293. package/scripts/prepare-basis-tool.mjs +6 -0
  294. package/scripts/prepare-product.d.mts +14 -0
  295. package/scripts/prepare-product.mjs +101 -0
  296. package/scripts/product-build-tools.d.mts +3 -0
  297. package/scripts/product-build-tools.json +3 -0
  298. package/scripts/product-build-tools.mjs +31 -0
  299. package/scripts/publish-public.mjs +7 -0
  300. package/scripts/push-tables.d.mts +1 -0
  301. package/scripts/push-tables.mjs +28 -0
  302. package/scripts/record-shard-mounts.mjs +133 -0
  303. package/scripts/sdk-externals.d.mts +2 -0
  304. package/scripts/sdk-externals.mjs +2 -0
  305. package/scripts/section-inventory.ts +209 -0
  306. package/scripts/select-candidate.mjs +15 -0
  307. package/scripts/shard-build-pool.d.mts +4 -0
  308. package/scripts/shard-build-pool.mjs +53 -0
  309. package/scripts/shard-line-baseline.json +17 -0
  310. package/scripts/shard-milestones.d.mts +15 -0
  311. package/scripts/shard-milestones.mjs +105 -0
  312. package/scripts/shard-output-report.d.mts +9 -0
  313. package/scripts/shard-output-report.mjs +85 -0
  314. package/scripts/shard-platform-cli.mjs +93 -0
  315. package/scripts/shard-progress.mjs +212 -0
  316. package/scripts/shard-timelapse.py +102 -0
  317. package/scripts/shardfile-cold-boot.mjs +79 -0
  318. package/scripts/shardfile-vite.d.mts +4 -0
  319. package/scripts/shardfile-vite.mjs +20 -0
  320. package/scripts/simplify-models.mjs +24 -0
  321. package/scripts/site-facts.mjs +88 -0
  322. package/scripts/test-template-gate.mjs +44 -0
  323. package/scripts/test_golden_compare.py +68 -0
  324. package/scripts/tex-tiers.cache.json +181 -0
  325. package/scripts/tex-tiers.mjs +240 -0
  326. package/scripts/texmem-probe.mjs +184 -0
  327. package/scripts/unused-assets.mjs +173 -0
  328. package/scripts/vite-tmp.d.mts +23 -0
  329. package/scripts/vite-tmp.mjs +157 -0
  330. package/scripts/wave-line-baselines.json +32 -0
  331. package/scripts/wildshard.d.mts +4 -0
  332. package/scripts/wildshard.mjs +105 -0
  333. package/scripts/witness-checkpoints.d.mts +10 -0
  334. package/scripts/witness-checkpoints.mjs +84 -0
  335. package/scripts/witness-generation.d.mts +10 -0
  336. package/scripts/witness-generation.mjs +45 -0
  337. package/scripts/witness-manifests.d.mts +8 -0
  338. package/scripts/witness-manifests.mjs +157 -0
  339. package/scripts/worktree-ignore.d.mts +4 -0
  340. package/scripts/worktree-ignore.mjs +36 -0
  341. package/scripts/worktree-reap.mjs +214 -0
  342. package/scripts/worktree.mjs +396 -0
  343. package/scripts/worldclaw/capture-front.sh +28 -0
  344. package/scripts/worldclaw/design-template.md +62 -0
  345. package/scripts/worldclaw/spec-map.py +92 -0
  346. package/scripts/worldclaw/spec.ts +96 -0
  347. package/skills/wildshard/SKILL.md +50 -0
  348. package/skills/wildshard-goldens/SKILL.md +54 -0
  349. package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
  350. package/skills/wildshard-upgrade/SKILL.md +47 -0
  351. package/src/.oxfmtrc.json +50 -0
  352. package/src/.oxlintrc.json +173 -0
  353. package/src/cli/account/account.ts +199 -0
  354. package/src/cli/account/command.ts +193 -0
  355. package/src/cli/account/key.ts +154 -0
  356. package/src/cli/args.ts +97 -0
  357. package/src/cli/audio/audio.ts +39 -0
  358. package/src/cli/bin.mjs +8 -0
  359. package/src/cli/delete/delete.ts +258 -0
  360. package/src/cli/help.ts +204 -0
  361. package/src/cli/hero/adopt.ts +103 -0
  362. package/src/cli/hero/hero.ts +112 -0
  363. package/src/cli/hero/stamp.ts +298 -0
  364. package/src/cli/main.ts +291 -0
  365. package/src/cli/report.ts +20 -0
  366. package/src/cli/shardfile/command.ts +49 -0
  367. package/src/cli/shardfile/shardfile.ts +192 -0
  368. package/src/cli/upload/api.ts +246 -0
  369. package/src/cli/upload/compress.ts +55 -0
  370. package/src/cli/upload/hero.ts +62 -0
  371. package/src/cli/upload/placement.ts +115 -0
  372. package/src/cli/upload/provenance.ts +192 -0
  373. package/src/cli/upload/signature.ts +30 -0
  374. package/src/cli/upload/upload.ts +269 -0
  375. package/src/cli/upload/validate.ts +74 -0
  376. package/src/cli/upload/wire.ts +147 -0
  377. package/src/cli/version.ts +63 -0
  378. package/src/commons/bake/portableMath.ts +187 -0
  379. package/src/commons/catalogue.ts +10 -0
  380. package/src/commons/courseProgram.ts +32 -0
  381. package/src/commons/practiceCourse.ts +16 -0
  382. package/src/commons/scripts/abi.as +14 -0
  383. package/src/commons/scripts/bridge.as +14 -0
  384. package/src/commons/scripts/course.as +63 -0
  385. package/src/scripts/ask-new.sh +29 -0
  386. package/src/scripts/asks.mjs +141 -0
  387. package/src/scripts/herdr-prompt.sh +34 -0
  388. package/src/scripts/herdr-question-open.sh +67 -0
  389. package/src/scripts/md-wrap.mjs +229 -0
  390. package/src/server/app.ts +19 -0
  391. package/src/server/serve.ts +49 -0
  392. package/src/sharddev/admission.ts +7 -0
  393. package/src/sharddev/agentFiles.ts +127 -0
  394. package/src/sharddev/arenaView.ts +15 -0
  395. package/src/sharddev/as/groupBankV2.ts +36 -0
  396. package/src/sharddev/as/groupStepV2.ts +13 -0
  397. package/src/sharddev/as/ws.ts +30 -0
  398. package/src/sharddev/as/wsV2.ts +180 -0
  399. package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
  400. package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
  401. package/src/sharddev/assetHandle.ts +84 -0
  402. package/src/sharddev/assetOwner.ts +70 -0
  403. package/src/sharddev/assetScope.ts +30 -0
  404. package/src/sharddev/assets.ts +21 -0
  405. package/src/sharddev/audio.ts +9 -0
  406. package/src/sharddev/audioEncode.ts +211 -0
  407. package/src/sharddev/author.ts +3 -0
  408. package/src/sharddev/authorError.ts +28 -0
  409. package/src/sharddev/authorManifest.ts +39 -0
  410. package/src/sharddev/bake/annulus.ts +19 -0
  411. package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
  412. package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
  413. package/src/sharddev/bake/authoredWorld.ts +201 -0
  414. package/src/sharddev/bake/basisEncoder.ts +95 -0
  415. package/src/sharddev/bake/basisGlb.ts +85 -0
  416. package/src/sharddev/bake/basisTool.ts +74 -0
  417. package/src/sharddev/bake/basisToolInputs.ts +476 -0
  418. package/src/sharddev/bake/byteCodec.ts +33 -0
  419. package/src/sharddev/bake/canvasAtlas.ts +406 -0
  420. package/src/sharddev/bake/coarseCopy.ts +59 -0
  421. package/src/sharddev/bake/colliders.ts +87 -0
  422. package/src/sharddev/bake/compactGlb.ts +224 -0
  423. package/src/sharddev/bake/compileScript.ts +119 -0
  424. package/src/sharddev/bake/compileScriptV2.ts +75 -0
  425. package/src/sharddev/bake/contactRows.ts +84 -0
  426. package/src/sharddev/bake/creaturePlacement.ts +117 -0
  427. package/src/sharddev/bake/export.ts +67 -0
  428. package/src/sharddev/bake/facetedGeometry.ts +379 -0
  429. package/src/sharddev/bake/farImpostor.ts +120 -0
  430. package/src/sharddev/bake/forest.ts +100 -0
  431. package/src/sharddev/bake/format-hook.mjs +2 -0
  432. package/src/sharddev/bake/generatorGlb.ts +23 -0
  433. package/src/sharddev/bake/geometryBounds.ts +77 -0
  434. package/src/sharddev/bake/geometryError.ts +48 -0
  435. package/src/sharddev/bake/glb.ts +355 -0
  436. package/src/sharddev/bake/glbCompression.ts +143 -0
  437. package/src/sharddev/bake/gltfSource.ts +59 -0
  438. package/src/sharddev/bake/groundMap.ts +142 -0
  439. package/src/sharddev/bake/image.ts +20 -0
  440. package/src/sharddev/bake/isleMap.ts +64 -0
  441. package/src/sharddev/bake/json.mjs +84 -0
  442. package/src/sharddev/bake/keyedSky.ts +47 -0
  443. package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
  444. package/src/sharddev/bake/kinds.ts +137 -0
  445. package/src/sharddev/bake/lightSources.ts +31 -0
  446. package/src/sharddev/bake/mapAssembly.ts +84 -0
  447. package/src/sharddev/bake/mapRaster.ts +173 -0
  448. package/src/sharddev/bake/mapRest.ts +57 -0
  449. package/src/sharddev/bake/mapScenes.ts +234 -0
  450. package/src/sharddev/bake/materialGraph.ts +32 -0
  451. package/src/sharddev/bake/meadow.ts +27 -0
  452. package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
  453. package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
  454. package/src/sharddev/bake/nativeLattice.ts +178 -0
  455. package/src/sharddev/bake/nativeRaster.ts +106 -0
  456. package/src/sharddev/bake/nativeTerrainField.ts +11 -0
  457. package/src/sharddev/bake/navigation-json.mjs +38 -0
  458. package/src/sharddev/bake/navigation.ts +113 -0
  459. package/src/sharddev/bake/navigationAsset.ts +18 -0
  460. package/src/sharddev/bake/nearPlaceholder.ts +206 -0
  461. package/src/sharddev/bake/normalizeRig.ts +80 -0
  462. package/src/sharddev/bake/phoneAstc.ts +93 -0
  463. package/src/sharddev/bake/placeholders.ts +581 -0
  464. package/src/sharddev/bake/placement.ts +80 -0
  465. package/src/sharddev/bake/portableBytes.ts +18 -0
  466. package/src/sharddev/bake/portableBytesMemo.ts +50 -0
  467. package/src/sharddev/bake/practiceCourse.ts +49 -0
  468. package/src/sharddev/bake/primitives.ts +96 -0
  469. package/src/sharddev/bake/props.ts +443 -0
  470. package/src/sharddev/bake/questPlacement.ts +98 -0
  471. package/src/sharddev/bake/rawTexture.ts +26 -0
  472. package/src/sharddev/bake/riderArms.ts +97 -0
  473. package/src/sharddev/bake/rig.ts +95 -0
  474. package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
  475. package/src/sharddev/bake/signPlacements.ts +25 -0
  476. package/src/sharddev/bake/simplifier.ts +52 -0
  477. package/src/sharddev/bake/skinned.ts +312 -0
  478. package/src/sharddev/bake/slabChunks.ts +149 -0
  479. package/src/sharddev/bake/slabs.ts +263 -0
  480. package/src/sharddev/bake/source-loader.mjs +55 -0
  481. package/src/sharddev/bake/sourceMetadata.ts +54 -0
  482. package/src/sharddev/bake/species.ts +368 -0
  483. package/src/sharddev/bake/specimenCatalogue.ts +47 -0
  484. package/src/sharddev/bake/splatGround.ts +141 -0
  485. package/src/sharddev/bake/staticMaterials.ts +171 -0
  486. package/src/sharddev/bake/terrain.ts +195 -0
  487. package/src/sharddev/bake/texture.ts +33 -0
  488. package/src/sharddev/bake/textureWasm.ts +81 -0
  489. package/src/sharddev/bake/tileEncoder.ts +11 -0
  490. package/src/sharddev/bake/tileGrid.ts +62 -0
  491. package/src/sharddev/bake/v2Finite.ts +160 -0
  492. package/src/sharddev/bake/v2Fuel.ts +71 -0
  493. package/src/sharddev/bake/wholePartition.ts +74 -0
  494. package/src/sharddev/bake/wholePieceJoin.ts +147 -0
  495. package/src/sharddev/bake/world.ts +173 -0
  496. package/src/sharddev/bake/worldCollision.ts +128 -0
  497. package/src/sharddev/bake/worldGeometry.ts +237 -0
  498. package/src/sharddev/bake/worldGlb.ts +123 -0
  499. package/src/sharddev/bake/worldImage.ts +12 -0
  500. package/src/sharddev/bake/worldLod.ts +128 -0
  501. package/src/sharddev/bake/worldRows.ts +102 -0
  502. package/src/sharddev/bake/worldTextureMemo.ts +63 -0
  503. package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
  504. package/src/sharddev/bake.ts +193 -0
  505. package/src/sharddev/bakePublication.ts +31 -0
  506. package/src/sharddev/behaviourSource.ts +94 -0
  507. package/src/sharddev/bin/wildshard.mjs +7 -0
  508. package/src/sharddev/blobBytes.ts +65 -0
  509. package/src/sharddev/blobs.ts +138 -0
  510. package/src/sharddev/bootInventory.ts +129 -0
  511. package/src/sharddev/bossProfiles.ts +18 -0
  512. package/src/sharddev/buildBehaviour.ts +77 -0
  513. package/src/sharddev/buildCacheMetrics.ts +17 -0
  514. package/src/sharddev/buildDecisionScripts.ts +122 -0
  515. package/src/sharddev/check.ts +118 -0
  516. package/src/sharddev/checkProject.ts +127 -0
  517. package/src/sharddev/cli.ts +200 -0
  518. package/src/sharddev/clientChannels.ts +169 -0
  519. package/src/sharddev/clientScripts.ts +10 -0
  520. package/src/sharddev/commons.ts +77 -0
  521. package/src/sharddev/commonsCosts.ts +11 -0
  522. package/src/sharddev/compileMovers.ts +11 -0
  523. package/src/sharddev/configBoundary.ts +6 -0
  524. package/src/sharddev/cookInput.ts +40 -0
  525. package/src/sharddev/crowds.ts +6 -0
  526. package/src/sharddev/decisionBindingMap.ts +11 -0
  527. package/src/sharddev/decisionScriptBindings.ts +117 -0
  528. package/src/sharddev/decisionScripts.ts +28 -0
  529. package/src/sharddev/decisionSource.ts +51 -0
  530. package/src/sharddev/dev.ts +113 -0
  531. package/src/sharddev/director.ts +26 -0
  532. package/src/sharddev/directorAbi.ts +77 -0
  533. package/src/sharddev/discoveryDocument.ts +97 -0
  534. package/src/sharddev/draft.ts +11 -0
  535. package/src/sharddev/eliteEntryRows.ts +29 -0
  536. package/src/sharddev/entries.ts +76 -0
  537. package/src/sharddev/entryReads.ts +73 -0
  538. package/src/sharddev/executeBundle.ts +55 -0
  539. package/src/sharddev/finds.ts +5 -0
  540. package/src/sharddev/formatJsonSchema.ts +3 -0
  541. package/src/sharddev/generationCache.ts +257 -0
  542. package/src/sharddev/generationRecipe.ts +94 -0
  543. package/src/sharddev/handwritten.ts +110 -0
  544. package/src/sharddev/immutable.ts +14 -0
  545. package/src/sharddev/interactions.ts +38 -0
  546. package/src/sharddev/kit/bakedGeometry.ts +16 -0
  547. package/src/sharddev/kit/geometryPack.ts +110 -0
  548. package/src/sharddev/ledger.ts +13 -0
  549. package/src/sharddev/looks/tileField.ts +67 -0
  550. package/src/sharddev/materialGraphFiles.ts +57 -0
  551. package/src/sharddev/materials.ts +574 -0
  552. package/src/sharddev/measure.ts +18 -0
  553. package/src/sharddev/modes.ts +115 -0
  554. package/src/sharddev/moverPrograms.ts +213 -0
  555. package/src/sharddev/movers.ts +75 -0
  556. package/src/sharddev/nativePopulationRows.ts +46 -0
  557. package/src/sharddev/newProject.ts +226 -0
  558. package/src/sharddev/noise.ts +54 -0
  559. package/src/sharddev/outputProduct.ts +188 -0
  560. package/src/sharddev/outputRuntime.ts +66 -0
  561. package/src/sharddev/performancePolicy.ts +29 -0
  562. package/src/sharddev/phasedBoss.ts +34 -0
  563. package/src/sharddev/physics.ts +194 -0
  564. package/src/sharddev/platformSections.ts +42 -0
  565. package/src/sharddev/plumbing.ts +8 -0
  566. package/src/sharddev/productOutput.ts +128 -0
  567. package/src/sharddev/project.ts +337 -0
  568. package/src/sharddev/projectCompilerIdentity.ts +94 -0
  569. package/src/sharddev/projectDecisions.ts +66 -0
  570. package/src/sharddev/projectEntryProof.ts +32 -0
  571. package/src/sharddev/projectGeneration.ts +219 -0
  572. package/src/sharddev/projectInputFiles.ts +47 -0
  573. package/src/sharddev/projectManifest.ts +108 -0
  574. package/src/sharddev/projectMap.ts +35 -0
  575. package/src/sharddev/projectOutput.ts +242 -0
  576. package/src/sharddev/projectPolicy.ts +17 -0
  577. package/src/sharddev/projectSections.ts +27 -0
  578. package/src/sharddev/questGraph.ts +25 -0
  579. package/src/sharddev/quests.ts +65 -0
  580. package/src/sharddev/random.ts +61 -0
  581. package/src/sharddev/refusals.ts +304 -0
  582. package/src/sharddev/reportCard.ts +13 -0
  583. package/src/sharddev/returnProjectionV2.ts +81 -0
  584. package/src/sharddev/rows.ts +192 -0
  585. package/src/sharddev/runtimeImports.ts +38 -0
  586. package/src/sharddev/runtimeMirrors.ts +39 -0
  587. package/src/sharddev/runtimePerformance.ts +38 -0
  588. package/src/sharddev/scene.ts +321 -0
  589. package/src/sharddev/sceneAnimation.ts +54 -0
  590. package/src/sharddev/sceneAudio.ts +64 -0
  591. package/src/sharddev/sceneDeclarations.ts +100 -0
  592. package/src/sharddev/sceneGraph.ts +139 -0
  593. package/src/sharddev/sceneTransform.ts +12 -0
  594. package/src/sharddev/schemaValidation.ts +61 -0
  595. package/src/sharddev/sections.ts +47 -0
  596. package/src/sharddev/shardSource.ts +59 -0
  597. package/src/sharddev/sourceReader.ts +26 -0
  598. package/src/sharddev/spawns.ts +38 -0
  599. package/src/sharddev/species/clips.ts +24 -0
  600. package/src/sharddev/species.ts +29 -0
  601. package/src/sharddev/speciesBrains.ts +19 -0
  602. package/src/sharddev/synth.ts +66 -0
  603. package/src/sharddev/test/compileDualScriptV2.ts +71 -0
  604. package/src/sharddev/test/compileSimV2.ts +21 -0
  605. package/src/sharddev/test/diskScriptScenario.ts +86 -0
  606. package/src/sharddev/test/scriptScenario.ts +249 -0
  607. package/src/sharddev/test/scriptSource.ts +12 -0
  608. package/src/sharddev/version.ts +4 -0
  609. package/src/sharddev/weapons/bowProfile.ts +20 -0
  610. package/src/sharddev/weapons/firearmRows.ts +11 -0
  611. package/src/sharddev/weapons/meleeProfile.ts +71 -0
  612. package/src/sharddev/weapons/thrownProfile.ts +10 -0
  613. package/src/sharddev/worldScenes.ts +308 -0
  614. package/src/sharddev/worldSource.ts +82 -0
  615. package/src/shards/_template/README.md +78 -0
  616. package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
  617. package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
  618. package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
  619. package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
  620. package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
  621. package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
  622. package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
  623. package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
  624. package/src/shards/_template/behaviour/boss.as +39 -0
  625. package/src/shards/_template/behaviour/door.as +32 -0
  626. package/src/shards/_template/behaviour/hooks.json +129 -0
  627. package/src/shards/_template/behaviour/idle.as +75 -0
  628. package/src/shards/_template/behaviour/items.as +22 -0
  629. package/src/shards/_template/card/landscape.jpg +0 -0
  630. package/src/shards/_template/card/portrait.jpg +0 -0
  631. package/src/shards/_template/card/thumb.jpg +0 -0
  632. package/src/shards/_template/data/audio.json +45 -0
  633. package/src/shards/_template/data/bossDecision.json +83 -0
  634. package/src/shards/_template/data/budgets.json +70 -0
  635. package/src/shards/_template/data/card.json +281 -0
  636. package/src/shards/_template/data/clientScripts.json +987 -0
  637. package/src/shards/_template/data/creatures.json +65 -0
  638. package/src/shards/_template/data/director.json +39 -0
  639. package/src/shards/_template/data/encounters.json +96 -0
  640. package/src/shards/_template/data/items.json +172 -0
  641. package/src/shards/_template/data/layout.json +66 -0
  642. package/src/shards/_template/data/ledger.json +32 -0
  643. package/src/shards/_template/data/look.json +521 -0
  644. package/src/shards/_template/data/map.json +64 -0
  645. package/src/shards/_template/data/moves.json +16 -0
  646. package/src/shards/_template/data/placeholder.json +8 -0
  647. package/src/shards/_template/data/plumbing.json +32 -0
  648. package/src/shards/_template/data/quests.json +223 -0
  649. package/src/shards/_template/data/rows.json +423 -0
  650. package/src/shards/_template/data/skins.json +66 -0
  651. package/src/shards/_template/data/spawn.json +6 -0
  652. package/src/shards/_template/data/targets.json +150 -0
  653. package/src/shards/_template/data/text.json +12 -0
  654. package/src/shards/_template/data/ui.json +33 -0
  655. package/src/shards/_template/data/water.json +13 -0
  656. package/src/shards/_template/generators/behaviour.ts +34 -0
  657. package/src/shards/_template/generators/boss.ts +29 -0
  658. package/src/shards/_template/generators/buildOptions.ts +2 -0
  659. package/src/shards/_template/generators/cell.ts +224 -0
  660. package/src/shards/_template/generators/districts.ts +215 -0
  661. package/src/shards/_template/generators/farLook.ts +15 -0
  662. package/src/shards/_template/generators/generate.ts +27 -0
  663. package/src/shards/_template/generators/ground.ts +15 -0
  664. package/src/shards/_template/generators/kit.ts +69 -0
  665. package/src/shards/_template/generators/landscape.ts +59 -0
  666. package/src/shards/_template/generators/landscapeNoise.ts +62 -0
  667. package/src/shards/_template/generators/mapInputs.ts +10 -0
  668. package/src/shards/_template/generators/product.ts +100 -0
  669. package/src/shards/_template/generators/productOutput.ts +18 -0
  670. package/src/shards/_template/generators/props.ts +9 -0
  671. package/src/shards/_template/generators/templatePropsSource.ts +58 -0
  672. package/src/shards/_template/generators/terrain.ts +17 -0
  673. package/src/shards/_template/generators/world.ts +630 -0
  674. package/src/shards/_template/hero.json +10 -0
  675. package/src/shards/_template/look/entry-reads.json +20 -0
  676. package/src/shards/_template/manifest.json +281 -0
  677. package/src/shards/_template/shard.config.ts +10 -0
  678. package/src/shared/health.ts +10 -0
  679. package/src/tools/build-web.ts +59 -0
  680. package/src/tsconfig.json +30 -0
  681. package/src/web/app.tsx +53 -0
  682. package/src/web/index.html +12 -0
  683. package/src/web/main.tsx +10 -0
  684. package/src/web/tsconfig.json +13 -0
  685. package/tsconfig.author.json +23 -0
  686. package/tsconfig.commons.json +21 -0
  687. package/tsconfig.json +47 -0
  688. package/tsconfig.sharddev.json +20 -0
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+ // bake-packs.mjs — one boot pack per shard × tier (project/archive/2026-09-22-load-perf.md, "requests, first launch ≤ 20").
3
+ //
4
+ // A shard's boot reads 4–80 files (texture sets, glTF triplets, LODs, baked terrain / sky / cards). Each is a
5
+ // request: cheap over HTTP/2 on Wi-Fi, but ~80 of them are the whole "requests" budget four times over, and each
6
+ // one pays the service worker's per-request cost on the phone. The pack is those same files — exactly the list
7
+ // `bootFetches(def, chunkFiles(def))` returns for that tier, the bytes the boot would have fetched one by one —
8
+ // concatenated in step order into one file the boot streams (src/client/engine/boot/pack.ts): each file is handed to its step
9
+ // the moment its last byte lands, so download ∥ build overlaps as it did with the per-file prefetch, in one request.
10
+ //
11
+ // public/assets/packs/<slug>.<tier>-<hash8>.bin content-addressed (a changed file makes a new name), cache-first
12
+ // in the SW; gitignored and left out of the byte table — every
13
+ // build regenerates it from the committed files
14
+ // src/client/game/boot/packs.generated.ts slug → tier → { parts: { url, bytes, files: [path, offset, size, type][] }[] }
15
+ //
16
+ // PARTS (E160, the user: "don't invalidate those as much"): one pack per shard meant any edit to any of its files named a
17
+ // new pack — Pine Hollow's phone players re-downloaded 18 MB for one repainted texture. A pack is now a few parts, each
18
+ // content-addressed on its own, so an edit costs its part. The cuts depend on the files' paths, not their bytes, so an
19
+ // edit does not move them: once a part holds PART_MIN it ends after a file whose path hashes to 0 mod 4 (or at PART_MAX
20
+ // whatever the path), never between a glTF's textures and the .gltf that follows them (Safari reads those textures
21
+ // through <img>: they must land first). A resized file can move at most the cut after it; the next hash cut re-aligns.
22
+ // Pine Hollow's 18 MB phone boot is ~8 parts; the requests row (bench.budget.json) has the room.
23
+ // KTX2 runs instead use bounded directory/slot cohorts (boot-pack-parts.mjs): tiled entry only asks for a
24
+ // demanded texture set, so mixing an unrelated set into its part would defeat the demand-only pack reader.
25
+ //
26
+ // glTF textures go before their .gltf: Safari's GLTFLoader loads textures through <img>, which the pack's fetch
27
+ // interception cannot see — src/client/engine/boot/pack.ts hands those loaders a blob: URL instead, which only works when the
28
+ // texture has already landed by the time the .gltf asks for it.
29
+ //
30
+ // Run after the byte table is written (vite.config.ts): the tier's file names come from src/client/game/boot/bytes.generated.ts.
31
+ // node --import ./scripts/bake-loader.mjs scripts/bake-packs.mjs [--check]
32
+ import { createHash } from 'node:crypto';
33
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync } from 'node:fs';
34
+ import { dirname, resolve } from 'node:path';
35
+ import { pathToFileURL } from 'node:url';
36
+ import { assetIndex, assetVersionRows } from '@wildshard/engine/scripts/app-build/gen.ts';
37
+ import { parseBootPublication, publishedBootTableSources, publishBootPublication, readBootPublication } from '@wildshard/engine/scripts/boot-publication.mjs';
38
+ import { bootPackParts } from '@wildshard/engine/scripts/boot-pack-parts.mjs';
39
+ import { lateAudioGroups } from '@wildshard/engine/scripts/app-build/audioPacks.ts';
40
+
41
+ const ROOT = resolve(import.meta.dirname, '..');
42
+ const PUBLIC = resolve(ROOT, 'public');
43
+ const PACK_DIR = resolve(PUBLIC, 'assets/packs');
44
+ const OUT_TS = resolve(ROOT, 'src/client/game/boot/packs.generated.ts');
45
+ const CHECK = process.argv.includes('--check');
46
+ const TIERS = ['phone', 'desktop'];
47
+
48
+ // the modules read the tier / chunk from the page's URL at import time: stand in for a phone page (Node has `navigator`)
49
+ const { initializeTier } = await import('@wildshard/engine/core/tier');
50
+ initializeTier('phone');
51
+
52
+ const imp = (p) => import(pathToFileURL(resolve(ROOT, p)).href);
53
+ const { SHARDS } = await imp('src/shards.generated.ts');
54
+ const { playable } = await imp('src/client/game/shard/registry.ts');
55
+ const PLAYABLE_SHARDS = SHARDS.filter(playable);
56
+ const { prepareShardAssets } = await imp('src/client/game/shard/load.ts');
57
+ const { imagesFirstPlayingBytes } = await imp('src/client/game/grid/runtimeCost.ts');
58
+ const { registerGpuFiles, autoTexturePolicy } = await imp('src/client/engine/boot/gpuFiles.ts');
59
+ await Promise.all(SHARDS.map((m) => prepareShardAssets(m, registerGpuFiles)));
60
+ const { chunkFiles } = await imp('src/client/engine/boot/manifest.ts');
61
+ const { bootFetches } = await imp('src/client/engine/boot/prefetch.ts');
62
+
63
+ const TYPES = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp', glb: 'model/gltf-binary', gltf: 'model/gltf+json', bin: 'application/octet-stream', json: 'application/json', m4a: 'audio/mp4', wav: 'audio/wav' };
64
+ const typeOf = (p) => TYPES[/\.(\w+)$/.exec(p)?.[1] ?? ''] ?? 'application/octet-stream';
65
+
66
+ /** glTF textures ahead of their .gltf, everything else in the boot's own order */
67
+ function packOrder(paths) {
68
+ const out = [];
69
+ const placed = new Set();
70
+ for (const p of paths) {
71
+ if (placed.has(p)) continue;
72
+ const m = /^(\/assets\/models\/[^/]+\/)[^/]+\.gltf$/.exec(p);
73
+ if (m) for (const q of paths) if (!placed.has(q) && q.startsWith(`${m[1]}textures/`)) { out.push(q); placed.add(q); }
74
+ out.push(p); placed.add(p);
75
+ }
76
+ return out;
77
+ }
78
+
79
+ if (!CHECK) mkdirSync(PACK_DIR, { recursive: true });
80
+ const packs = {};
81
+ const keep = new Set();
82
+ /** @param {string} slug @param {string} tierName @param {readonly string[]} paths */
83
+ function writeParts(slug, tierName, paths) {
84
+ return bootPackParts(paths, path => readFileSync(resolve(PUBLIC, `.${path}`)).length).map(group => {
85
+ const bodies = group.map(path => readFileSync(resolve(PUBLIC, `.${path}`)));
86
+ const blob = Buffer.concat(bodies);
87
+ const name = `${slug}.${tierName}-${createHash('sha256').update(blob).digest('hex').slice(0, 8)}.bin`;
88
+ keep.add(name);
89
+ let offset = 0;
90
+ const files = group.map((path, index) => {
91
+ const bytes = bodies[index].length, row = [path, offset, bytes, typeOf(path)]; offset += bytes; return row;
92
+ });
93
+ const out = resolve(PACK_DIR, name);
94
+ if (!CHECK && !existsSync(out)) writeFileSync(out, blob);
95
+ return { url: `/assets/packs/${name}`, bytes: blob.length, files };
96
+ });
97
+ }
98
+ for (const def of PLAYABLE_SHARDS) {
99
+ for (const tierName of TIERS) {
100
+ if (tierName === 'desktop' && def.load === undefined) continue; // unmigrated shards keep their existing phone-only packs
101
+ await initializeTier(tierName);
102
+ const files = chunkFiles(def, autoTexturePolicy(def.tiers?.[tierName]?.textures, imagesFirstPlayingBytes(def.runtimeCost))?.mode ?? 'img');
103
+ const paths = packOrder(bootFetches(def, files));
104
+ if (paths.length < 2) continue;
105
+ for (const p of paths) if (!existsSync(resolve(PUBLIC, `.${p}`))) throw new Error(`bake-packs: ${def.slug} boots ${p} but public has no such file`);
106
+ const parts = writeParts(def.slug, tierName, paths);
107
+ packs[def.slug] = { ...packs[def.slug], [tierName]: { parts } };
108
+ const total = parts.reduce((s, x) => s + x.bytes, 0);
109
+ console.log(`[pack] ${def.slug}.${tierName}: ${paths.length} files, ${(total / 1e6).toFixed(2)} MB in ${parts.length} parts (${parts.map((x) => (x.bytes / 1e6).toFixed(1)).join(' + ')} MB)`);
110
+ }
111
+ for (const [name, paths] of Object.entries(await lateAudioGroups(ROOT, def.slug))) {
112
+ packs[name] = { phone: { parts: writeParts(name, 'phone', paths) } };
113
+ }
114
+ }
115
+
116
+ const publication = parseBootPublication({ schema: 'boot-publication/1',
117
+ bytes: Object.fromEntries(Object.entries(JSON.parse(assetIndex())).filter(([name]) => !name.endsWith('.DS_Store'))),
118
+ versions: assetVersionRows(), packs });
119
+ const ts = publishedBootTableSources(publication)['src/client/game/boot/packs.generated.ts'];
120
+ const prev = existsSync(OUT_TS) ? readFileSync(OUT_TS, 'utf8') : '';
121
+ if (CHECK) {
122
+ if (JSON.stringify(readBootPublication(ROOT)) !== JSON.stringify(publication)) throw new Error('bake-packs: boot publication facts are stale');
123
+ if (prev !== ts) { console.error('[pack] src/client/game/boot/packs.generated.ts is stale — run the build'); process.exit(1); }
124
+ } else {
125
+ if (prev !== ts) { mkdirSync(dirname(OUT_TS), { recursive: true }); writeFileSync(OUT_TS, ts); }
126
+ for (const f of readdirSync(PACK_DIR)) if (!keep.has(f)) unlinkSync(resolve(PACK_DIR, f)); // a changed file made a new hash
127
+ }
128
+
129
+ if (!CHECK) publishBootPublication(ROOT, publication);
@@ -0,0 +1,102 @@
1
+ // node --experimental-transform-types --import ./scripts/bake-loader.mjs scripts/bake-pickups.mjs [--check]
2
+ // GR9 / GR10 (a) (G798): a plain script, run by hand when pickups change; its outputs (src/client/game/data/pickupCatalogue.json
3
+ // and public/assets/baked/common/pickups/*.bin) are committed files, not catalogue outputs. --check verifies them.
4
+ import { createHash } from 'node:crypto';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { zlibSync, unzlibSync } from 'fflate';
7
+ import { authoredPickups } from '@wildshard/engine/game/generators/pickups';
8
+ import { byteWriter, jsonBytes } from '@wildshard/engine/scripts/bake-output.mjs';
9
+ import { installKitProps } from '@wildshard/engine/game/models/interact';
10
+ import { Interactables, Live } from '@wildshard/engine/world/interact/Interactables';
11
+ import { pickupLook, registerPickupLook } from '@wildshard/engine/world/interact/types';
12
+ import { readBakedGeometry } from '@wildshard/engine/game/plugin/geometry';
13
+ import { DRIFTWOOD_INTERACT } from '../src/shards/driftwood-isle/generators/interactables.ts';
14
+ import { pineTableFromPlacements } from '../src/shards/pine-hollow/generators/questTable.ts';
15
+ import { pineSpots } from '../src/shards/pine-hollow/generators/spots.ts';
16
+
17
+ const seed = 0x1a7e, variants = new Map(), traces = {};
18
+ const spots = pineSpots();
19
+ const pine = pineTableFromPlacements(spots.rows);
20
+ const add = (part, value) => {
21
+ const key = `${part.key}:${value}`;
22
+ if (!variants.has(key)) variants.set(key, { part, seed: value });
23
+ };
24
+ installKitProps();
25
+ for (const row of authoredPickups) registerPickupLook(row.id, { ...row,
26
+ parts: row.parts.map(part => {
27
+ const bound = { key: part.key, batch: part.batch, geometry: value => { add(part, value); return part.geometry(value); } };
28
+ if ('bob' in part) bound.bob = part.bob;
29
+ if ('pulse' in part) bound.pulse = part.pulse;
30
+ return bound;
31
+ }),
32
+ });
33
+ // Run the actual engine cache and seed counter; visibility and saved flags never skip construction.
34
+ for (const [name, table] of Object.entries({ 'driftwood-isle': DRIFTWOOD_INTERACT, 'pine-hollow': pine })) {
35
+ const flags = { has: () => false }, runner = new Interactables({ flags }), rows = [], seeds = new Map();
36
+ const original = runner.geo.bind(runner);
37
+ runner.geo = (key, batch, make) => original(key, batch, () => {
38
+ seeds.set(key, runner.seed); return make();
39
+ });
40
+ for (const def of table.rows) {
41
+ runner.parts(new Live(def, flags));
42
+ if (def.kind === 'pickup' || def.kind === 'altar') {
43
+ const parts = pickupLook(def.kind === 'pickup' ? def.look : def.socketLook)?.parts ?? [];
44
+ rows.push({ id: def.id, kind: def.kind, parts: parts.slice(0, def.kind === 'altar' ? 1 : parts.length)
45
+ .map(part => ({ key: part.key, seed: seeds.get(part.key) })) });
46
+ }
47
+ }
48
+ traces[name] = rows;
49
+ for (const pending of runner.pending) pending.geo.dispose();
50
+ }
51
+ // Every Explorer model uses the original default seed; loot uses its independent fixed seed.
52
+ for (const row of authoredPickups) for (const part of row.parts) add(part, seed);
53
+ const coin = authoredPickups.find(row => row.id === 'coin').parts[0]; add(coin, 0xc01);
54
+ // The retained shelf bake and frozen legacy shelf use one independently coloured token per slot.
55
+ const token = authoredPickups.find(row => row.id === 'token').parts[0];
56
+ for (let i = 0; i < 8; i++) add(token, 1000 + i);
57
+
58
+ const writer = byteWriter(process.argv.includes('--check'), 'pickup-bake');
59
+ const memberBytes = new Map();
60
+ let rawBytes = 0, compressedBytes = 0, legacyEncodedBytes = 0;
61
+ const geometries = [...variants.values()].map(({ part, seed: value }) => {
62
+ const geometry = part.geometry(value), chunks = [];
63
+ if (geometry.index !== null || geometry.groups.length > 0) throw new Error('Pickup bake requires original unindexed draws');
64
+ const attrs = Object.entries(geometry.attributes).map(([name, attribute]) => {
65
+ if (!(attribute.array instanceof Float32Array)) throw new Error(`Unsupported pickup attribute ${name}`);
66
+ chunks.push(Buffer.from(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength));
67
+ return [name, 'f32', attribute.itemSize, attribute.normalized];
68
+ });
69
+ const row = { attrs, count: geometry.getAttribute('position').count, index: null, indexCount: 0,
70
+ box: geometry.boundingBox !== null, expand: false };
71
+ const bytes = Buffer.concat(chunks), compressed = zlibSync(bytes), restored = readBakedGeometry(unzlibSync(compressed), 0, row);
72
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
73
+ const actual = restored.getAttribute(name).array;
74
+ if (!Buffer.from(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength)
75
+ .equals(Buffer.from(actual.buffer, actual.byteOffset, actual.byteLength))) throw new Error(`Pickup byte mismatch ${part.key}:${value}:${name}`);
76
+ }
77
+ if (!geometry.boundingBox.equals(restored.boundingBox) || !geometry.boundingSphere.equals(restored.boundingSphere)) throw new Error(`Pickup bounds mismatch ${part.key}:${value}`);
78
+ rawBytes += bytes.length; compressedBytes += compressed.length; legacyEncodedBytes += Math.ceil(compressed.length/3)*4;
79
+ geometry.dispose(); restored.dispose();
80
+ const file = `/assets/baked/common/pickups/${createHash('sha256').update(bytes).digest('hex')}.bin`;
81
+ writer.put(fileURLToPath(new URL(`../public${file}`, import.meta.url)),bytes);
82
+ memberBytes.set(file, bytes);
83
+ return { key: part.key, seed: value, geometry: row, file };
84
+ });
85
+ // Keep each original source file/identity for native and frozen readers. The
86
+ // browser's generic bank reader restores those same members from one body.
87
+ const bankBytes = Buffer.concat([...memberBytes.values()]);
88
+ const bankFile = `/assets/baked/common/pickups/${createHash('sha256').update(bankBytes).digest('hex')}.bin`;
89
+ let bankOffset = 0;
90
+ const members = [...memberBytes].map(([file, bytes]) => {
91
+ const member = { file, offset: bankOffset, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') };
92
+ bankOffset += bytes.length;
93
+ return member;
94
+ });
95
+ writer.put(fileURLToPath(new URL(`../public${bankFile}`, import.meta.url)), bankBytes);
96
+ const looks = authoredPickups.map(row => ({ id: row.id, model: row.model, name: row.name, batch: row.batch, lift: row.lift,
97
+ parts: row.parts.map(({ geometry: _geometry, ...part }) => part) }));
98
+ const rows = { file: 'src/client/game/generators/pickups.ts', seed, coin: coin.key, geometries, looks,
99
+ banks: [{ file: bankFile, bytes: bankBytes.length, members }] };
100
+ writer.put(fileURLToPath(new URL('@wildshard/engine/game/data/pickupCatalogue', import.meta.url)), jsonBytes(rows));
101
+ writer.finish();
102
+ console.log(JSON.stringify({ variants: geometries.length, rawBytes, compressedBytes, encodedBytes: 0, legacyEncodedBytes, traces }, null, 2));
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ // G384: emit a shard's query-only terrain (`form: 'query'`) through its explicit shard-owned author function, which wraps
3
+ // the SDK's `bakeQueryTerrain` over its retained bare WSTR lattice. File I/O stays here, never in shard authoring code.
4
+ // node scripts/bake-query-terrain.mjs <entry> <function> <lattice> <metadata> <assets> [--check]
5
+ // <metadata> receives `{ terrain, files, critical }`; <assets>/<hash> receives each charged file, named by its content hash.
6
+ import '@wildshard/engine/scripts/format-hook.mjs';
7
+ import { createHash } from 'node:crypto';
8
+ import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
9
+ import { registerHooks } from 'node:module';
10
+ import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
11
+ import { fileURLToPath, pathToFileURL } from 'node:url';
12
+
13
+ const check = process.argv.includes('--check'), args = process.argv.slice(2).filter(arg => arg !== '--check');
14
+ const entry = args.at(0), binding = args.at(1), lattice = args.at(2), metadata = args.at(3), assets = args.at(4);
15
+ if (args.length !== 5 || entry === undefined || binding === undefined || lattice === undefined || metadata === undefined || assets === undefined) {
16
+ throw new Error('bake-query-terrain: entry, function, lattice, metadata and asset folder required');
17
+ }
18
+ const root = process.cwd();
19
+ /** Confine every path to regular files in the repository tree. @param {string} path */
20
+ function confined(path) {
21
+ if (isAbsolute(path) || path.includes('\\') || path.split('/').some(part => part === '' || part === '.' || part === '..')) throw new Error(`bake-query-terrain: path escapes the tree: ${path}`);
22
+ const parts = path.split('/');
23
+ for (let length = 1; length <= parts.length; length++) {
24
+ const at = resolve(root, ...parts.slice(0, length));
25
+ if (existsSync(at) && lstatSync(at).isSymbolicLink()) throw new Error(`bake-query-terrain: symlink refused: ${path}`);
26
+ }
27
+ const target = resolve(root, path);
28
+ if (!target.startsWith(root + sep)) throw new Error(`bake-query-terrain: path escapes the tree: ${path}`);
29
+ return target;
30
+ }
31
+ const owner = /^src\/shards\/([^/]+)\/generators\//u.exec(entry)?.[1];
32
+ if (owner === undefined || !metadata.startsWith(`src/shards/${owner}/`) || assets !== `src/shards/${owner}/assets`) throw new Error('bake-query-terrain: a shard-owned generator writes only its own shard');
33
+ // Authoring resolution only (the SDK source loader's law, without engine, game or app identity): extensionless TS imports,
34
+ // and nothing outside sdk, commons, format and this shard's author folders.
35
+ const folders = new Set(['generators', 'data', 'quests', 'blender', 'assets', 'behaviour']);
36
+ registerHooks({ resolve(specifier, context, next) {
37
+ const relativeTs = specifier.startsWith('.') && context.parentURL?.startsWith('file:') && !/\.[cm]?[jt]s$/u.test(specifier);
38
+ const result = relativeTs && existsSync(fileURLToPath(new URL(`${specifier}.ts`, context.parentURL)))
39
+ ? { url: new URL(`${specifier}.ts`, context.parentURL).href, shortCircuit: true } : next(specifier, context);
40
+ if (result.url.startsWith('file:')) {
41
+ const parts = relative(root, fileURLToPath(result.url)).split(sep);
42
+ if (parts[0] === 'src' && (parts.includes('runtime') || (parts[1] === 'shards' ? parts[2] !== owner || !folders.has(parts[3] ?? '') : !['sdk', 'sharddev', 'commons', 'format'].includes(parts[1] ?? '')))) {
43
+ throw new Error(`bake-query-terrain: non-authoring dependency refused: ${parts.join('/')}`);
44
+ }
45
+ }
46
+ return result;
47
+ } });
48
+ const author = await import(pathToFileURL(confined(entry)).href);
49
+ const bake = author[binding];
50
+ if (typeof bake !== 'function') throw new Error(`bake-query-terrain: ${entry} exports no ${binding}`);
51
+ const product = bake(new Uint8Array(readFileSync(confined(lattice))));
52
+ if (product?.terrain?.form !== 'query' || !(product.assets instanceof Map) || product.assets.size !== product.files.length) throw new Error('bake-query-terrain: the author must return one query terrain product');
53
+ const outputs = new Map([[metadata, Buffer.from(`${JSON.stringify({ terrain: product.terrain, files: product.files, critical: product.critical })}\n`)]]);
54
+ for (const [hash, bytes] of product.assets) {
55
+ if (!(bytes instanceof Uint8Array) || createHash('sha256').update(bytes).digest('hex') !== hash) throw new Error('bake-query-terrain: asset differs from its hash');
56
+ outputs.set(`${assets}/${hash}`, Buffer.from(bytes));
57
+ }
58
+ for (const [file, bytes] of outputs) {
59
+ const path = confined(file);
60
+ if (check) {
61
+ if (!existsSync(path) || !readFileSync(path).equals(bytes)) throw new Error(`bake-query-terrain: stale output ${file}`);
62
+ } else { mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, bytes); }
63
+ }
64
+ console.info(`bake-query-terrain: ${owner} query sampling ${product.critical.join(', ')}`);
@@ -0,0 +1,16 @@
1
+ // A standalone recurve asset tool (GR6, D2-style): run it by hand when the recurve
2
+ // bow changes; its committed outputs are public/assets/nalati/baked/recurve-pool.json and the pool GLB it names.
3
+ import {createHash} from 'node:crypto';
4
+ import {mkdirSync,writeFileSync,readFileSync} from 'node:fs';
5
+ import {recurvePool} from '../src/shards/nalati-grasslands/generators/recurvePool.ts';
6
+
7
+ const made=recurvePool(),out=new URL('../public/assets/nalati/baked/',import.meta.url);
8
+ const hash=createHash('sha256').update(made.glb).digest('hex');
9
+ if(hash!=='6f362ed67dfffeb86ad47768a8e43a59267da96dee77914d0f9cf2af70b8e3ea')throw new Error(`Recurve pool hash changed (${hash}); update the declared generation output`);
10
+ made.rows.pool.url=`/assets/nalati/baked/${hash}.glb`;
11
+ const metadata=new URL('recurve-pool.json',out),text=`${JSON.stringify(made.rows)}\n`;
12
+ if(process.argv.includes('--check')){
13
+ if(!readFileSync(new URL(`${hash}.glb`,out)).equals(made.glb)||readFileSync(metadata,'utf8')!==text)throw new Error('Recurve pool stale: run bake-recurve-pool.mjs');
14
+ }else{
15
+ mkdirSync(out,{recursive:true});writeFileSync(new URL(`${hash}.glb`,out),made.glb);writeFileSync(metadata,text);
16
+ }
@@ -0,0 +1,3 @@
1
+ /** Generate wire schemas and standalone types from the build-only registry. */
2
+ export function sectionSchemaTables(root:string,slug:string):Promise<{tables:Readonly<Record<string,string>>;report:{path:string;sourceHash:string;schemas:number;bytes:number}}>;
3
+ export function writeSectionSchemaTables(root:string,slug:string,options?:{check?:boolean}):Promise<{path:string;sourceHash:string;schemas:number;bytes:number}>;
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ // Trusted first-party source bake. Only numeric metadata and immutable bytes enter shard.config.ts.
3
+ import { readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs';
4
+ import { resolve } from 'node:path';
5
+ import { createHash } from 'node:crypto';
6
+ import { build } from 'vite';
7
+ import { compileScript } from './compile-script.mjs';
8
+ import { executeBundle } from '../src/sharddev/executeBundle.ts';
9
+
10
+ const root = resolve(import.meta.dirname, '..'), project = resolve(root, 'src/shards/_template');
11
+ const result = await build({ plugins: [{ name: 'external-build-tool', enforce: 'pre', resolveId(id) { return id === 'vite' ? { id: import.meta.resolve('vite'), external: true } : null; } }], configFile: false, publicDir: false, logLevel: 'silent', build: { write: false, minify: false,
12
+ lib: { entry: resolve(project, 'generators/terrain.ts'), formats: ['es'], fileName: 'terrain' }, rolldownOptions: { platform: 'node', external: [/^node:/u] } } });
13
+ const output = Array.isArray(result) ? result.at(0) : result;
14
+ if (output === undefined) throw new Error('Missing terrain generator output');
15
+ const chunks = output.output.filter((entry) => entry.type === 'chunk');
16
+ const chunk = chunks.at(0);
17
+ if (chunks.length !== 1 || chunk === undefined) throw new Error(`Terrain generator must bundle once: ${chunks.map((entry) => entry.fileName).join(',')}`);
18
+ const generator = await executeBundle(chunk.code, project);
19
+ if (typeof generator !== 'object' || generator === null || !('templateTerrain' in generator) || typeof generator.templateTerrain !== 'function')
20
+ throw new Error('Missing terrain generator export');
21
+ const terrain = generator.templateTerrain();
22
+ mkdirSync(resolve(project, 'assets'), { recursive: true });
23
+ for (const [hash, bytes] of terrain.assets) writeFileSync(resolve(project, 'assets', hash), bytes);
24
+ const { assets: _assets, ...metadata } = terrain;
25
+ writeFileSync(resolve(project, 'data/terrain.json'), `${JSON.stringify(metadata, null, 2)}\n`);
26
+ const bytes = await compileScript(readFileSync(resolve(project, 'behaviour/door.as'), 'utf8'), { maximumPages: 2 });
27
+ const hash = createHash('sha256').update(bytes).digest('hex');
28
+ writeFileSync(resolve(project, 'assets', hash), bytes);
29
+ writeFileSync(resolve(project, 'behaviour/door.json'), `${JSON.stringify({ hash, compressed: bytes.length }, null, 2)}\n`);
30
+ const props = JSON.parse(readFileSync(resolve(project, 'data/props.json'), 'utf8'));
31
+ for (const file of props.files) copyFileSync(resolve(root, 'public/assets/baked/template-props', file.hash), resolve(project, 'assets', file.hash));
32
+ console.info(`template bake: ${terrain.tiles.length} tiles, ${terrain.assets.size} terrain files, door ${bytes.length} bytes`);
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
3
+ // bake-textures.mjs — bake the sky's procedural textures once (project/archive/2026-09-22-load-perf.md §P2; SF87, G320).
4
+ //
5
+ // The sky's cloud field, banded planet and gas giant are painted on a canvas at runtime when the build has no file for
6
+ // them (`bakedTexture(name, make)`, src/client/engine/boot/bakedTextures.ts). This bundles a bake page
7
+ // (scripts/bake/skyTexturesPage.ts: the engine's pure painters, src/client/engine/world/skyTextures.ts, and nothing else), runs
8
+ // it on a blank page in headless Chromium (muted, as the iPhone 16 Pro), and writes the shard's
9
+ // public/assets/baked/<slug>/tex/<name>.jpg plus textures.json with a hash of the output files. It boots no game page and
10
+ // loads no shard runtime or legacy code. Every run bakes in memory; --check writes nothing.
11
+ //
12
+ // scripts/browser-lane.sh node scripts/bake-textures.mjs [--chunk pine-hollow|driftwood-isle|--all] [--check]
13
+ //
14
+ // GR9 (G798): a plain script, run by hand when the painters change; its outputs are committed files, not catalogue
15
+ // outputs, and --check verifies them.
16
+ import { existsSync, readdirSync } from 'node:fs';
17
+ import { resolve } from 'node:path';
18
+ import { build } from 'vite';
19
+ import { byteWriter, outputHash, jsonBytes, toolVersion, browserBakeBytes } from '@wildshard/engine/scripts/bake-output.mjs';
20
+
21
+ const ROOT = resolve(import.meta.dirname, '..');
22
+ /** Which sky textures each shard ships baked (the rest paint at runtime): the sky pieces its look builds. */
23
+ const SHARDS = {
24
+ 'driftwood-isle': ['giant'], // the gas giant (its sky spec's `planet`)
25
+ 'pine-hollow': ['clouds', 'planet'], // the cloud layer and the ringed planet
26
+ };
27
+ const arg = (k, d) => { const i = process.argv.indexOf(k); return i > 0 ? process.argv[i + 1] : d; };
28
+ const all = process.argv.includes('--all');
29
+ const only = arg('--chunk', 'pine-hollow');
30
+ if (!all && !Object.hasOwn(SHARDS, only)) throw new Error(`bake-textures: --chunk ${only}? (${Object.keys(SHARDS).join(', ')})`);
31
+ const slugs = all ? Object.keys(SHARDS) : [only];
32
+ const check = process.argv.includes('--check');
33
+ const output = byteWriter(check, 'bake-textures');
34
+
35
+ const bundle = await build({
36
+ configFile: false, logLevel: 'silent', publicDir: false, root: ROOT,
37
+ build: { write: false, target: 'esnext', minify: false, lib: { entry: resolve(ROOT, 'scripts/bake/skyTexturesPage.ts'), formats: ['iife'], name: 'skyTexturesPage' } },
38
+ });
39
+ const chunks = (Array.isArray(bundle) ? bundle : [bundle]).flatMap((b) => ('output' in b ? b.output : []));
40
+ const code = chunks.find((c) => c.type === 'chunk')?.code;
41
+ if (code === undefined) throw new Error('bake-textures: the bake page did not bundle');
42
+
43
+ const { chromium, devices } = await import('playwright');
44
+ const browser = await chromium.launch({ headless: true, args: [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--enable-gpu', '--ignore-gpu-blocklist'] });
45
+ try {
46
+ const page = await (await browser.newContext(devices['iPhone 16 Pro'])).newPage();
47
+ /** @type {string[]} */ const errors = [];
48
+ page.on('pageerror', (e) => { errors.push(e.message); });
49
+ await page.setContent('<!doctype html><meta charset="utf-8"><title>sky bake</title>');
50
+ await page.addScriptTag({ content: code });
51
+ for (const slug of slugs) {
52
+ const dir = resolve(ROOT, 'public/assets/baked', slug, 'tex');
53
+ const meta = resolve(ROOT, 'public/assets/baked', slug, 'textures.json');
54
+ const names = SHARDS[/** @type {keyof typeof SHARDS} */ (slug)], sink = await browserBakeBytes(page, { maxFiles: names.length });
55
+ try {
56
+ /** @type {Record<string, { lossless: boolean; width: number; height: number }>} */
57
+ const out = await page.evaluate(({ selected, url }) => window.bakeSkyTextures(selected, url), { selected: names, url: sink.url });
58
+ const files = {};
59
+ const buffers = [];
60
+ const wanted = new Set();
61
+ for (const [name, { lossless, width, height }] of Object.entries(out).sort(([a], [b]) => a.localeCompare(b))) {
62
+ const file = `${name}.${lossless ? 'png' : 'jpg'}`;
63
+ wanted.add(file);
64
+ const buf = sink.take(name);
65
+ // a source edit that did not change the pixels keeps the file byte-identical (no commit noise, same SW cache entry)
66
+ output.put(resolve(dir, file), buf);
67
+ buffers.push(buf);
68
+ files[file] = { bytes: buf.length, width, height };
69
+ }
70
+ if (existsSync(dir)) for (const f of readdirSync(dir)) if (!wanted.has(f) && !f.includes('.phone.')) output.remove(resolve(dir, f));
71
+ const hash = outputHash(Buffer.concat(buffers));
72
+ output.put(meta, jsonBytes({ hash, files }));
73
+ console.log(`bake-textures: ${slug} ${Object.keys(files).join(' ')} (hash ${hash.slice(0, 12)})`);
74
+ } finally { await sink.dispose(); }
75
+ }
76
+ if (errors.length > 0) throw new Error(`bake-textures: page errors: ${errors.join('; ')}`);
77
+ } finally {
78
+ await browser.close();
79
+ }
80
+ if (output.finish() > 0) console.log(`bake-textures: Chromium ${toolVersion(chromium.executablePath(), [...KEYCHAIN_ARGS, '--version']) ?? 'unavailable'}`);
@@ -0,0 +1,45 @@
1
+ {
2
+ "$doc": "G187 cut 3: written by scripts/bake-viewmodel-sets.mjs (per tier: viewmodel set plane table name -> KTX2; cache: PNG+settings hash -> KTX2); merged into the level's KTX2 table by scripts/bake-ktx2.mjs",
3
+ "phone": {
4
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.arm-b9c0f754.ktx2",
5
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.col-81cbdd17.ktx2",
6
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.nrm-8191fd87.ktx2",
7
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.arm-f50ea074.ktx2",
8
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.col-89a89fd0.ktx2",
9
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.nrm-db2bfc8d.ktx2",
10
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.arm-5a50a255.ktx2",
11
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.col-f2e5c2fa.ktx2",
12
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.nrm-f88fcc33.ktx2",
13
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.arm-c722a864.ktx2",
14
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.col-3f5e277c.ktx2",
15
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.nrm-8bbbf049.ktx2"
16
+ },
17
+ "desktop": {
18
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.arm-b9c0f754.ktx2",
19
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.col-81cbdd17.ktx2",
20
+ "procedural:/assets/baked/pine-hollow/viewmodel/bolt.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.nrm-8191fd87.ktx2",
21
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.arm-f50ea074.ktx2",
22
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.col-89a89fd0.ktx2",
23
+ "procedural:/assets/baked/pine-hollow/viewmodel/brushed-steel.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.nrm-db2bfc8d.ktx2",
24
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.arm-5a50a255.ktx2",
25
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.col-f2e5c2fa.ktx2",
26
+ "procedural:/assets/baked/pine-hollow/viewmodel/gunmetal.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.nrm-f88fcc33.ktx2",
27
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.arm.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.arm-c722a864.ktx2",
28
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.col.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.col-3f5e277c.ktx2",
29
+ "procedural:/assets/baked/pine-hollow/viewmodel/leather.nrm.png": "/assets/gpu/baked/pine-hollow/viewmodel/leather.nrm-8bbbf049.ktx2"
30
+ },
31
+ "cache": {
32
+ "c26da7e612eeebdea730ca12fe1555a214671c7d1a307d2516ede9ffb80c5f3f": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.col-89a89fd0.ktx2",
33
+ "5c464ceb49438cf53e6de3b81ced096d0c0c1b25f082562e6d6807022edbd827": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.nrm-db2bfc8d.ktx2",
34
+ "88f2557a5522c32b2456df34c24d3d9319ca6976c98aa861ed135edfbb574e7b": "/assets/gpu/baked/pine-hollow/viewmodel/leather.col-3f5e277c.ktx2",
35
+ "277b471bf6910502688aae245a40091ff1ff4f1a2d147862bf453b6ca66218f8": "/assets/gpu/baked/pine-hollow/viewmodel/leather.nrm-8bbbf049.ktx2",
36
+ "6a8ed14f871fb24507c7c5863da7048339a7b039a6fa8fe6f141c42b429a2aa9": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.col-81cbdd17.ktx2",
37
+ "1491c645974f4ca8a11c6ffa46ef8366f3298860d3fead6605995f8e3f4e87e5": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.nrm-8191fd87.ktx2",
38
+ "81bea00b51d0e435ac3bf342c2a7c2df99f06e99b1c14a2d9d13fcaca79e4dfe": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.col-f2e5c2fa.ktx2",
39
+ "f4b33dbffd783499ec29a76202e9f250fd9c6c37d5277e7c4129d4d94ba329f6": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.nrm-f88fcc33.ktx2",
40
+ "f0038c917e7ddc2633befdeabeac2e998cd949217100b315fc99d46c34dba262": "/assets/gpu/baked/pine-hollow/viewmodel/brushed-steel.arm-f50ea074.ktx2",
41
+ "de598303b981175c3b85dafeb56b9ff08572552c8047fca601eb92bbbdc3b3db": "/assets/gpu/baked/pine-hollow/viewmodel/leather.arm-c722a864.ktx2",
42
+ "bd79436d002ada7e4384d217bb4249ce8fdd0d087b0ca046ada868e5edd7bb33": "/assets/gpu/baked/pine-hollow/viewmodel/bolt.arm-b9c0f754.ktx2",
43
+ "064f993500579d619aa9308f6a5efb2a42419f7b7a9c107c3cb59d29eeb84a7a": "/assets/gpu/baked/pine-hollow/viewmodel/gunmetal.arm-5a50a255.ktx2"
44
+ }
45
+ }
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
3
+ // bake-viewmodel-sets.mjs — a level's weapon viewmodel texture sets as KTX2 (G187 cut 3, E435). The crossbow's and the
4
+ // rifle's walnut, steel, leather, bolt and gunmetal sets are drawn at every boot (src/client/engine/player/viewmodelTextures.ts
5
+ // makePixels, in a worker) and uploaded as RGBA8 DataTextures: ~18 MB of Pine Hollow's phone GL. Their pixels never change
6
+ // (seeded), so they are drawn here, offline, and the KTX2 path loads them compressed (src/client/engine/combat/view/ranged.ts
7
+ // startViewmodelTextures adopts a set whose three planes the level's KTX2 table holds).
8
+ //
9
+ // How: vite bundles viewmodelTextures.ts as it stands (the game's own makePixels) into a muted Chromium page, which draws
10
+ // each set (the steel sets' scratches need its 2D canvas) and hands back the raw RGBA planes. Each plane is written as a
11
+ // lossless PNG, row 0 = v 0 (the DataTexture's order), and encoded with bake-ktx2.mjs's classes — colour (UASTC 4×4
12
+ // level 2, sRGB), normal (UASTC, -normal_map), ARM as `linear` (UASTC, linear) — full box-filtered mips, zstd 20,
13
+ // unflipped (a DataTexture is not flipped either), content-addressed under public/assets/gpu/baked/<slug>/viewmodel/.
14
+ // The sets are a fixed size on every tier, so one file serves both: scripts/bake-viewmodel-sets.json maps, per tier, the
15
+ // plane's table name (viewmodelTextures.ts viewmodelBakeUrl: `/assets/baked/<slug>/viewmodel/<set>.<col|nrm|arm>.png`, a
16
+ // name, not a file) to its KTX2; bake-ktx2.mjs merges it into the level's KTX2 table and keeps the files. Rerun whenever
17
+ // a set's drawing changes, then rerun bake-ktx2.mjs.
18
+ //
19
+ // scripts/browser-lane.sh node scripts/bake-viewmodel-sets.mjs [--slug=pine-hollow] [--sets=brushed-steel,leather,bolt,gunmetal]
20
+ // Add --check-planes to print raw/PNG/cache hashes without encoding or writing assets.
21
+ // node --import ./scripts/bake-loader.mjs scripts/bake-ktx2.mjs
22
+ import { createHash } from 'node:crypto';
23
+ import { execFileSync } from 'node:child_process';
24
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
25
+ import { join, relative, resolve } from 'node:path';
26
+ import { deflateSync, crc32 } from 'node:zlib';
27
+ import { chromium } from 'playwright';
28
+ import { build } from 'vite';
29
+ import { browserBakeBytes } from '@wildshard/engine/scripts/bake-output.mjs';
30
+
31
+ const ROOT = resolve(import.meta.dirname, '..');
32
+ const PUB = resolve(ROOT, 'public');
33
+ const TABLE = resolve(ROOT, 'scripts/bake-viewmodel-sets.json');
34
+ const argv = process.argv.slice(2), checkPlanes = argv.includes('--check-planes');
35
+ const flag = (name, fallback) => argv.find((a) => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
36
+ const slug = flag('slug', 'pine-hollow');
37
+ /**
38
+ * the sets the level's weapons wear on the GPU (Pine Hollow: the crossbow's brushed-steel / leather / bolt, the
39
+ * lever-action's gunmetal). The cord stays drawn (64², no ARM plane), and so does the walnut: the crossbow stock fills the
40
+ * bottom of every phone shot, magnified, and its UASTC grain held the gate pose at SSIM 0.99961 against Pine's 0.99959
41
+ * floor (drawn: 0.99974)
42
+ */
43
+ const sets = flag('sets', 'brushed-steel,leather,bolt,gunmetal').split(',');
44
+ const OUT = resolve(PUB, `assets/gpu/baked/${slug}/viewmodel`);
45
+ const ENCODER = /v[\d.]+/.exec(execFileSync('basisu', ['-version']).toString())?.[0] ?? '?';
46
+ /** bake-ktx2.mjs COMMON + CLASS (color / normal / linear: the ARM plane is UASTC, not bake-ktx2's ETC1S `data` class — its
47
+ * roughness / metalness blocks moved the held weapon's highlights past Pine's parity floor on the phone) */
48
+ const COMMON = ['-ktx2', '-mipmap', '-mip_filter', 'box', '-max_threads', '4'];
49
+ const CLASS = {
50
+ col: ['-uastc', '-uastc_level', '2', '-srgb', '-ktx2_zstandard_level', '20'],
51
+ nrm: ['-uastc', '-uastc_level', '2', '-normal_map', '-ktx2_zstandard_level', '20'],
52
+ arm: ['-uastc', '-uastc_level', '2', '-linear', '-ktx2_zstandard_level', '20'],
53
+ };
54
+ const sha = (buf) => createHash('sha256').update(buf).digest('hex');
55
+ const pub = (abs) => `/${relative(PUB, abs).split('\\').join('/')}`;
56
+ const bakeUrl = (set, plane) => `procedural:/assets/baked/${slug}/viewmodel/${set}.${plane}.png`; // viewmodelTextures.ts viewmodelBakeUrl
57
+
58
+ /** a minimal RGBA8 PNG (filter 0 rows, zlib): lossless, so the planes reach basisu exactly as makePixels drew them */
59
+ function png(w, h, rgba) {
60
+ const raw = Buffer.alloc((w * 4 + 1) * h);
61
+ for (let y = 0; y < h; y++) Buffer.from(rgba.buffer, rgba.byteOffset + y * w * 4, w * 4).copy(raw, y * (w * 4 + 1) + 1);
62
+ const chunk = (type, data) => {
63
+ const len = Buffer.alloc(4); len.writeUInt32BE(data.length);
64
+ const td = Buffer.concat([Buffer.from(type, 'ascii'), data]);
65
+ const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(td) >>> 0);
66
+ return Buffer.concat([len, td, crc]);
67
+ };
68
+ const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 6;
69
+ return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw, { level: 9 })), chunk('IEND', Buffer.alloc(0))]);
70
+ }
71
+
72
+ // The game's exact makePixels plus its raw byte handoff, bundled for the bake page.
73
+ const bundle = await build({
74
+ configFile: false, logLevel: 'warn', root: ROOT,
75
+ build: { write: false, minify: false, lib: { entry: resolve(ROOT, 'scripts/bake/viewmodelPage.ts'), formats: ['iife'], name: 'ViewmodelBake', fileName: () => 'vt.js' } },
76
+ });
77
+ const output = (Array.isArray(bundle) ? bundle[0] : bundle).output.find((o) => o.type === 'chunk');
78
+ if (!output) throw new Error('bake-viewmodel-sets: vite produced no chunk');
79
+
80
+ const prior = existsSync(TABLE) ? JSON.parse(readFileSync(TABLE, 'utf8')) : {};
81
+ const cache = prior.cache ?? {};
82
+ const mine = (url) => url.replace(/^procedural:/u, '').startsWith(`/assets/baked/${slug}/viewmodel/`);
83
+ const next = Object.fromEntries(Object.entries(prior.phone ?? {}).filter(([url]) => !mine(url)));
84
+ const used = new Set();
85
+ mkdirSync(join(ROOT, 'tmp'), { recursive: true });
86
+ const TMP = mkdtempSync(join(ROOT, 'tmp', 'bake-viewmodel-sets-'));
87
+ let encoded = 0, reused = 0;
88
+
89
+ let browser;
90
+ try {
91
+ browser = await chromium.launch({ channel: 'chromium', args: [...KEYCHAIN_ARGS, '--mute-audio'] });
92
+ if (!checkPlanes) mkdirSync(OUT, { recursive: true });
93
+ const page = await (await browser.newContext()).newPage();
94
+ await page.setContent('<!doctype html><html><body></body></html>');
95
+ await page.addScriptTag({ content: output.code });
96
+ for (const set of sets) {
97
+ const sink = await browserBakeBytes(page, { maxFiles: 3 });
98
+ let drawn;
99
+ try {
100
+ drawn = await page.evaluate(({ name, url }) => window.bakeViewmodelPixels(name, url), { name: set, url: sink.url });
101
+ for (const plane of /** @type {const} */ (['col', 'nrm', 'arm'])) {
102
+ if (!drawn.planes.includes(plane)) throw new Error(`bake-viewmodel-sets: ${set} has no ${plane} plane`);
103
+ const rgba = sink.take(plane);
104
+ if (rgba.length !== drawn.w * drawn.h * 4) throw new Error(`Invalid ${set} ${plane} byte count`);
105
+ const image = png(drawn.w, drawn.h, rgba);
106
+ const key = sha(`${sha(image)}|${ENCODER}|${[...COMMON, ...CLASS[plane]].join(' ')}`);
107
+ if (checkPlanes) { console.log(JSON.stringify({ set, plane, w: drawn.w, h: drawn.h, bytes: rgba.length, rawHash: sha(rgba), pngHash: sha(image), cacheKey: key })); continue; }
108
+ used.add(key);
109
+ let out = cache[key];
110
+ if (out && existsSync(join(PUB, out))) reused++;
111
+ else {
112
+ const src = join(TMP, `${encoded}.png`), dst = join(TMP, `${encoded}.ktx2`);
113
+ writeFileSync(src, image);
114
+ execFileSync('basisu', [...COMMON, ...CLASS[plane], src, '-output_file', dst], { stdio: ['ignore', 'ignore', 'pipe'] });
115
+ const bytes = readFileSync(dst);
116
+ const file = join(OUT, `${set}.${plane}-${sha(bytes).slice(0, 8)}.ktx2`);
117
+ writeFileSync(file, bytes);
118
+ out = pub(file); cache[key] = out; encoded++;
119
+ }
120
+ next[bakeUrl(set, plane)] = out;
121
+ }
122
+ } finally { await sink.dispose(); }
123
+ console.log(`bake-viewmodel-sets: ${slug} ${set} ${drawn.w}×${drawn.h}`);
124
+ }
125
+ } finally {
126
+ try { await browser?.close(); } finally { rmSync(TMP, { recursive: true, force: true }); }
127
+ }
128
+
129
+ if (!checkPlanes) {
130
+ const table = Object.fromEntries(Object.entries(next).sort(([a], [b]) => a.localeCompare(b)));
131
+ const live = new Set(Object.values(table));
132
+ for (const k of Object.keys(cache)) if (!used.has(k) && !live.has(cache[k])) delete cache[k];
133
+ for (const f of readdirSync(OUT)) if (!live.has(pub(join(OUT, f)))) rmSync(join(OUT, f));
134
+ // one size on every tier: both tiers name the same files
135
+ writeFileSync(TABLE, `${JSON.stringify({ $doc: 'G187 cut 3: written by scripts/bake-viewmodel-sets.mjs (per tier: viewmodel set plane table name -> KTX2; cache: PNG+settings hash -> KTX2); merged into the level\'s KTX2 table by scripts/bake-ktx2.mjs', phone: table, desktop: table, cache }, null, 1)}\n`);
136
+ console.log(`bake-viewmodel-sets: ${encoded} encoded, ${reused} reused · ${live.size} files`);
137
+ }