sci2-ts 0.0.0-stage → 0.2.2

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 (357) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE +21 -0
  3. package/README.md +113 -2
  4. package/apps/viewer/editor.html +43 -0
  5. package/apps/viewer/explore.html +27 -0
  6. package/apps/viewer/index.html +26 -0
  7. package/apps/viewer/package.json +27 -0
  8. package/apps/viewer/play.html +26 -0
  9. package/apps/viewer/plugin.d.ts +18 -0
  10. package/apps/viewer/plugin.js +75 -0
  11. package/apps/viewer/plugin.ts +84 -0
  12. package/apps/viewer/src/adlib.d.ts +20 -0
  13. package/apps/viewer/src/adlib.js +55 -0
  14. package/apps/viewer/src/adlib.ts +62 -0
  15. package/apps/viewer/src/app.d.ts +5 -0
  16. package/apps/viewer/src/app.js +5 -0
  17. package/apps/viewer/src/app.ts +5 -0
  18. package/apps/viewer/src/asset-index.d.ts +22 -0
  19. package/apps/viewer/src/asset-index.js +74 -0
  20. package/apps/viewer/src/asset-index.ts +90 -0
  21. package/apps/viewer/src/audio.d.ts +28 -0
  22. package/apps/viewer/src/audio.js +102 -0
  23. package/apps/viewer/src/audio.ts +110 -0
  24. package/apps/viewer/src/editor-handles.d.ts +63 -0
  25. package/apps/viewer/src/editor-handles.js +332 -0
  26. package/apps/viewer/src/editor-handles.ts +368 -0
  27. package/apps/viewer/src/editor-languages.d.ts +23 -0
  28. package/apps/viewer/src/editor-languages.js +157 -0
  29. package/apps/viewer/src/editor-languages.ts +135 -0
  30. package/apps/viewer/src/editor.css +213 -0
  31. package/apps/viewer/src/editor.d.ts +1 -0
  32. package/apps/viewer/src/editor.js +393 -0
  33. package/apps/viewer/src/editor.ts +412 -0
  34. package/apps/viewer/src/explore/classes.d.ts +7 -0
  35. package/apps/viewer/src/explore/classes.js +63 -0
  36. package/apps/viewer/src/explore/classes.ts +61 -0
  37. package/apps/viewer/src/explore/context.d.ts +33 -0
  38. package/apps/viewer/src/explore/context.js +96 -0
  39. package/apps/viewer/src/explore/context.ts +124 -0
  40. package/apps/viewer/src/explore/explore.css +93 -0
  41. package/apps/viewer/src/explore/explore.d.ts +1 -0
  42. package/apps/viewer/src/explore/explore.js +102 -0
  43. package/apps/viewer/src/explore/explore.ts +104 -0
  44. package/apps/viewer/src/explore/inspect.d.ts +5 -0
  45. package/apps/viewer/src/explore/inspect.js +208 -0
  46. package/apps/viewer/src/explore/inspect.ts +279 -0
  47. package/apps/viewer/src/explore/live.d.ts +22 -0
  48. package/apps/viewer/src/explore/live.js +318 -0
  49. package/apps/viewer/src/explore/live.ts +365 -0
  50. package/apps/viewer/src/explore/map.d.ts +11 -0
  51. package/apps/viewer/src/explore/map.js +182 -0
  52. package/apps/viewer/src/explore/map.ts +193 -0
  53. package/apps/viewer/src/files.d.ts +21 -0
  54. package/apps/viewer/src/files.js +69 -0
  55. package/apps/viewer/src/files.ts +72 -0
  56. package/apps/viewer/src/game-profile.d.ts +19 -0
  57. package/apps/viewer/src/game-profile.js +4 -0
  58. package/apps/viewer/src/game-profile.ts +26 -0
  59. package/apps/viewer/src/main.d.ts +1 -0
  60. package/apps/viewer/src/main.js +473 -0
  61. package/apps/viewer/src/main.ts +527 -0
  62. package/apps/viewer/src/music.d.ts +14 -0
  63. package/apps/viewer/src/music.js +32 -0
  64. package/apps/viewer/src/music.ts +34 -0
  65. package/apps/viewer/src/opl-worklet.d.ts +1 -0
  66. package/apps/viewer/src/opl-worklet.js +47 -0
  67. package/apps/viewer/src/opl-worklet.ts +55 -0
  68. package/apps/viewer/src/overlay.d.ts +31 -0
  69. package/apps/viewer/src/overlay.js +103 -0
  70. package/apps/viewer/src/overlay.ts +123 -0
  71. package/apps/viewer/src/play.css +14 -0
  72. package/apps/viewer/src/play.d.ts +1 -0
  73. package/apps/viewer/src/play.js +179 -0
  74. package/apps/viewer/src/play.ts +177 -0
  75. package/apps/viewer/src/saves.d.ts +10 -0
  76. package/apps/viewer/src/saves.js +50 -0
  77. package/apps/viewer/src/saves.ts +51 -0
  78. package/apps/viewer/src/session.d.ts +91 -0
  79. package/apps/viewer/src/session.js +301 -0
  80. package/apps/viewer/src/session.ts +321 -0
  81. package/apps/viewer/src/sound-preview.d.ts +7 -0
  82. package/apps/viewer/src/sound-preview.js +214 -0
  83. package/apps/viewer/src/sound-preview.ts +228 -0
  84. package/apps/viewer/src/style.css +64 -0
  85. package/apps/viewer/vite.config.ts +25 -0
  86. package/bin/sci-ts.mjs +9 -0
  87. package/lib/994.sc +49 -0
  88. package/lib/995.sc +53 -0
  89. package/lib/996.sc +299 -0
  90. package/lib/997.sc +198 -0
  91. package/lib/998.sc +338 -0
  92. package/lib/999.sc +189 -0
  93. package/lib/resources.d.ts +2 -0
  94. package/lib/resources.js +84 -0
  95. package/lib/resources.ts +88 -0
  96. package/lib/system.sh +62 -0
  97. package/package.json +75 -4
  98. package/packages/content/room.schema.json +267 -0
  99. package/packages/content/src/index.d.ts +3 -0
  100. package/packages/content/src/index.js +3 -0
  101. package/packages/content/src/index.ts +3 -0
  102. package/packages/content/src/room.d.ts +111 -0
  103. package/packages/content/src/room.js +886 -0
  104. package/packages/content/src/room.ts +1011 -0
  105. package/packages/content/src/target.d.ts +80 -0
  106. package/packages/content/src/target.js +1 -0
  107. package/packages/content/src/target.ts +60 -0
  108. package/packages/content/src/yarn.d.ts +90 -0
  109. package/packages/content/src/yarn.js +214 -0
  110. package/packages/content/src/yarn.ts +261 -0
  111. package/packages/sci/src/analysis/game.d.ts +90 -0
  112. package/packages/sci/src/analysis/game.js +221 -0
  113. package/packages/sci/src/analysis/game.ts +305 -0
  114. package/packages/sci/src/analysis/runtime.d.ts +58 -0
  115. package/packages/sci/src/analysis/runtime.js +133 -0
  116. package/packages/sci/src/analysis/runtime.ts +163 -0
  117. package/packages/sci/src/audio/adlib.d.ts +73 -0
  118. package/packages/sci/src/audio/adlib.js +280 -0
  119. package/packages/sci/src/audio/adlib.ts +329 -0
  120. package/packages/sci/src/audio/index.d.ts +43 -0
  121. package/packages/sci/src/audio/index.js +99 -0
  122. package/packages/sci/src/audio/index.ts +122 -0
  123. package/packages/sci/src/audio/midi.d.ts +92 -0
  124. package/packages/sci/src/audio/midi.js +242 -0
  125. package/packages/sci/src/audio/midi.ts +262 -0
  126. package/packages/sci/src/audio/opl2.d.ts +74 -0
  127. package/packages/sci/src/audio/opl2.js +283 -0
  128. package/packages/sci/src/audio/opl2.ts +283 -0
  129. package/packages/sci/src/audio/sol.d.ts +32 -0
  130. package/packages/sci/src/audio/sol.js +81 -0
  131. package/packages/sci/src/audio/sol.ts +100 -0
  132. package/packages/sci/src/audio/write.d.ts +35 -0
  133. package/packages/sci/src/audio/write.js +91 -0
  134. package/packages/sci/src/audio/write.ts +108 -0
  135. package/packages/sci/src/gfx/cel.d.ts +36 -0
  136. package/packages/sci/src/gfx/cel.js +82 -0
  137. package/packages/sci/src/gfx/cel.ts +110 -0
  138. package/packages/sci/src/gfx/palette.d.ts +24 -0
  139. package/packages/sci/src/gfx/palette.js +49 -0
  140. package/packages/sci/src/gfx/palette.ts +56 -0
  141. package/packages/sci/src/gfx/pic-file.d.ts +46 -0
  142. package/packages/sci/src/gfx/pic-file.js +114 -0
  143. package/packages/sci/src/gfx/pic-file.ts +155 -0
  144. package/packages/sci/src/gfx/pic.d.ts +27 -0
  145. package/packages/sci/src/gfx/pic.js +34 -0
  146. package/packages/sci/src/gfx/pic.ts +53 -0
  147. package/packages/sci/src/gfx/quantize.d.ts +42 -0
  148. package/packages/sci/src/gfx/quantize.js +199 -0
  149. package/packages/sci/src/gfx/quantize.ts +218 -0
  150. package/packages/sci/src/gfx/view-file.d.ts +62 -0
  151. package/packages/sci/src/gfx/view-file.js +182 -0
  152. package/packages/sci/src/gfx/view-file.ts +233 -0
  153. package/packages/sci/src/gfx/view.d.ts +28 -0
  154. package/packages/sci/src/gfx/view.js +45 -0
  155. package/packages/sci/src/gfx/view.ts +62 -0
  156. package/packages/sci/src/index.d.ts +38 -0
  157. package/packages/sci/src/index.js +38 -0
  158. package/packages/sci/src/index.ts +38 -0
  159. package/packages/sci/src/motion/pathfinding.d.ts +40 -0
  160. package/packages/sci/src/motion/pathfinding.js +140 -0
  161. package/packages/sci/src/motion/pathfinding.ts +147 -0
  162. package/packages/sci/src/resource/archive.d.ts +16 -0
  163. package/packages/sci/src/resource/archive.js +51 -0
  164. package/packages/sci/src/resource/archive.ts +56 -0
  165. package/packages/sci/src/resource/lzs.d.ts +12 -0
  166. package/packages/sci/src/resource/lzs.js +64 -0
  167. package/packages/sci/src/resource/lzs.ts +66 -0
  168. package/packages/sci/src/resource/manager.d.ts +45 -0
  169. package/packages/sci/src/resource/manager.js +158 -0
  170. package/packages/sci/src/resource/manager.ts +184 -0
  171. package/packages/sci/src/resource/map.d.ts +18 -0
  172. package/packages/sci/src/resource/map.js +34 -0
  173. package/packages/sci/src/resource/map.ts +44 -0
  174. package/packages/sci/src/resource/types.d.ts +37 -0
  175. package/packages/sci/src/resource/types.js +45 -0
  176. package/packages/sci/src/resource/types.ts +57 -0
  177. package/packages/sci/src/script/assembly.d.ts +67 -0
  178. package/packages/sci/src/script/assembly.js +748 -0
  179. package/packages/sci/src/script/assembly.ts +714 -0
  180. package/packages/sci/src/script/compiler.d.ts +75 -0
  181. package/packages/sci/src/script/compiler.js +993 -0
  182. package/packages/sci/src/script/compiler.ts +1040 -0
  183. package/packages/sci/src/script/disasm.d.ts +81 -0
  184. package/packages/sci/src/script/disasm.js +318 -0
  185. package/packages/sci/src/script/disasm.ts +323 -0
  186. package/packages/sci/src/script/kernel-names.d.ts +6 -0
  187. package/packages/sci/src/script/kernel-names.js +165 -0
  188. package/packages/sci/src/script/kernel-names.ts +165 -0
  189. package/packages/sci/src/script/opcodes.d.ts +22 -0
  190. package/packages/sci/src/script/opcodes.js +45 -0
  191. package/packages/sci/src/script/opcodes.ts +72 -0
  192. package/packages/sci/src/script/script.d.ts +56 -0
  193. package/packages/sci/src/script/script.js +63 -0
  194. package/packages/sci/src/script/script.ts +111 -0
  195. package/packages/sci/src/script/sexpr.d.ts +45 -0
  196. package/packages/sci/src/script/sexpr.js +151 -0
  197. package/packages/sci/src/script/sexpr.ts +139 -0
  198. package/packages/sci/src/script/vocab.d.ts +15 -0
  199. package/packages/sci/src/script/vocab.js +44 -0
  200. package/packages/sci/src/script/vocab.ts +48 -0
  201. package/packages/sci/src/script/world.d.ts +25 -0
  202. package/packages/sci/src/script/world.js +65 -0
  203. package/packages/sci/src/script/world.ts +70 -0
  204. package/packages/sci/src/text/font.d.ts +37 -0
  205. package/packages/sci/src/text/font.js +103 -0
  206. package/packages/sci/src/text/font.ts +125 -0
  207. package/packages/sci/src/text/message.d.ts +69 -0
  208. package/packages/sci/src/text/message.js +171 -0
  209. package/packages/sci/src/text/message.ts +205 -0
  210. package/packages/sci/src/vm/kernels/arrays.d.ts +19 -0
  211. package/packages/sci/src/vm/kernels/arrays.js +182 -0
  212. package/packages/sci/src/vm/kernels/arrays.ts +164 -0
  213. package/packages/sci/src/vm/kernels/audio.d.ts +70 -0
  214. package/packages/sci/src/vm/kernels/audio.js +347 -0
  215. package/packages/sci/src/vm/kernels/audio.ts +349 -0
  216. package/packages/sci/src/vm/kernels/core.d.ts +5 -0
  217. package/packages/sci/src/vm/kernels/core.js +87 -0
  218. package/packages/sci/src/vm/kernels/core.ts +91 -0
  219. package/packages/sci/src/vm/kernels/graphics.d.ts +141 -0
  220. package/packages/sci/src/vm/kernels/graphics.js +467 -0
  221. package/packages/sci/src/vm/kernels/graphics.ts +502 -0
  222. package/packages/sci/src/vm/kernels/index.d.ts +8 -0
  223. package/packages/sci/src/vm/kernels/index.js +29 -0
  224. package/packages/sci/src/vm/kernels/index.ts +32 -0
  225. package/packages/sci/src/vm/kernels/lists.d.ts +6 -0
  226. package/packages/sci/src/vm/kernels/lists.js +127 -0
  227. package/packages/sci/src/vm/kernels/lists.ts +111 -0
  228. package/packages/sci/src/vm/kernels/motion.d.ts +7 -0
  229. package/packages/sci/src/vm/kernels/motion.js +204 -0
  230. package/packages/sci/src/vm/kernels/motion.ts +194 -0
  231. package/packages/sci/src/vm/kernels/palette.d.ts +82 -0
  232. package/packages/sci/src/vm/kernels/palette.js +292 -0
  233. package/packages/sci/src/vm/kernels/palette.ts +303 -0
  234. package/packages/sci/src/vm/kernels/saves.d.ts +45 -0
  235. package/packages/sci/src/vm/kernels/saves.js +123 -0
  236. package/packages/sci/src/vm/kernels/saves.ts +149 -0
  237. package/packages/sci/src/vm/kernels/system.d.ts +62 -0
  238. package/packages/sci/src/vm/kernels/system.js +110 -0
  239. package/packages/sci/src/vm/kernels/system.ts +128 -0
  240. package/packages/sci/src/vm/kernels/text.d.ts +13 -0
  241. package/packages/sci/src/vm/kernels/text.js +338 -0
  242. package/packages/sci/src/vm/kernels/text.ts +328 -0
  243. package/packages/sci/src/vm/memory.d.ts +138 -0
  244. package/packages/sci/src/vm/memory.js +168 -0
  245. package/packages/sci/src/vm/memory.ts +266 -0
  246. package/packages/sci/src/vm/replace.d.ts +11 -0
  247. package/packages/sci/src/vm/replace.js +14 -0
  248. package/packages/sci/src/vm/replace.ts +16 -0
  249. package/packages/sci/src/vm/savegame.d.ts +89 -0
  250. package/packages/sci/src/vm/savegame.js +161 -0
  251. package/packages/sci/src/vm/savegame.ts +188 -0
  252. package/packages/sci/src/vm/value.d.ts +17 -0
  253. package/packages/sci/src/vm/value.js +12 -0
  254. package/packages/sci/src/vm/value.ts +25 -0
  255. package/packages/sci/src/vm/vm.d.ts +155 -0
  256. package/packages/sci/src/vm/vm.js +1053 -0
  257. package/packages/sci/src/vm/vm.ts +914 -0
  258. package/tools/adlib-render.d.ts +1 -0
  259. package/tools/adlib-render.js +49 -0
  260. package/tools/adlib-render.ts +42 -0
  261. package/tools/analyze.d.ts +1 -0
  262. package/tools/analyze.js +25 -0
  263. package/tools/analyze.ts +25 -0
  264. package/tools/art/build.d.ts +34 -0
  265. package/tools/art/build.js +175 -0
  266. package/tools/art/build.ts +153 -0
  267. package/tools/art.d.ts +1 -0
  268. package/tools/art.js +31 -0
  269. package/tools/art.ts +29 -0
  270. package/tools/asm.d.ts +1 -0
  271. package/tools/asm.js +61 -0
  272. package/tools/asm.ts +55 -0
  273. package/tools/cli.d.ts +1 -0
  274. package/tools/cli.js +99 -0
  275. package/tools/cli.ts +100 -0
  276. package/tools/editor-server.d.ts +29 -0
  277. package/tools/editor-server.js +162 -0
  278. package/tools/editor-server.ts +176 -0
  279. package/tools/explore.d.ts +1 -0
  280. package/tools/explore.js +305 -0
  281. package/tools/explore.ts +250 -0
  282. package/tools/game/audio.d.ts +19 -0
  283. package/tools/game/audio.js +143 -0
  284. package/tools/game/audio.ts +130 -0
  285. package/tools/game/build.d.ts +46 -0
  286. package/tools/game/build.js +259 -0
  287. package/tools/game/build.ts +283 -0
  288. package/tools/game/defaults.d.ts +26 -0
  289. package/tools/game/defaults.js +82 -0
  290. package/tools/game/defaults.ts +83 -0
  291. package/tools/game/font.d.ts +3 -0
  292. package/tools/game/font.js +124 -0
  293. package/tools/game/font.ts +126 -0
  294. package/tools/game/kit.d.ts +7 -0
  295. package/tools/game/kit.js +7 -0
  296. package/tools/game/kit.ts +10 -0
  297. package/tools/game/new.d.ts +8 -0
  298. package/tools/game/new.js +39 -0
  299. package/tools/game/new.ts +38 -0
  300. package/tools/game/target.d.ts +7 -0
  301. package/tools/game/target.js +41 -0
  302. package/tools/game/target.ts +42 -0
  303. package/tools/game/template/resources.ts.tmpl +43 -0
  304. package/tools/game/template/rooms/1.room.yaml +9 -0
  305. package/tools/game/template/rooms/1.yarn +17 -0
  306. package/tools/game/template/scripts/0.sc +24 -0
  307. package/tools/game.d.ts +1 -0
  308. package/tools/game.js +77 -0
  309. package/tools/game.ts +70 -0
  310. package/tools/mod-build.d.ts +28 -0
  311. package/tools/mod-build.js +173 -0
  312. package/tools/mod-build.ts +179 -0
  313. package/tools/mod-target.d.ts +16 -0
  314. package/tools/mod-target.js +26 -0
  315. package/tools/mod-target.ts +32 -0
  316. package/tools/mod.d.ts +1 -0
  317. package/tools/mod.js +47 -0
  318. package/tools/mod.ts +45 -0
  319. package/tools/msg.d.ts +1 -0
  320. package/tools/msg.js +40 -0
  321. package/tools/msg.ts +36 -0
  322. package/tools/node-files.d.ts +3 -0
  323. package/tools/node-files.js +34 -0
  324. package/tools/node-files.ts +33 -0
  325. package/tools/patches.d.ts +3 -0
  326. package/tools/patches.js +13 -0
  327. package/tools/patches.ts +13 -0
  328. package/tools/pic-build.d.ts +9 -0
  329. package/tools/pic-build.js +26 -0
  330. package/tools/pic-build.ts +27 -0
  331. package/tools/pic.d.ts +1 -0
  332. package/tools/pic.js +64 -0
  333. package/tools/pic.ts +61 -0
  334. package/tools/play.d.ts +1 -0
  335. package/tools/play.js +54 -0
  336. package/tools/play.ts +54 -0
  337. package/tools/png.d.ts +16 -0
  338. package/tools/png.js +124 -0
  339. package/tools/png.ts +123 -0
  340. package/tools/res.d.ts +1 -0
  341. package/tools/res.js +48 -0
  342. package/tools/res.ts +50 -0
  343. package/tools/scenario.d.ts +1 -0
  344. package/tools/scenario.js +74 -0
  345. package/tools/scenario.ts +80 -0
  346. package/tools/site/build.d.ts +8 -0
  347. package/tools/site/build.js +110 -0
  348. package/tools/site/build.ts +116 -0
  349. package/tools/site/markdown.d.ts +11 -0
  350. package/tools/site/markdown.js +88 -0
  351. package/tools/site/markdown.ts +84 -0
  352. package/tools/view-build.d.ts +34 -0
  353. package/tools/view-build.js +47 -0
  354. package/tools/view-build.ts +71 -0
  355. package/tools/view.d.ts +1 -0
  356. package/tools/view.js +54 -0
  357. package/tools/view.ts +52 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Markdown to HTML, for the docs pages of a built site: the parts the docs use (headings,
3
+ * paragraphs, lists, tables, fenced code, quotes; code, links, images, bold and italic
4
+ * inline). Links to .md files become links to the .html pages made from them.
5
+ */
6
+
7
+ const escape = (s: string) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
8
+
9
+ export const slug = (text: string) =>
10
+ text.toLowerCase().replace(/<[^>]+>/g, "").replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
11
+
12
+ const pageLink = (href: string) =>
13
+ /^[a-z]+:/i.test(href) || href.startsWith("#") ? href : href.replace(/(^|\/)README\.md(?=#|$)/, "$1index.md").replace(/\.md(?=#|$)/, ".html");
14
+
15
+ export function inline(text: string): string {
16
+ const code: string[] = [];
17
+ let s = text.replace(/`([^`]+)`/g, (_, c: string) => `\u0000${code.push(`<code>${escape(c)}</code>`) - 1}\u0000`);
18
+ s = escape(s);
19
+ s = s.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (_, alt: string, src: string) => `<img src="${src}" alt="${alt}">`);
20
+ s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, label: string, href: string) => `<a href="${pageLink(href)}">${label}</a>`);
21
+ s = s.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
22
+ s = s.replace(/(^|[\s(])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>");
23
+ return s.replace(/\u0000(\d+)\u0000/g, (_, i: string) => code[Number(i)]!);
24
+ }
25
+
26
+ export function markdown(source: string): { html: string; title: string } {
27
+ const lines = source.replace(/\r\n/g, "\n").split("\n");
28
+ const out: string[] = [];
29
+ let title = "";
30
+ let i = 0;
31
+ const cells = (row: string) => row.trim().replace(/^\||\|$/g, "").split(/(?<!\\)\|/).map((c) => inline(c.trim().replace(/\\\|/g, "|")));
32
+ while (i < lines.length) {
33
+ const line = lines[i]!;
34
+ if (!line.trim()) { i++; continue; }
35
+ const fence = /^```(\w*)/.exec(line);
36
+ if (fence) {
37
+ const body: string[] = [];
38
+ for (i++; i < lines.length && !lines[i]!.startsWith("```"); i++) body.push(lines[i]!);
39
+ i++;
40
+ out.push(`<pre><code${fence[1] ? ` class="language-${fence[1]}"` : ""}>${escape(body.join("\n"))}</code></pre>`);
41
+ continue;
42
+ }
43
+ const heading = /^(#{1,6})\s+(.*)$/.exec(line);
44
+ if (heading) {
45
+ const text = inline(heading[2]!);
46
+ if (!title && heading[1]!.length === 1) title = heading[2]!.replace(/[*`]/g, "");
47
+ out.push(`<h${heading[1]!.length} id="${slug(text)}">${text}</h${heading[1]!.length}>`);
48
+ i++;
49
+ continue;
50
+ }
51
+ if (line.startsWith("|") && /^\|?\s*:?-+/.test(lines[i + 1] ?? "")) {
52
+ const head = cells(line);
53
+ const rows: string[][] = [];
54
+ for (i += 2; i < lines.length && lines[i]!.startsWith("|"); i++) rows.push(cells(lines[i]!));
55
+ out.push(`<table><thead><tr>${head.map((c) => `<th>${c}</th>`).join("")}</tr></thead><tbody>${rows.map((r) => `<tr>${r.map((c) => `<td>${c}</td>`).join("")}</tr>`).join("")}</tbody></table>`);
56
+ continue;
57
+ }
58
+ if (line.startsWith(">")) {
59
+ const body: string[] = [];
60
+ for (; i < lines.length && lines[i]!.startsWith(">"); i++) body.push(lines[i]!.replace(/^>\s?/, ""));
61
+ out.push(`<blockquote>${markdown(body.join("\n")).html}</blockquote>`);
62
+ continue;
63
+ }
64
+ const item = /^(\s*)([-*]|\d+\.)\s+/;
65
+ if (item.test(line)) {
66
+ const ordered = /^\s*\d+\./.test(line);
67
+ const items: string[] = [];
68
+ for (; i < lines.length; i++) {
69
+ const l = lines[i]!;
70
+ if (item.test(l)) items.push(l.replace(item, ""));
71
+ else if (l.trim() && /^\s{2,}/.test(l) && items.length) items[items.length - 1] += ` ${l.trim()}`;
72
+ else break;
73
+ }
74
+ const tag = ordered ? "ol" : "ul";
75
+ out.push(`<${tag}>${items.map((t) => `<li>${inline(t)}</li>`).join("")}</${tag}>`);
76
+ continue;
77
+ }
78
+ // A paragraph: lines up to a blank one or the start of another block (always at least one).
79
+ const para: string[] = [lines[i++]!.trim()];
80
+ for (; i < lines.length && lines[i]!.trim() && !/^(#{1,6}\s|```|\||>|\s*([-*]|\d+\.)\s)/.test(lines[i]!); i++) para.push(lines[i]!.trim());
81
+ out.push(`<p>${inline(para.join(" "))}</p>`);
82
+ }
83
+ return { html: out.join("\n"), title };
84
+ }
@@ -0,0 +1,34 @@
1
+ import { type ResourceManager, type ViewFile } from "../packages/sci/src/index.ts";
2
+ /**
3
+ * A view described by a JSON manifest next to its PNGs:
4
+ *
5
+ * { "view": 701, "palette": "shared" | { "pic": 701 }, "dither": false,
6
+ * "loops": [
7
+ * { "cels": [{ "png": "wisp-0.png", "anchor": [8, 15] }, ...] }, // own cels
8
+ * { "link": 0, "mirror": true } // loop 0, flipped
9
+ * ] }
10
+ *
11
+ * `anchor` is the pixel placed at the object's x,y (default: bottom centre). "shared" uses
12
+ * only the colours every room shares (characters, items); { "pic": n } may also use room
13
+ * n's own colours (its props). Alpha 64-191 becomes a shadow pixel.
14
+ */
15
+ export interface ViewManifest {
16
+ view: number;
17
+ palette: "shared" | {
18
+ pic: number;
19
+ };
20
+ dither?: boolean;
21
+ loops: ({
22
+ cels: {
23
+ png: string;
24
+ anchor?: [number, number];
25
+ }[];
26
+ } | {
27
+ link: number;
28
+ mirror?: boolean;
29
+ })[];
30
+ }
31
+ export declare function viewFromManifest(path: string, rm: ResourceManager): Promise<{
32
+ number: number;
33
+ view: ViewFile;
34
+ }>;
@@ -0,0 +1,47 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { ROOM_COLORS, ResourceType, SHARED_COLORS, hunkToPalette, mapToPalette, mergePalette, parsePicFile, } from "../packages/sci/src/index.js";
4
+ import { basePalette } from "./pic-build.js";
5
+ import { decodePng } from "./png.js";
6
+ const SKIP = 255;
7
+ export async function viewFromManifest(path, rm) {
8
+ const m = JSON.parse(readFileSync(path, "utf8"));
9
+ const base = await basePalette(rm);
10
+ let palette = base, indices = SHARED_COLORS;
11
+ if (m.palette !== "shared") {
12
+ const pic = parsePicFile((await rm.load({ type: ResourceType.Pic, number: m.palette.pic })).data);
13
+ palette = mergePalette(base, hunkToPalette(pic.palette));
14
+ indices = ROOM_COLORS;
15
+ }
16
+ const loops = m.loops.map((l) => {
17
+ if ("link" in l)
18
+ return { link: l.link, mirror: !!l.mirror, cels: [] };
19
+ return {
20
+ link: -1,
21
+ mirror: false,
22
+ cels: l.cels.map((c) => {
23
+ const img = decodePng(readFileSync(join(dirname(path), c.png)));
24
+ const [ax, ay] = c.anchor ?? [img.width >> 1, img.height - 1];
25
+ return {
26
+ width: img.width, height: img.height,
27
+ displaceX: (img.width >> 1) - ax, displaceY: img.height - 1 - ay,
28
+ skipColor: SKIP,
29
+ pixels: mapToPalette(img.data, img.width, img.height, palette, indices, SKIP, !!m.dither),
30
+ };
31
+ }),
32
+ };
33
+ });
34
+ // The view carries the entries it may use, with the same colours as the rooms have them.
35
+ const used = [...indices, 253, 254].sort((a, b) => a - b);
36
+ const first = used[0], last = used.at(-1);
37
+ const hunk = {
38
+ header: Uint8Array.from([14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]),
39
+ entryPrefix: Uint8Array.from([0, 255, 255, 255, 255, 255, 255, 255, 0, 0]),
40
+ first,
41
+ used: Array.from({ length: last - first + 1 }, (_, i) => (used.includes(first + i) ? 1 : 0)),
42
+ rgb: Array.from({ length: last - first + 1 }, (_, i) => [palette.rgb[(first + i) * 3], palette.rgb[(first + i) * 3 + 1], palette.rgb[(first + i) * 3 + 2]]),
43
+ shared: false,
44
+ defaultUsed: 1,
45
+ };
46
+ return { number: m.view, view: { flags: 1, loops, palette: hunk } };
47
+ }
@@ -0,0 +1,71 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import {
4
+ ROOM_COLORS, ResourceType, SHARED_COLORS, hunkToPalette, mapToPalette, mergePalette, parsePicFile, type HunkPaletteFile,
5
+ type ResourceManager, type ViewFile, type ViewLoop,
6
+ } from "../packages/sci/src/index.ts";
7
+ import { basePalette } from "./pic-build.ts";
8
+ import { decodePng } from "./png.ts";
9
+
10
+ /**
11
+ * A view described by a JSON manifest next to its PNGs:
12
+ *
13
+ * { "view": 701, "palette": "shared" | { "pic": 701 }, "dither": false,
14
+ * "loops": [
15
+ * { "cels": [{ "png": "wisp-0.png", "anchor": [8, 15] }, ...] }, // own cels
16
+ * { "link": 0, "mirror": true } // loop 0, flipped
17
+ * ] }
18
+ *
19
+ * `anchor` is the pixel placed at the object's x,y (default: bottom centre). "shared" uses
20
+ * only the colours every room shares (characters, items); { "pic": n } may also use room
21
+ * n's own colours (its props). Alpha 64-191 becomes a shadow pixel.
22
+ */
23
+ export interface ViewManifest {
24
+ view: number;
25
+ palette: "shared" | { pic: number };
26
+ dither?: boolean;
27
+ loops: ({ cels: { png: string; anchor?: [number, number] }[] } | { link: number; mirror?: boolean })[];
28
+ }
29
+
30
+ const SKIP = 255;
31
+
32
+ export async function viewFromManifest(path: string, rm: ResourceManager): Promise<{ number: number; view: ViewFile }> {
33
+ const m = JSON.parse(readFileSync(path, "utf8")) as ViewManifest;
34
+ const base = await basePalette(rm);
35
+ let palette = base, indices = SHARED_COLORS;
36
+ if (m.palette !== "shared") {
37
+ const pic = parsePicFile((await rm.load({ type: ResourceType.Pic, number: m.palette.pic })).data);
38
+ palette = mergePalette(base, hunkToPalette(pic.palette));
39
+ indices = ROOM_COLORS;
40
+ }
41
+ const loops: ViewLoop[] = m.loops.map((l) => {
42
+ if ("link" in l) return { link: l.link, mirror: !!l.mirror, cels: [] };
43
+ return {
44
+ link: -1,
45
+ mirror: false,
46
+ cels: l.cels.map((c) => {
47
+ const img = decodePng(readFileSync(join(dirname(path), c.png)));
48
+ const [ax, ay] = c.anchor ?? [img.width >> 1, img.height - 1];
49
+ return {
50
+ width: img.width, height: img.height,
51
+ displaceX: (img.width >> 1) - ax, displaceY: img.height - 1 - ay,
52
+ skipColor: SKIP,
53
+ pixels: mapToPalette(img.data, img.width, img.height, palette, indices, SKIP, !!m.dither),
54
+ };
55
+ }),
56
+ };
57
+ });
58
+ // The view carries the entries it may use, with the same colours as the rooms have them.
59
+ const used = [...indices, 253, 254].sort((a, b) => a - b);
60
+ const first = used[0]!, last = used.at(-1)!;
61
+ const hunk: HunkPaletteFile = {
62
+ header: Uint8Array.from([14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]),
63
+ entryPrefix: Uint8Array.from([0, 255, 255, 255, 255, 255, 255, 255, 0, 0]),
64
+ first,
65
+ used: Array.from({ length: last - first + 1 }, (_, i) => (used.includes(first + i) ? 1 : 0)),
66
+ rgb: Array.from({ length: last - first + 1 }, (_, i) => [palette.rgb[(first + i) * 3]!, palette.rgb[(first + i) * 3 + 1]!, palette.rgb[(first + i) * 3 + 2]!]),
67
+ shared: false,
68
+ defaultUsed: 1,
69
+ };
70
+ return { number: m.view, view: { flags: 1, loops, palette: hunk } };
71
+ }
@@ -0,0 +1 @@
1
+ export {};
package/tools/view.js ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Views (sprites and animations).
3
+ * pnpm view export <n> [dir] loop<L>-cel<C>.png + view.json (a manifest you can edit)
4
+ * pnpm view import <view.json> [dir] build the view → <n>.V56
5
+ * pnpm view roundtrip parse + write every view, compare bytes
6
+ */
7
+ import { mkdirSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { ResourceManager, ResourceType, celToRgba, hunkToPalette, mergePalette, parseViewFile, writeView } from "../packages/sci/src/index.js";
10
+ import { nodeFiles } from "./node-files.js";
11
+ import { writePatch } from "./patches.js";
12
+ import { basePalette } from "./pic-build.js";
13
+ import { rgbaPng } from "./png.js";
14
+ import { viewFromManifest } from "./view-build.js";
15
+ const [command = "roundtrip", ...args] = process.argv.slice(2);
16
+ const rm = await ResourceManager.open(nodeFiles(process.env.SCI_GAME ?? "original"));
17
+ if (command === "export") {
18
+ const n = Number(args[0]);
19
+ const dir = args[1] ?? `out/views/${n}`;
20
+ mkdirSync(dir, { recursive: true });
21
+ const view = parseViewFile((await rm.load({ type: ResourceType.View, number: n })).data);
22
+ const palette = mergePalette(await basePalette(rm), view.palette ? hunkToPalette(view.palette) : undefined);
23
+ const manifest = { view: n, palette: "shared", loops: [] };
24
+ view.loops.forEach((loop, l) => {
25
+ if (loop.link !== -1)
26
+ return manifest.loops.push({ link: loop.link, mirror: loop.mirror });
27
+ manifest.loops.push({
28
+ cels: loop.cels.map((cel, c) => {
29
+ const png = `loop${l}-cel${c}.png`;
30
+ // Shadows (remap 254) come out half-transparent black, the way import reads them.
31
+ const rgba = new Uint8Array(celToRgba(cel, palette, { remap: new Map([[253, 128], [254, 128]]) }).buffer);
32
+ writeFileSync(join(dir, png), rgbaPng({ width: cel.width, height: cel.height, data: rgba }));
33
+ return { png, anchor: [(cel.width >> 1) - cel.displaceX, cel.height - 1 - cel.displaceY] };
34
+ }),
35
+ });
36
+ });
37
+ writeFileSync(join(dir, "view.json"), `${JSON.stringify(manifest, null, 1)}\n`);
38
+ console.log(`view ${n}: ${view.loops.length} loops → ${dir}`);
39
+ }
40
+ else if (command === "import") {
41
+ const { number, view } = await viewFromManifest(args[0], rm);
42
+ writePatch(args[1] ?? "out/views", ResourceType.View, number, writeView(view));
43
+ }
44
+ else {
45
+ const list = rm.list(ResourceType.View);
46
+ const bad = [];
47
+ for (const info of list) {
48
+ const d = Buffer.from((await rm.load(info)).data);
49
+ if (d.compare(Buffer.from(writeView(parseViewFile(d)))))
50
+ bad.push(info.number);
51
+ }
52
+ console.log(`${list.length - bad.length}/${list.length} views round-trip byte-exact${bad.length ? `; differ: ${bad.join(" ")}` : ""}`);
53
+ process.exitCode = bad.length ? 1 : 0;
54
+ }
package/tools/view.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Views (sprites and animations).
3
+ * pnpm view export <n> [dir] loop<L>-cel<C>.png + view.json (a manifest you can edit)
4
+ * pnpm view import <view.json> [dir] build the view → <n>.V56
5
+ * pnpm view roundtrip parse + write every view, compare bytes
6
+ */
7
+ import { mkdirSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { ResourceManager, ResourceType, celToRgba, hunkToPalette, mergePalette, parseViewFile, writeView } from "../packages/sci/src/index.ts";
10
+ import { nodeFiles } from "./node-files.ts";
11
+ import { writePatch } from "./patches.ts";
12
+ import { basePalette } from "./pic-build.ts";
13
+ import { rgbaPng } from "./png.ts";
14
+ import { viewFromManifest, type ViewManifest } from "./view-build.ts";
15
+
16
+ const [command = "roundtrip", ...args] = process.argv.slice(2);
17
+ const rm = await ResourceManager.open(nodeFiles(process.env.SCI_GAME ?? "original"));
18
+
19
+ if (command === "export") {
20
+ const n = Number(args[0]);
21
+ const dir = args[1] ?? `out/views/${n}`;
22
+ mkdirSync(dir, { recursive: true });
23
+ const view = parseViewFile((await rm.load({ type: ResourceType.View, number: n })).data);
24
+ const palette = mergePalette(await basePalette(rm), view.palette ? hunkToPalette(view.palette) : undefined);
25
+ const manifest: ViewManifest = { view: n, palette: "shared", loops: [] };
26
+ view.loops.forEach((loop, l) => {
27
+ if (loop.link !== -1) return manifest.loops.push({ link: loop.link, mirror: loop.mirror });
28
+ manifest.loops.push({
29
+ cels: loop.cels.map((cel, c) => {
30
+ const png = `loop${l}-cel${c}.png`;
31
+ // Shadows (remap 254) come out half-transparent black, the way import reads them.
32
+ const rgba = new Uint8Array(celToRgba(cel, palette, { remap: new Map([[253, 128], [254, 128]]) }).buffer);
33
+ writeFileSync(join(dir, png), rgbaPng({ width: cel.width, height: cel.height, data: rgba }));
34
+ return { png, anchor: [(cel.width >> 1) - cel.displaceX, cel.height - 1 - cel.displaceY] as [number, number] };
35
+ }),
36
+ });
37
+ });
38
+ writeFileSync(join(dir, "view.json"), `${JSON.stringify(manifest, null, 1)}\n`);
39
+ console.log(`view ${n}: ${view.loops.length} loops → ${dir}`);
40
+ } else if (command === "import") {
41
+ const { number, view } = await viewFromManifest(args[0]!, rm);
42
+ writePatch(args[1] ?? "out/views", ResourceType.View, number, writeView(view));
43
+ } else {
44
+ const list = rm.list(ResourceType.View);
45
+ const bad: number[] = [];
46
+ for (const info of list) {
47
+ const d = Buffer.from((await rm.load(info)).data);
48
+ if (d.compare(Buffer.from(writeView(parseViewFile(d))))) bad.push(info.number);
49
+ }
50
+ console.log(`${list.length - bad.length}/${list.length} views round-trip byte-exact${bad.length ? `; differ: ${bad.join(" ")}` : ""}`);
51
+ process.exitCode = bad.length ? 1 : 0;
52
+ }