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.
- package/CHANGELOG.md +78 -0
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/apps/viewer/editor.html +43 -0
- package/apps/viewer/explore.html +27 -0
- package/apps/viewer/index.html +26 -0
- package/apps/viewer/package.json +27 -0
- package/apps/viewer/play.html +26 -0
- package/apps/viewer/plugin.d.ts +18 -0
- package/apps/viewer/plugin.js +75 -0
- package/apps/viewer/plugin.ts +84 -0
- package/apps/viewer/src/adlib.d.ts +20 -0
- package/apps/viewer/src/adlib.js +55 -0
- package/apps/viewer/src/adlib.ts +62 -0
- package/apps/viewer/src/app.d.ts +5 -0
- package/apps/viewer/src/app.js +5 -0
- package/apps/viewer/src/app.ts +5 -0
- package/apps/viewer/src/asset-index.d.ts +22 -0
- package/apps/viewer/src/asset-index.js +74 -0
- package/apps/viewer/src/asset-index.ts +90 -0
- package/apps/viewer/src/audio.d.ts +28 -0
- package/apps/viewer/src/audio.js +102 -0
- package/apps/viewer/src/audio.ts +110 -0
- package/apps/viewer/src/editor-handles.d.ts +63 -0
- package/apps/viewer/src/editor-handles.js +332 -0
- package/apps/viewer/src/editor-handles.ts +368 -0
- package/apps/viewer/src/editor-languages.d.ts +23 -0
- package/apps/viewer/src/editor-languages.js +157 -0
- package/apps/viewer/src/editor-languages.ts +135 -0
- package/apps/viewer/src/editor.css +213 -0
- package/apps/viewer/src/editor.d.ts +1 -0
- package/apps/viewer/src/editor.js +393 -0
- package/apps/viewer/src/editor.ts +412 -0
- package/apps/viewer/src/explore/classes.d.ts +7 -0
- package/apps/viewer/src/explore/classes.js +63 -0
- package/apps/viewer/src/explore/classes.ts +61 -0
- package/apps/viewer/src/explore/context.d.ts +33 -0
- package/apps/viewer/src/explore/context.js +96 -0
- package/apps/viewer/src/explore/context.ts +124 -0
- package/apps/viewer/src/explore/explore.css +93 -0
- package/apps/viewer/src/explore/explore.d.ts +1 -0
- package/apps/viewer/src/explore/explore.js +102 -0
- package/apps/viewer/src/explore/explore.ts +104 -0
- package/apps/viewer/src/explore/inspect.d.ts +5 -0
- package/apps/viewer/src/explore/inspect.js +208 -0
- package/apps/viewer/src/explore/inspect.ts +279 -0
- package/apps/viewer/src/explore/live.d.ts +22 -0
- package/apps/viewer/src/explore/live.js +318 -0
- package/apps/viewer/src/explore/live.ts +365 -0
- package/apps/viewer/src/explore/map.d.ts +11 -0
- package/apps/viewer/src/explore/map.js +182 -0
- package/apps/viewer/src/explore/map.ts +193 -0
- package/apps/viewer/src/files.d.ts +21 -0
- package/apps/viewer/src/files.js +69 -0
- package/apps/viewer/src/files.ts +72 -0
- package/apps/viewer/src/game-profile.d.ts +19 -0
- package/apps/viewer/src/game-profile.js +4 -0
- package/apps/viewer/src/game-profile.ts +26 -0
- package/apps/viewer/src/main.d.ts +1 -0
- package/apps/viewer/src/main.js +473 -0
- package/apps/viewer/src/main.ts +527 -0
- package/apps/viewer/src/music.d.ts +14 -0
- package/apps/viewer/src/music.js +32 -0
- package/apps/viewer/src/music.ts +34 -0
- package/apps/viewer/src/opl-worklet.d.ts +1 -0
- package/apps/viewer/src/opl-worklet.js +47 -0
- package/apps/viewer/src/opl-worklet.ts +55 -0
- package/apps/viewer/src/overlay.d.ts +31 -0
- package/apps/viewer/src/overlay.js +103 -0
- package/apps/viewer/src/overlay.ts +123 -0
- package/apps/viewer/src/play.css +14 -0
- package/apps/viewer/src/play.d.ts +1 -0
- package/apps/viewer/src/play.js +179 -0
- package/apps/viewer/src/play.ts +177 -0
- package/apps/viewer/src/saves.d.ts +10 -0
- package/apps/viewer/src/saves.js +50 -0
- package/apps/viewer/src/saves.ts +51 -0
- package/apps/viewer/src/session.d.ts +91 -0
- package/apps/viewer/src/session.js +301 -0
- package/apps/viewer/src/session.ts +321 -0
- package/apps/viewer/src/sound-preview.d.ts +7 -0
- package/apps/viewer/src/sound-preview.js +214 -0
- package/apps/viewer/src/sound-preview.ts +228 -0
- package/apps/viewer/src/style.css +64 -0
- package/apps/viewer/vite.config.ts +25 -0
- package/bin/sci-ts.mjs +9 -0
- package/lib/994.sc +49 -0
- package/lib/995.sc +53 -0
- package/lib/996.sc +299 -0
- package/lib/997.sc +198 -0
- package/lib/998.sc +338 -0
- package/lib/999.sc +189 -0
- package/lib/resources.d.ts +2 -0
- package/lib/resources.js +84 -0
- package/lib/resources.ts +88 -0
- package/lib/system.sh +62 -0
- package/package.json +75 -4
- package/packages/content/room.schema.json +267 -0
- package/packages/content/src/index.d.ts +3 -0
- package/packages/content/src/index.js +3 -0
- package/packages/content/src/index.ts +3 -0
- package/packages/content/src/room.d.ts +111 -0
- package/packages/content/src/room.js +886 -0
- package/packages/content/src/room.ts +1011 -0
- package/packages/content/src/target.d.ts +80 -0
- package/packages/content/src/target.js +1 -0
- package/packages/content/src/target.ts +60 -0
- package/packages/content/src/yarn.d.ts +90 -0
- package/packages/content/src/yarn.js +214 -0
- package/packages/content/src/yarn.ts +261 -0
- package/packages/sci/src/analysis/game.d.ts +90 -0
- package/packages/sci/src/analysis/game.js +221 -0
- package/packages/sci/src/analysis/game.ts +305 -0
- package/packages/sci/src/analysis/runtime.d.ts +58 -0
- package/packages/sci/src/analysis/runtime.js +133 -0
- package/packages/sci/src/analysis/runtime.ts +163 -0
- package/packages/sci/src/audio/adlib.d.ts +73 -0
- package/packages/sci/src/audio/adlib.js +280 -0
- package/packages/sci/src/audio/adlib.ts +329 -0
- package/packages/sci/src/audio/index.d.ts +43 -0
- package/packages/sci/src/audio/index.js +99 -0
- package/packages/sci/src/audio/index.ts +122 -0
- package/packages/sci/src/audio/midi.d.ts +92 -0
- package/packages/sci/src/audio/midi.js +242 -0
- package/packages/sci/src/audio/midi.ts +262 -0
- package/packages/sci/src/audio/opl2.d.ts +74 -0
- package/packages/sci/src/audio/opl2.js +283 -0
- package/packages/sci/src/audio/opl2.ts +283 -0
- package/packages/sci/src/audio/sol.d.ts +32 -0
- package/packages/sci/src/audio/sol.js +81 -0
- package/packages/sci/src/audio/sol.ts +100 -0
- package/packages/sci/src/audio/write.d.ts +35 -0
- package/packages/sci/src/audio/write.js +91 -0
- package/packages/sci/src/audio/write.ts +108 -0
- package/packages/sci/src/gfx/cel.d.ts +36 -0
- package/packages/sci/src/gfx/cel.js +82 -0
- package/packages/sci/src/gfx/cel.ts +110 -0
- package/packages/sci/src/gfx/palette.d.ts +24 -0
- package/packages/sci/src/gfx/palette.js +49 -0
- package/packages/sci/src/gfx/palette.ts +56 -0
- package/packages/sci/src/gfx/pic-file.d.ts +46 -0
- package/packages/sci/src/gfx/pic-file.js +114 -0
- package/packages/sci/src/gfx/pic-file.ts +155 -0
- package/packages/sci/src/gfx/pic.d.ts +27 -0
- package/packages/sci/src/gfx/pic.js +34 -0
- package/packages/sci/src/gfx/pic.ts +53 -0
- package/packages/sci/src/gfx/quantize.d.ts +42 -0
- package/packages/sci/src/gfx/quantize.js +199 -0
- package/packages/sci/src/gfx/quantize.ts +218 -0
- package/packages/sci/src/gfx/view-file.d.ts +62 -0
- package/packages/sci/src/gfx/view-file.js +182 -0
- package/packages/sci/src/gfx/view-file.ts +233 -0
- package/packages/sci/src/gfx/view.d.ts +28 -0
- package/packages/sci/src/gfx/view.js +45 -0
- package/packages/sci/src/gfx/view.ts +62 -0
- package/packages/sci/src/index.d.ts +38 -0
- package/packages/sci/src/index.js +38 -0
- package/packages/sci/src/index.ts +38 -0
- package/packages/sci/src/motion/pathfinding.d.ts +40 -0
- package/packages/sci/src/motion/pathfinding.js +140 -0
- package/packages/sci/src/motion/pathfinding.ts +147 -0
- package/packages/sci/src/resource/archive.d.ts +16 -0
- package/packages/sci/src/resource/archive.js +51 -0
- package/packages/sci/src/resource/archive.ts +56 -0
- package/packages/sci/src/resource/lzs.d.ts +12 -0
- package/packages/sci/src/resource/lzs.js +64 -0
- package/packages/sci/src/resource/lzs.ts +66 -0
- package/packages/sci/src/resource/manager.d.ts +45 -0
- package/packages/sci/src/resource/manager.js +158 -0
- package/packages/sci/src/resource/manager.ts +184 -0
- package/packages/sci/src/resource/map.d.ts +18 -0
- package/packages/sci/src/resource/map.js +34 -0
- package/packages/sci/src/resource/map.ts +44 -0
- package/packages/sci/src/resource/types.d.ts +37 -0
- package/packages/sci/src/resource/types.js +45 -0
- package/packages/sci/src/resource/types.ts +57 -0
- package/packages/sci/src/script/assembly.d.ts +67 -0
- package/packages/sci/src/script/assembly.js +748 -0
- package/packages/sci/src/script/assembly.ts +714 -0
- package/packages/sci/src/script/compiler.d.ts +75 -0
- package/packages/sci/src/script/compiler.js +993 -0
- package/packages/sci/src/script/compiler.ts +1040 -0
- package/packages/sci/src/script/disasm.d.ts +81 -0
- package/packages/sci/src/script/disasm.js +318 -0
- package/packages/sci/src/script/disasm.ts +323 -0
- package/packages/sci/src/script/kernel-names.d.ts +6 -0
- package/packages/sci/src/script/kernel-names.js +165 -0
- package/packages/sci/src/script/kernel-names.ts +165 -0
- package/packages/sci/src/script/opcodes.d.ts +22 -0
- package/packages/sci/src/script/opcodes.js +45 -0
- package/packages/sci/src/script/opcodes.ts +72 -0
- package/packages/sci/src/script/script.d.ts +56 -0
- package/packages/sci/src/script/script.js +63 -0
- package/packages/sci/src/script/script.ts +111 -0
- package/packages/sci/src/script/sexpr.d.ts +45 -0
- package/packages/sci/src/script/sexpr.js +151 -0
- package/packages/sci/src/script/sexpr.ts +139 -0
- package/packages/sci/src/script/vocab.d.ts +15 -0
- package/packages/sci/src/script/vocab.js +44 -0
- package/packages/sci/src/script/vocab.ts +48 -0
- package/packages/sci/src/script/world.d.ts +25 -0
- package/packages/sci/src/script/world.js +65 -0
- package/packages/sci/src/script/world.ts +70 -0
- package/packages/sci/src/text/font.d.ts +37 -0
- package/packages/sci/src/text/font.js +103 -0
- package/packages/sci/src/text/font.ts +125 -0
- package/packages/sci/src/text/message.d.ts +69 -0
- package/packages/sci/src/text/message.js +171 -0
- package/packages/sci/src/text/message.ts +205 -0
- package/packages/sci/src/vm/kernels/arrays.d.ts +19 -0
- package/packages/sci/src/vm/kernels/arrays.js +182 -0
- package/packages/sci/src/vm/kernels/arrays.ts +164 -0
- package/packages/sci/src/vm/kernels/audio.d.ts +70 -0
- package/packages/sci/src/vm/kernels/audio.js +347 -0
- package/packages/sci/src/vm/kernels/audio.ts +349 -0
- package/packages/sci/src/vm/kernels/core.d.ts +5 -0
- package/packages/sci/src/vm/kernels/core.js +87 -0
- package/packages/sci/src/vm/kernels/core.ts +91 -0
- package/packages/sci/src/vm/kernels/graphics.d.ts +141 -0
- package/packages/sci/src/vm/kernels/graphics.js +467 -0
- package/packages/sci/src/vm/kernels/graphics.ts +502 -0
- package/packages/sci/src/vm/kernels/index.d.ts +8 -0
- package/packages/sci/src/vm/kernels/index.js +29 -0
- package/packages/sci/src/vm/kernels/index.ts +32 -0
- package/packages/sci/src/vm/kernels/lists.d.ts +6 -0
- package/packages/sci/src/vm/kernels/lists.js +127 -0
- package/packages/sci/src/vm/kernels/lists.ts +111 -0
- package/packages/sci/src/vm/kernels/motion.d.ts +7 -0
- package/packages/sci/src/vm/kernels/motion.js +204 -0
- package/packages/sci/src/vm/kernels/motion.ts +194 -0
- package/packages/sci/src/vm/kernels/palette.d.ts +82 -0
- package/packages/sci/src/vm/kernels/palette.js +292 -0
- package/packages/sci/src/vm/kernels/palette.ts +303 -0
- package/packages/sci/src/vm/kernels/saves.d.ts +45 -0
- package/packages/sci/src/vm/kernels/saves.js +123 -0
- package/packages/sci/src/vm/kernels/saves.ts +149 -0
- package/packages/sci/src/vm/kernels/system.d.ts +62 -0
- package/packages/sci/src/vm/kernels/system.js +110 -0
- package/packages/sci/src/vm/kernels/system.ts +128 -0
- package/packages/sci/src/vm/kernels/text.d.ts +13 -0
- package/packages/sci/src/vm/kernels/text.js +338 -0
- package/packages/sci/src/vm/kernels/text.ts +328 -0
- package/packages/sci/src/vm/memory.d.ts +138 -0
- package/packages/sci/src/vm/memory.js +168 -0
- package/packages/sci/src/vm/memory.ts +266 -0
- package/packages/sci/src/vm/replace.d.ts +11 -0
- package/packages/sci/src/vm/replace.js +14 -0
- package/packages/sci/src/vm/replace.ts +16 -0
- package/packages/sci/src/vm/savegame.d.ts +89 -0
- package/packages/sci/src/vm/savegame.js +161 -0
- package/packages/sci/src/vm/savegame.ts +188 -0
- package/packages/sci/src/vm/value.d.ts +17 -0
- package/packages/sci/src/vm/value.js +12 -0
- package/packages/sci/src/vm/value.ts +25 -0
- package/packages/sci/src/vm/vm.d.ts +155 -0
- package/packages/sci/src/vm/vm.js +1053 -0
- package/packages/sci/src/vm/vm.ts +914 -0
- package/tools/adlib-render.d.ts +1 -0
- package/tools/adlib-render.js +49 -0
- package/tools/adlib-render.ts +42 -0
- package/tools/analyze.d.ts +1 -0
- package/tools/analyze.js +25 -0
- package/tools/analyze.ts +25 -0
- package/tools/art/build.d.ts +34 -0
- package/tools/art/build.js +175 -0
- package/tools/art/build.ts +153 -0
- package/tools/art.d.ts +1 -0
- package/tools/art.js +31 -0
- package/tools/art.ts +29 -0
- package/tools/asm.d.ts +1 -0
- package/tools/asm.js +61 -0
- package/tools/asm.ts +55 -0
- package/tools/cli.d.ts +1 -0
- package/tools/cli.js +99 -0
- package/tools/cli.ts +100 -0
- package/tools/editor-server.d.ts +29 -0
- package/tools/editor-server.js +162 -0
- package/tools/editor-server.ts +176 -0
- package/tools/explore.d.ts +1 -0
- package/tools/explore.js +305 -0
- package/tools/explore.ts +250 -0
- package/tools/game/audio.d.ts +19 -0
- package/tools/game/audio.js +143 -0
- package/tools/game/audio.ts +130 -0
- package/tools/game/build.d.ts +46 -0
- package/tools/game/build.js +259 -0
- package/tools/game/build.ts +283 -0
- package/tools/game/defaults.d.ts +26 -0
- package/tools/game/defaults.js +82 -0
- package/tools/game/defaults.ts +83 -0
- package/tools/game/font.d.ts +3 -0
- package/tools/game/font.js +124 -0
- package/tools/game/font.ts +126 -0
- package/tools/game/kit.d.ts +7 -0
- package/tools/game/kit.js +7 -0
- package/tools/game/kit.ts +10 -0
- package/tools/game/new.d.ts +8 -0
- package/tools/game/new.js +39 -0
- package/tools/game/new.ts +38 -0
- package/tools/game/target.d.ts +7 -0
- package/tools/game/target.js +41 -0
- package/tools/game/target.ts +42 -0
- package/tools/game/template/resources.ts.tmpl +43 -0
- package/tools/game/template/rooms/1.room.yaml +9 -0
- package/tools/game/template/rooms/1.yarn +17 -0
- package/tools/game/template/scripts/0.sc +24 -0
- package/tools/game.d.ts +1 -0
- package/tools/game.js +77 -0
- package/tools/game.ts +70 -0
- package/tools/mod-build.d.ts +28 -0
- package/tools/mod-build.js +173 -0
- package/tools/mod-build.ts +179 -0
- package/tools/mod-target.d.ts +16 -0
- package/tools/mod-target.js +26 -0
- package/tools/mod-target.ts +32 -0
- package/tools/mod.d.ts +1 -0
- package/tools/mod.js +47 -0
- package/tools/mod.ts +45 -0
- package/tools/msg.d.ts +1 -0
- package/tools/msg.js +40 -0
- package/tools/msg.ts +36 -0
- package/tools/node-files.d.ts +3 -0
- package/tools/node-files.js +34 -0
- package/tools/node-files.ts +33 -0
- package/tools/patches.d.ts +3 -0
- package/tools/patches.js +13 -0
- package/tools/patches.ts +13 -0
- package/tools/pic-build.d.ts +9 -0
- package/tools/pic-build.js +26 -0
- package/tools/pic-build.ts +27 -0
- package/tools/pic.d.ts +1 -0
- package/tools/pic.js +64 -0
- package/tools/pic.ts +61 -0
- package/tools/play.d.ts +1 -0
- package/tools/play.js +54 -0
- package/tools/play.ts +54 -0
- package/tools/png.d.ts +16 -0
- package/tools/png.js +124 -0
- package/tools/png.ts +123 -0
- package/tools/res.d.ts +1 -0
- package/tools/res.js +48 -0
- package/tools/res.ts +50 -0
- package/tools/scenario.d.ts +1 -0
- package/tools/scenario.js +74 -0
- package/tools/scenario.ts +80 -0
- package/tools/site/build.d.ts +8 -0
- package/tools/site/build.js +110 -0
- package/tools/site/build.ts +116 -0
- package/tools/site/markdown.d.ts +11 -0
- package/tools/site/markdown.js +88 -0
- package/tools/site/markdown.ts +84 -0
- package/tools/view-build.d.ts +34 -0
- package/tools/view-build.js +47 -0
- package/tools/view-build.ts +71 -0
- package/tools/view.d.ts +1 -0
- package/tools/view.js +54 -0
- 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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
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
|
+
}
|
package/tools/view.d.ts
ADDED
|
@@ -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
|
+
}
|