@team-antioch/sc2-adjutant 0.1.0 → 0.1.1

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 (149) hide show
  1. package/README.md +2 -0
  2. package/data/blizzard-baseline.json +3061 -0
  3. package/data/button-hotkeys.json +5722 -0
  4. package/data/game-assets.json +50909 -0
  5. package/data/package-entries.json +32361 -2
  6. package/dist/capture/bank-fixtures.d.ts +13 -0
  7. package/dist/capture/bank-fixtures.js +35 -0
  8. package/dist/capture/bank-snapshots.d.ts +95 -0
  9. package/dist/capture/bank-snapshots.js +302 -0
  10. package/dist/capture/editor-broker-client.d.ts +27 -4
  11. package/dist/capture/editor-broker-client.js +3 -3
  12. package/dist/capture/editor-broker.js +154 -9
  13. package/dist/capture/effect-tour.d.ts +113 -0
  14. package/dist/capture/effect-tour.js +283 -0
  15. package/dist/capture/effect-video.d.ts +74 -0
  16. package/dist/capture/effect-video.js +173 -0
  17. package/dist/capture/exemplar-capture.d.ts +4 -0
  18. package/dist/capture/exemplar-capture.js +4 -1
  19. package/dist/capture/shots.d.ts +6 -1
  20. package/dist/capture/shots.js +1 -1
  21. package/dist/capture/stop-tour.d.ts +3 -1
  22. package/dist/capture/stop-tour.js +1 -1
  23. package/dist/capture/style-pack-captures.d.ts +67 -0
  24. package/dist/capture/style-pack-captures.js +172 -0
  25. package/dist/catalog/stock-catalog.d.ts +8 -0
  26. package/dist/catalog/stock-catalog.js +13 -0
  27. package/dist/cli/capture-exemplars.js +18 -32
  28. package/dist/cli/effect-tour.d.ts +2 -0
  29. package/dist/cli/effect-tour.js +378 -0
  30. package/dist/cli/make-frames.d.ts +1 -0
  31. package/dist/cli/make-frames.js +21 -0
  32. package/dist/cli/sound-mix.d.ts +1 -0
  33. package/dist/cli/sound-mix.js +75 -0
  34. package/dist/cli/study.js +6 -26
  35. package/dist/domain/blueprint-trigger.d.ts +355 -3
  36. package/dist/domain/blueprint-trigger.js +149 -8
  37. package/dist/domain/library-interface.d.ts +50 -29
  38. package/dist/domain/library-interface.js +54 -41
  39. package/dist/domain/mission-blueprint.d.ts +13 -6
  40. package/dist/domain/mission-blueprint.js +6 -0
  41. package/dist/domain/mod-blueprint.d.ts +4 -4
  42. package/dist/host/game-logs.d.ts +63 -0
  43. package/dist/host/game-logs.js +178 -0
  44. package/dist/host/game-ownership.d.ts +37 -0
  45. package/dist/host/game-ownership.js +84 -0
  46. package/dist/host/game-run-report.d.ts +63 -0
  47. package/dist/host/game-run-report.js +119 -0
  48. package/dist/host/known-errors.d.ts +34 -0
  49. package/dist/host/known-errors.js +73 -0
  50. package/dist/init/init-workspace.d.ts +3 -1
  51. package/dist/init/init-workspace.js +10 -1
  52. package/dist/map/convert-mission-triggers.d.ts +115 -7
  53. package/dist/map/convert-mission-triggers.js +527 -47
  54. package/dist/map/editor-changes.d.ts +1 -1
  55. package/dist/map/editor-form.d.ts +5 -0
  56. package/dist/map/editor-form.js +72 -0
  57. package/dist/map/game-packages.d.ts +3 -2
  58. package/dist/map/game-packages.js +5 -2
  59. package/dist/map/kept-references.js +47 -1
  60. package/dist/map/kept-session.js +3 -1
  61. package/dist/map/outline-diff.d.ts +24 -0
  62. package/dist/map/outline-diff.js +95 -0
  63. package/dist/map/outline-trigger.d.ts +7 -0
  64. package/dist/map/outline-trigger.js +29 -20
  65. package/dist/map/ownership-plan.d.ts +6 -2
  66. package/dist/map/ownership-plan.js +1 -1
  67. package/dist/map/package-output.js +13 -8
  68. package/dist/map/tune-kept-triggers.d.ts +7 -0
  69. package/dist/map/tune-kept-triggers.js +33 -6
  70. package/dist/map/write-blueprint-trigger.d.ts +9 -4
  71. package/dist/map/write-blueprint-trigger.js +46 -13
  72. package/dist/map/write-map-package.js +20 -9
  73. package/dist/mcp/capture-jobs.d.ts +2 -0
  74. package/dist/mcp/capture-jobs.js +2 -0
  75. package/dist/mcp/server.d.ts +11 -2
  76. package/dist/mcp/server.js +17 -4
  77. package/dist/mcp/tools/bank-report.d.ts +19 -0
  78. package/dist/mcp/tools/bank-report.js +51 -0
  79. package/dist/mcp/tools/blueprint.js +18 -14
  80. package/dist/mcp/tools/capture.d.ts +4 -0
  81. package/dist/mcp/tools/capture.js +22 -5
  82. package/dist/mcp/tools/catalog.d.ts +1 -1
  83. package/dist/mcp/tools/catalog.js +30 -1
  84. package/dist/mcp/tools/compile.d.ts +1 -1
  85. package/dist/mcp/tools/compile.js +100 -9
  86. package/dist/mcp/tools/editor-handoff.d.ts +4 -1
  87. package/dist/mcp/tools/editor-handoff.js +6 -3
  88. package/dist/mcp/tools/style-pack.d.ts +11 -0
  89. package/dist/mcp/tools/style-pack.js +245 -0
  90. package/dist/mcp/tools/tool-group.d.ts +9 -0
  91. package/dist/mods/button-hotkeys.d.ts +45 -0
  92. package/dist/mods/button-hotkeys.js +185 -0
  93. package/dist/mods/compile-mod.js +19 -5
  94. package/dist/mods/custom-doodads.d.ts +21 -1
  95. package/dist/mods/custom-doodads.js +53 -7
  96. package/dist/mods/data-rules.js +8 -1
  97. package/dist/mods/effective-entry.d.ts +18 -0
  98. package/dist/mods/effective-entry.js +52 -0
  99. package/dist/mods/function-search.js +12 -0
  100. package/dist/mods/library-xml.d.ts +34 -5
  101. package/dist/mods/library-xml.js +94 -22
  102. package/dist/mods/sound-mix.d.ts +92 -0
  103. package/dist/mods/sound-mix.js +195 -0
  104. package/dist/plugins/check-workspace.js +22 -3
  105. package/dist/plugins/plugin-api.d.ts +59 -5
  106. package/dist/plugins/plugin-api.js +6 -0
  107. package/dist/plugins/plugin-sdk.d.ts +13 -1
  108. package/dist/plugins/plugin-sdk.js +16 -1
  109. package/dist/plugins/plugin-sources.js +1 -0
  110. package/dist/plugins/registry.d.ts +4 -0
  111. package/dist/plugins/registry.js +6 -2
  112. package/dist/plugins/workspace.d.ts +5 -0
  113. package/dist/plugins/workspace.js +10 -2
  114. package/dist/study/blizzard-baseline.d.ts +76 -0
  115. package/dist/study/blizzard-baseline.js +137 -0
  116. package/dist/study/exemplar-report.d.ts +71 -0
  117. package/dist/study/exemplar-report.js +163 -0
  118. package/dist/study/find-places.d.ts +127 -0
  119. package/dist/study/find-places.js +306 -0
  120. package/dist/study/load-map-package.d.ts +3 -0
  121. package/dist/study/load-map-package.js +11 -0
  122. package/dist/study/map-study.d.ts +1 -0
  123. package/dist/study/map-study.js +3 -0
  124. package/dist/study/measure-lighting.d.ts +6 -0
  125. package/dist/study/measure-lighting.js +1 -1
  126. package/dist/study/measures.d.ts +225 -0
  127. package/dist/study/measures.js +366 -0
  128. package/dist/study/scaffold-style-pack.d.ts +58 -0
  129. package/dist/study/scaffold-style-pack.js +261 -0
  130. package/dist/study/study-exemplars.d.ts +67 -0
  131. package/dist/study/study-exemplars.js +133 -0
  132. package/dist/triggers/blueprint-triggers.d.ts +71 -11
  133. package/dist/triggers/blueprint-triggers.js +403 -48
  134. package/dist/triggers/kept-trigger-galaxy.d.ts +29 -0
  135. package/dist/triggers/kept-trigger-galaxy.js +103 -7
  136. package/dist/triggers/splice-map-script.d.ts +2 -0
  137. package/dist/triggers/splice-map-script.js +309 -8
  138. package/dist/triggers/write-triggers-xml.js +20 -5
  139. package/dist/ui/frame-path-check.d.ts +43 -4
  140. package/dist/ui/frame-path-check.js +121 -13
  141. package/dist/ui/frame-paths.d.ts +21 -1
  142. package/dist/ui/frame-paths.js +26 -6
  143. package/dist/ui/toast.d.ts +4 -5
  144. package/dist/ui/toast.js +6 -10
  145. package/examples/example-campaign/README.md +27 -0
  146. package/examples/example-campaign/missions/ashfall-relay/blueprint.json +11 -1
  147. package/examples/example-campaign/missions/ashfall-relay/triggers/ash-tremors.json +69 -0
  148. package/examples/example-campaign/missions/ashfall-relay/triggers/start-ash-tremors.json +31 -0
  149. package/package.json +3 -3
@@ -0,0 +1,378 @@
1
+ // The effect tour (capture/effect-tour.ts): films the game's effect models in the game, for an
2
+ // effects gallery.
3
+ //
4
+ // npm run effect-tour -- base [<folder>]
5
+ // writes a flat test map's Blueprint into <folder> (by default missions/effect-tour, which git
6
+ // ignores) and compiles it there. Every batch map is a copy of it.
7
+ // npm run effect-tour -- make --models <folder> --base <map> --out <folder> [--batch <n>] [--only <regex>] [--limit <n>]
8
+ // reads each Assets/Effects model core's game-models.json names from <folder> (the files
9
+ // extracted from the install with a CASC extractor, as stormex -I 'assets\\effects\\.*\.m3$' -x
10
+ // writes them), plans its frames from its animations and bounds, and writes batch maps of <n>
11
+ // effects each (120 by default) into <out>/batch-NN/, with a manifest of their frames.
12
+ // Glazes are left out: a glaze is a material laid on another model, and draws nothing alone.
13
+ // npm run effect-tour -- make --folder <folder> --base <map> --out <folder> [--batch <n>] [--only <regex>] [--limit <n>]
14
+ // films every .m3 under <folder>/Assets/Effects instead, models not in the game (Heroes of the
15
+ // Storm's, converted for StarCraft II): each batch map imports its models, at their paths under
16
+ // <folder>, and the textures they name, from <folder>/Assets/Textures.
17
+ // npm run effect-tour -- capture <out> [--batches <a>-<b>] [--freeze] [--redo]
18
+ // films each batch through the Editor Broker (Test Document; the game's window is
19
+ // screenshotted at each frame), into <out>/batch-NN/frames/, and writes its index.html. A
20
+ // batch with its index.html is skipped unless --redo, so a stopped run carries on where it was.
21
+ // With --video the game window is recorded too (frames/video.mp4, 1600x900, about 18 MB a minute): each
22
+ // effect gets a clip (clips/<n>.mp4) and the frames where most is on screen (peaks/), for
23
+ // what's over before a screenshot is taken, such as an impact's burst of particles.
24
+ // npm run effect-tour -- pick <out> [--batches <a>-<b>]
25
+ // cuts the clips and picks the frames again from each batch's recording, and rewrites the index
26
+ // of each batch filmed to its end.
27
+ import { existsSync } from "node:fs";
28
+ import { cp, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
29
+ import path from "node:path";
30
+ import { cutEffect, effectSegments, parseVideoStops } from "../capture/effect-video.js";
31
+ import { batchRange, DEFAULT_HOLD, effectModelData, effectTourScript, batchSeconds, EFFECT_TOUR_BANK, EFFECT_TOUR_INIT, EFFECT_TOUR_SCRIPT_ID, planEffectBatch } from "../capture/effect-tour.js";
32
+ import { hideErrorsDuringTest } from "../capture/capture-copy.js";
33
+ import { runBrokeredCapture } from "../capture/editor-broker-client.js";
34
+ import { readM3Footprint } from "../catalog/m3-footprint.js";
35
+ import { readM3Sequences } from "../catalog/m3-sequences.js";
36
+ import { readM3TexturePaths } from "../catalog/m3-textures.js";
37
+ import { loadHost, requireCapability } from "../host/host.js";
38
+ import { loadMachineConfig } from "../host/machine-config.js";
39
+ import { compileMission } from "../map/compile-mission.js";
40
+ import { missionMapPackage } from "../map/mission-package.js";
41
+ import { workspaceFor } from "../plugins/workspace.js";
42
+ import { withCustomScript } from "../triggers/custom-script.js";
43
+ const USAGE = [
44
+ "Usage: effect-tour base [<folder>]",
45
+ " effect-tour make --models <folder> --base <map> --out <folder> [--batch <n>] [--only <regex>] [--limit <n>]",
46
+ " effect-tour capture <out> [--batches <a>-<b>] [--freeze] [--video] [--redo]",
47
+ " effect-tour pick <out> [--batches <a>-<b>]",
48
+ ].join("\n");
49
+ /** Void (Campaign): a few effect files are only in the campaign's own assets, and it brings in Liberty's. */
50
+ const VOID_CAMPAIGN = "bnet:Void (Campaign)/0.0/999,file:Campaigns/Void.SC2Campaign";
51
+ function option(args, name) {
52
+ const index = args.indexOf(`--${name}`);
53
+ if (index < 0)
54
+ return undefined;
55
+ const [value] = args.splice(index, 2).slice(1);
56
+ return value;
57
+ }
58
+ function flag(args, name) {
59
+ const index = args.indexOf(`--${name}`);
60
+ if (index >= 0)
61
+ args.splice(index, 1);
62
+ return index >= 0;
63
+ }
64
+ const rect = (x0, y0, x1, y1) => [
65
+ { x: x0, y: y0 },
66
+ { x: x1, y: y0 },
67
+ { x: x1, y: y1 },
68
+ { x: x0, y: y1 },
69
+ ];
70
+ /** The base map: 256 × 256 of flat built floor, so a far camera still sees only floor, the pad at its centre. */
71
+ export function effectTourBlueprint(campaignId) {
72
+ return {
73
+ id: "effect-tour",
74
+ campaignId,
75
+ title: "Effect Tour",
76
+ summary: "A flat floor with a pad at its centre, where npm run effect-tour films each effect model in turn.",
77
+ setting: "test floor",
78
+ mapSize: { width: 256, height: 256 },
79
+ raggedCliffs: 0,
80
+ tilesetId: "KorhalCityEx2",
81
+ dependencies: [VOID_CAMPAIGN],
82
+ zones: [{ id: "floor", name: "Floor", elevation: 1, landform: "flat", role: "base", surface: "built", polygon: rect(0, 0, 256, 256) }],
83
+ anchors: [{ id: "pad", name: "Pad", zoneId: "floor", kind: "point", position: { x: 128, y: 128, z: 0 } }],
84
+ beats: [{ id: "film", title: "Film", summary: "The tour films each effect on the pad." }],
85
+ placements: [],
86
+ screenplay: { title: "Effect Tour" },
87
+ };
88
+ }
89
+ async function base(folder) {
90
+ const blueprintPath = path.join(folder, "blueprint.json");
91
+ const workspace = await workspaceFor(blueprintPath);
92
+ await mkdir(folder, { recursive: true });
93
+ await writeFile(blueprintPath, `${JSON.stringify(effectTourBlueprint(workspace.campaign.id), null, 2)}\n`);
94
+ const compiled = await compileMission(workspace, blueprintPath, undefined, { host: await loadHost(await loadMachineConfig()) });
95
+ for (const warning of compiled.warnings)
96
+ console.warn(`Warning: ${warning}`);
97
+ console.log(`Effect tour base map compiled: ${await missionMapPackage(blueprintPath)}`);
98
+ }
99
+ /** Every file under `folder`, by its storage path from Assets/ on, lower-cased. */
100
+ /** A file's storage path, from its last Assets/ folder on (a folder above can be called assets too), with forward slashes; undefined outside one. */
101
+ function storagePath(full) {
102
+ const slashed = full.replace(/\\/g, "/");
103
+ const at = slashed.toLowerCase().lastIndexOf("/assets/");
104
+ return at >= 0 ? slashed.slice(at + 1) : undefined;
105
+ }
106
+ /** A positive whole number option, or the usage message. */
107
+ function count(value, fallback, name) {
108
+ if (value === undefined)
109
+ return fallback;
110
+ const n = Number(value);
111
+ if (!Number.isInteger(n) || n < 1)
112
+ throw new Error(`--${name} takes a whole number above 0, not ${JSON.stringify(value)}\n${USAGE}`);
113
+ return n;
114
+ }
115
+ async function storageFiles(folder) {
116
+ const files = new Map();
117
+ for (const entry of await readdir(folder, { recursive: true, withFileTypes: true })) {
118
+ if (!entry.isFile())
119
+ continue;
120
+ const full = path.join(entry.parentPath, entry.name);
121
+ const storage = storagePath(full);
122
+ if (storage && !files.has(storage.toLowerCase()))
123
+ files.set(storage.toLowerCase(), full);
124
+ }
125
+ return files;
126
+ }
127
+ async function make(args) {
128
+ const models = option(args, "models");
129
+ const folder = option(args, "folder");
130
+ const baseMap = option(args, "base");
131
+ const out = option(args, "out");
132
+ if ((!models && !folder) || !baseMap || !out)
133
+ throw new Error(USAGE);
134
+ const size = count(option(args, "batch"), 120, "batch");
135
+ const only = option(args, "only");
136
+ const limit = count(option(args, "limit"), undefined, "limit");
137
+ // A folder's models are imported into the maps; the game's are named by their storage path.
138
+ const files = await storageFiles(folder ?? models);
139
+ const gameModels = folder
140
+ ? [...files.entries()].filter(([key]) => key.startsWith("assets/effects/") && key.endsWith(".m3")).map(([, full]) => storagePath(full)).sort()
141
+ : JSON.parse(await readFile(new URL("../../data/game-models.json", import.meta.url), "utf8"));
142
+ const effects = [];
143
+ const missing = [];
144
+ const unreadable = [];
145
+ for (const file of gameModels) {
146
+ // A folder's own spelling of the path is kept, so compared in lower case.
147
+ if (!file.toLowerCase().startsWith("assets/effects/") || file.toLowerCase().startsWith("assets/effects/glaze/"))
148
+ continue;
149
+ if (only && !new RegExp(only, "i").test(file))
150
+ continue;
151
+ const found = files.get(file.toLowerCase());
152
+ if (!found) {
153
+ missing.push(file);
154
+ continue;
155
+ }
156
+ try {
157
+ const data = new Uint8Array(await readFile(found));
158
+ const { min, max } = readM3Footprint(data);
159
+ effects.push({ file, sequences: readM3Sequences(data), min, max });
160
+ }
161
+ catch (error) {
162
+ unreadable.push(`${file} (${error.message})`);
163
+ }
164
+ }
165
+ const taken = limit ? effects.slice(0, limit) : effects;
166
+ await mkdir(out, { recursive: true });
167
+ let total = 0;
168
+ let frames = 0;
169
+ const missingTextures = new Set();
170
+ for (let b = 0; b * size < taken.length; b++) {
171
+ const batch = planEffectBatch(taken.slice(b * size, (b + 1) * size));
172
+ const name = `batch-${String(b + 1).padStart(2, "0")}`;
173
+ const dir = path.join(out, name);
174
+ const map = path.join(dir, `effect-tour-${String(b + 1).padStart(2, "0")}.SC2Map`);
175
+ await rm(map, { recursive: true, force: true });
176
+ await mkdir(dir, { recursive: true });
177
+ await cp(baseMap, map, { recursive: true });
178
+ await rm(path.join(map, "MapScript.galaxy"), { force: true });
179
+ await writeFile(path.join(map, "MapInfo"), hideErrorsDuringTest(await readFile(path.join(map, "MapInfo"))));
180
+ await writeFile(path.join(map, "Triggers"), withCustomScript(undefined, EFFECT_TOUR_SCRIPT_ID, effectTourScript(batch), EFFECT_TOUR_INIT));
181
+ await mkdir(path.join(map, "Base.SC2Data", "GameData"), { recursive: true });
182
+ await writeFile(path.join(map, "Base.SC2Data", "GameData", "ModelData.xml"), effectModelData(batch));
183
+ if (folder) {
184
+ // Imported at the paths they're named by: the model's own, and each texture's as the model names it.
185
+ for (const effect of batch.effects) {
186
+ const source = files.get(effect.file.toLowerCase());
187
+ await mkdir(path.dirname(path.join(map, effect.file)), { recursive: true });
188
+ await cp(source, path.join(map, effect.file));
189
+ for (const texture of readM3TexturePaths(new Uint8Array(await readFile(source)))) {
190
+ const found = files.get(texture.replace(/\\/g, "/").toLowerCase());
191
+ if (!found) {
192
+ missingTextures.add(texture);
193
+ continue;
194
+ }
195
+ const to = path.join(map, texture.replace(/\\/g, "/"));
196
+ await mkdir(path.dirname(to), { recursive: true });
197
+ await cp(found, to);
198
+ }
199
+ }
200
+ }
201
+ const seconds = batchSeconds(batch);
202
+ const manifest = { batch: b + 1, map, effects: batch.effects, shots: batch.shots, seconds };
203
+ await writeFile(path.join(dir, "manifest.json"), `${JSON.stringify(manifest, null, 1)}\n`);
204
+ total += seconds;
205
+ frames += batch.shots.length;
206
+ console.log(`${name}: ${batch.effects.length} effects, ${batch.shots.length} frames, about ${Math.ceil(seconds / 60)} min in game`);
207
+ }
208
+ if (folder && missingTextures.size)
209
+ console.log(`Textures not in ${folder} (${missingTextures.size}): ${[...missingTextures].slice(0, 12).join(", ")}${missingTextures.size > 12 ? ", …" : ""}`);
210
+ console.log(`${taken.length} effects, ${frames} frames in ${Math.ceil(taken.length / size)} batches, about ${Math.round(total / 60)} min in game plus 1–2 min to start each batch`);
211
+ if (missing.length)
212
+ console.log(`Not in ${models} (${missing.length}): ${missing.slice(0, 12).join(", ")}${missing.length > 12 ? ", …" : ""}`);
213
+ if (unreadable.length)
214
+ console.log(`Unreadable (${unreadable.length}): ${unreadable.join("; ")}`);
215
+ }
216
+ const html = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
217
+ /** A batch's contact sheet: one row per effect, its frames in order, each labelled, then its clip and picked frames when it was recorded. */
218
+ function batchIndex(manifest, framesDir, present, videos = new Map()) {
219
+ const dir = path.dirname(framesDir);
220
+ const rel = (file) => html(path.relative(dir, file).split(path.sep).join("/"));
221
+ const rows = manifest.effects.map((effect, n) => {
222
+ const shots = manifest.shots.filter((shot) => shot.effect === n);
223
+ const cells = shots.map((shot) => {
224
+ const frame = `${String(shot.stop).padStart(4, "0")}.jpg`;
225
+ return present.has(frame)
226
+ ? `<figure><img loading="lazy" src="${html(path.basename(framesDir))}/${frame}"><figcaption>${shot.label}</figcaption></figure>`
227
+ : `<figure class="missing"><div>no frame</div><figcaption>${shot.label}</figcaption></figure>`;
228
+ });
229
+ const anims = effect.sequences.map((sequence) => `${sequence.name} ${sequence.durationMs / 1000}s${sequence.looping ? "" : " once"}`).join(", ") || "no animations";
230
+ const video = videos.get(n);
231
+ const recorded = video
232
+ ? `<div class="row"><figure><video src="${rel(video.clip)}" controls loop muted playsinline preload="none"></video><figcaption>clip</figcaption></figure>${video.peaks
233
+ .map((peak) => `<figure><img loading="lazy" src="${rel(peak.file)}"><figcaption>+${peak.seconds.toFixed(2)} s</figcaption></figure>`)
234
+ .join("")}${video.peaks.length ? "" : `<figure class="missing"><div>nothing new on screen</div><figcaption>video</figcaption></figure>`}</div>`
235
+ : "";
236
+ return `<section><h2>${html(effect.file.replace(/^Assets\/Effects\//, ""))}</h2><p>${html(anims)}</p><div class="row">${cells.join("")}</div>${recorded}</section>`;
237
+ });
238
+ return `<!doctype html><meta charset="utf-8"><title>Effect tour, batch ${manifest.batch}</title>
239
+ <style>body{font:14px system-ui;background:#222;color:#ddd;margin:16px}h2{font-size:14px;margin:16px 0 2px}p{margin:0 0 6px;color:#999}.row{display:flex;gap:6px;flex-wrap:wrap}figure{margin:0}img,video{width:320px;display:block}.row+.row{margin-top:6px}figcaption{font-size:12px;color:#aaa}.missing div{width:320px;height:180px;background:#400;display:grid;place-items:center}</style>
240
+ <h1>Effect tour, batch ${manifest.batch}</h1>
241
+ ${rows.join("\n")}
242
+ `;
243
+ }
244
+ async function capture(out, args) {
245
+ const range = option(args, "batches");
246
+ const freeze = flag(args, "freeze");
247
+ const video = flag(args, "video");
248
+ const redo = flag(args, "redo");
249
+ const [from, to] = batchRange(range);
250
+ const host = await loadHost(await loadMachineConfig());
251
+ requireCapability(host, "editor.captureTour", "Filming effects");
252
+ const batches = (await readdir(out)).filter((name) => /^batch-\d+$/.test(name)).sort();
253
+ for (const name of batches) {
254
+ const number = Number(name.slice(6));
255
+ if (number < from || number > to)
256
+ continue;
257
+ const dir = path.join(out, name);
258
+ const manifest = JSON.parse(await readFile(path.join(dir, "manifest.json"), "utf8"));
259
+ const framesDir = path.join(dir, "frames");
260
+ const have = existsSync(framesDir) ? new Set((await readdir(framesDir)).filter((file) => file.endsWith(".jpg"))) : new Set();
261
+ // A batch filmed to its end has its index; a frame or two the capture missed doesn't refilm it.
262
+ if (!redo && existsSync(path.join(dir, "index.html"))) {
263
+ console.log(`${name}: already filmed (${have.size} of ${manifest.shots.length} frames), skipped`);
264
+ continue;
265
+ }
266
+ // The batch's own map, wherever the folder now is.
267
+ const map = path.join(dir, path.basename(manifest.map));
268
+ // Written on every capture, so the script matches this run's options: a --freeze run doesn't
269
+ // leave the next one frozen too, and --video saves a mark before each attach.
270
+ const options = { freeze, video };
271
+ await writeFile(path.join(map, "Triggers"), withCustomScript(undefined, EFFECT_TOUR_SCRIPT_ID, effectTourScript(planEffectBatch(manifest.effects), options), EFFECT_TOUR_INIT));
272
+ await rm(framesDir, { recursive: true, force: true });
273
+ const started = Date.now();
274
+ console.log(`${name}: filming ${manifest.effects.length} effects, ${manifest.shots.length} frames (about ${Math.ceil(manifest.seconds / 60)} min once the game is up)`);
275
+ const { frames, end } = await runBrokeredCapture(host, {
276
+ kind: "map",
277
+ source: map,
278
+ label: name,
279
+ copy: true,
280
+ bank: EFFECT_TOUR_BANK,
281
+ settings: { frameDigits: 4, width: 1600, quality: 85, startSeconds: 450, pressSpaceAfterSeconds: 90, ...(video ? { video: VIDEO_SETTINGS } : {}) },
282
+ outputDir: framesDir,
283
+ }, { log: (line) => console.log(` ${line}`) });
284
+ const present = new Set(existsSync(framesDir) ? (await readdir(framesDir)).filter((file) => file.endsWith(".jpg")) : []);
285
+ const videos = video ? await cutBatch(dir, manifest) : new Map();
286
+ // Only a batch filmed to its end gets its index, which marks it done: one that ended early is filmed again.
287
+ if (end === "done")
288
+ await writeFile(path.join(dir, "index.html"), batchIndex(manifest, framesDir, present, videos));
289
+ const missed = manifest.shots.filter((shot) => !present.has(`${String(shot.stop).padStart(4, "0")}.jpg`));
290
+ console.log(`${name}: ${frames} frames, ${end}, ${Math.round((Date.now() - started) / 60000)} min${missed.length ? `; ${missed.length} missing` : ""}; ${path.join(dir, "index.html")}`);
291
+ }
292
+ }
293
+ /**
294
+ * The recording's size, rate and HEVC quality: the stills' 1600x900, at 30 fps, at a quality that
295
+ * keeps sparks and particles (at 0.5 they smeared away). Sizes: docs/reference/effect-tour.md.
296
+ */
297
+ const VIDEO_SETTINGS = { width: 1600, fps: 30, quality: 0.9 };
298
+ /** The hold the batch's map was filmed with (its script's fxHold), else the default: the segments are placed by it. */
299
+ async function batchHold(dir, manifest) {
300
+ for (const map of [path.join(dir, path.basename(manifest.map)), manifest.map]) {
301
+ const triggers = path.join(map, "Triggers");
302
+ if (!existsSync(triggers))
303
+ continue;
304
+ const hold = /fxHold = ([0-9.]+);/.exec(await readFile(triggers, "utf8"))?.[1];
305
+ if (hold)
306
+ return Number(hold);
307
+ }
308
+ return DEFAULT_HOLD;
309
+ }
310
+ /** Cuts a batch's recording into each effect's clip and picked frames; an empty map when it has no recording. */
311
+ async function cutBatch(dir, manifest) {
312
+ const framesDir = path.join(dir, "frames");
313
+ const video = path.join(framesDir, "video.mp4");
314
+ const stopsFile = path.join(framesDir, "video-stops.txt");
315
+ const results = new Map();
316
+ if (!existsSync(video) || !existsSync(stopsFile)) {
317
+ console.log(` no recording in ${framesDir}`);
318
+ return results;
319
+ }
320
+ const segments = effectSegments(manifest.shots, parseVideoStops(await readFile(stopsFile, "utf8")), await batchHold(dir, manifest));
321
+ await rm(path.join(dir, "clips"), { recursive: true, force: true });
322
+ await rm(path.join(dir, "peaks"), { recursive: true, force: true });
323
+ for (const segment of segments) {
324
+ try {
325
+ results.set(segment.effect, await cutEffect(video, segment, dir, String(segment.effect + 1).padStart(4, "0")));
326
+ }
327
+ catch (error) {
328
+ console.log(` effect ${segment.effect + 1}: couldn't cut its clip: ${error.message}`);
329
+ }
330
+ }
331
+ const unplaced = manifest.effects.length - segments.length;
332
+ console.log(` ${results.size} clips, ${[...results.values()].reduce((sum, each) => sum + each.peaks.length, 0)} picked frames${unplaced ? `; ${unplaced} effects not found in the recording` : ""}`);
333
+ return results;
334
+ }
335
+ async function pick(out, args) {
336
+ const [from, to] = batchRange(option(args, "batches"));
337
+ for (const name of (await readdir(out)).filter((each) => /^batch-\d+$/.test(each)).sort()) {
338
+ const number = Number(name.slice(6));
339
+ if (number < from || number > to)
340
+ continue;
341
+ const dir = path.join(out, name);
342
+ if (!existsSync(path.join(dir, "manifest.json"))) {
343
+ console.log(`${name}: no manifest.json, skipped`);
344
+ continue;
345
+ }
346
+ const manifest = JSON.parse(await readFile(path.join(dir, "manifest.json"), "utf8"));
347
+ const framesDir = path.join(dir, "frames");
348
+ console.log(`${name}:`);
349
+ const videos = await cutBatch(dir, manifest);
350
+ // Only an index capture wrote is rewritten: an index marks a batch filmed to its end, and one
351
+ // that ended early, or never started, has to stay unmarked so capture films it again.
352
+ const index = path.join(dir, "index.html");
353
+ if (!existsSync(index)) {
354
+ console.log(`${name}: not filmed to its end; clips cut, no index written`);
355
+ continue;
356
+ }
357
+ const present = new Set(existsSync(framesDir) ? (await readdir(framesDir)).filter((file) => file.endsWith(".jpg")) : []);
358
+ await writeFile(index, batchIndex(manifest, framesDir, present, videos));
359
+ console.log(`${name}: ${index}`);
360
+ }
361
+ }
362
+ async function main() {
363
+ const [command, ...args] = process.argv.slice(2);
364
+ if (command === "base")
365
+ return base(args[0] ?? path.resolve("missions", "effect-tour"));
366
+ if (command === "make")
367
+ return make(args);
368
+ if (command === "capture" && args[0])
369
+ return capture(args[0], args.slice(1));
370
+ if (command === "pick" && args[0])
371
+ return pick(args[0], args.slice(1));
372
+ console.error(USAGE);
373
+ process.exitCode = 1;
374
+ }
375
+ main().catch((error) => {
376
+ console.error(error instanceof Error ? error.message : error);
377
+ process.exitCode = 1;
378
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ // Makes the 1000px frames of the active Style Pack's tours (makeFrames), in the Workspace above the
2
+ // current folder: what make-frames.sh runs, and what capture_exemplar does after each capture.
3
+ // The tours are in the pack's exemplar-maps/, or under $SC2_RESEARCH_DIR/docs/research/exemplar-maps/
4
+ // when it is set.
5
+ import path from "node:path";
6
+ import { makeFrames } from "../capture/style-pack-captures.js";
7
+ import { WORKSPACE_FILE, workspaceFor } from "../plugins/workspace.js";
8
+ import { exemplarCaptureDir } from "../study/study-exemplars.js";
9
+ async function main() {
10
+ const workspace = await workspaceFor(path.join(process.cwd(), WORKSPACE_FILE));
11
+ const { made, removed, kept, unreadable } = await makeFrames(exemplarCaptureDir(workspace));
12
+ console.log(`made ${made}, removed ${removed}, kept ${kept}`);
13
+ if (unreadable.length) {
14
+ console.error(`couldn't read ${unreadable.join(", ")}`);
15
+ process.exitCode = 1;
16
+ }
17
+ }
18
+ main().catch((error) => {
19
+ console.error(error instanceof Error ? error.message : error);
20
+ process.exitCode = 1;
21
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ // The actor data that plays a sound mix: several CSounds as one sound, each from its own time
2
+ // (src/mods/sound-mix.ts, docs/reference/sound-mixes.md). Reads a mix file (one mix or a list) and
3
+ // prints its entries: Generic Entries for a Mod Blueprint's entries, or with --xml the elements to
4
+ // add to a map's ActorData.xml. Every CSound a layer plays is checked against the game's data and
5
+ // the own data given with --sounds (a SoundData.xml, a JSON file of Generic Entries, or a folder of
6
+ // them, such as a .SC2Map, a .SC2Mod or a Mod Blueprint's entries); one defined nowhere would play
7
+ // nothing, so the command refuses it.
8
+ //
9
+ // npm run sound-mix -- <mix.json> [--xml] [--sounds <file or folder>]... [--out <file>]
10
+ import { readFile, writeFile } from "node:fs/promises";
11
+ import path from "node:path";
12
+ import { checkSoundMixes, definedSounds, SoundMixFileSchema, soundMixEntries, soundMixWiring, soundMixXml } from "../mods/sound-mix.js";
13
+ import { helpAsked, optionValue } from "./help-asked.js";
14
+ const USAGE = "Usage: sound-mix <mix.json> [--xml] [--sounds <file or folder>]... [--out <file>]";
15
+ const VALUED = new Set(["--sounds", "--out"]);
16
+ async function main() {
17
+ const args = process.argv.slice(2);
18
+ if (helpAsked(args, VALUED)) {
19
+ console.log(USAGE);
20
+ return;
21
+ }
22
+ const cwd = process.env.INIT_CWD ?? process.cwd();
23
+ const sources = [];
24
+ let xml = false;
25
+ let out;
26
+ const positional = [];
27
+ for (let i = 0; i < args.length; i++) {
28
+ const arg = args[i];
29
+ if (arg === "--xml")
30
+ xml = true;
31
+ else if (arg === "--sounds")
32
+ sources.push(path.resolve(cwd, optionValue(args, i++, arg)));
33
+ else if (arg === "--out")
34
+ out = path.resolve(cwd, optionValue(args, i++, arg));
35
+ else if (arg.startsWith("--"))
36
+ throw new Error(`Unknown option ${arg}. ${USAGE}`);
37
+ else
38
+ positional.push(arg);
39
+ }
40
+ if (positional.length !== 1) {
41
+ console.error(USAGE);
42
+ process.exitCode = 2;
43
+ return;
44
+ }
45
+ const file = path.resolve(cwd, positional[0]);
46
+ const parsed = SoundMixFileSchema.safeParse(JSON.parse(await readFile(file, "utf8")));
47
+ if (!parsed.success)
48
+ throw new Error(`${file} isn't a sound mix file: ${parsed.error.issues.map((issue) => `${issue.path.join(".") || "(top)"}: ${issue.message}`).join("; ")}`);
49
+ const mixes = parsed.data;
50
+ const own = new Set();
51
+ for (const source of sources)
52
+ for (const id of await definedSounds(source))
53
+ own.add(id);
54
+ const { found, problems } = checkSoundMixes(mixes, own);
55
+ for (const [sound, where] of found)
56
+ console.error(` ${sound}: ${where.join(", ")}`);
57
+ if (problems.length > 0) {
58
+ for (const problem of problems)
59
+ console.error(problem);
60
+ process.exitCode = 1;
61
+ return;
62
+ }
63
+ const entries = mixes.flatMap(soundMixEntries);
64
+ const text = xml ? `${soundMixXml(entries)}\n` : `${JSON.stringify(entries, null, 2)}\n`;
65
+ if (out)
66
+ await writeFile(out, text);
67
+ else
68
+ process.stdout.write(text);
69
+ console.error(`${entries.length} actor${entries.length === 1 ? "" : "s"} for ${mixes.length} mix${mixes.length === 1 ? "" : "es"}${out ? ` -> ${out}` : ""}.`);
70
+ console.error(`Create each from the actor of the unit it's for, on the event it's for. On a death: ${soundMixWiring(mixes[0])}`);
71
+ }
72
+ main().catch((error) => {
73
+ console.error(error instanceof Error ? error.message : error);
74
+ process.exitCode = 1;
75
+ });
package/dist/cli/study.js CHANGED
@@ -1,38 +1,18 @@
1
1
  // Builds a Map Study for each Exemplar Map of the active Style Pack (the Workspace config's
2
2
  // `stylePack`, found above the current folder): study.json plus layer renders in the pack's folder
3
3
  // for that map. Source maps are read from the folder the machine config's `exemplarMaps` names
4
- // (SC2_ADJUTANT_EXEMPLAR_MAPS overrides it).
4
+ // (SC2_ADJUTANT_EXEMPLAR_MAPS overrides it), else the Workspace config's. The study_exemplar tool
5
+ // runs the same code (src/study/study-exemplars.ts).
5
6
  //
6
7
  // npm run study # every exemplar
7
8
  // npm run study -- 3-11 # just these ids
8
- import { existsSync } from "node:fs";
9
- import { mkdir, writeFile } from "node:fs/promises";
10
9
  import path from "node:path";
11
- import { writePng } from "../preview/write-png.js";
12
- import { exemplarMapSources, WORKSPACE_FILE, workspaceFor } from "../plugins/workspace.js";
13
- import { loadMapPackage } from "../study/load-map-package.js";
14
- import { buildMapStudy } from "../study/map-study.js";
10
+ import { WORKSPACE_FILE, workspaceFor } from "../plugins/workspace.js";
11
+ import { studyExemplars } from "../study/study-exemplars.js";
15
12
  async function main() {
16
- const only = new Set(process.argv.slice(2));
13
+ const ids = process.argv.slice(2);
17
14
  const workspace = await workspaceFor(path.join(process.cwd(), WORKSPACE_FILE));
18
- const exemplars = await exemplarMapSources(workspace);
19
- const unknown = [...only].filter((id) => !exemplars.some((exemplar) => exemplar.id === id));
20
- if (unknown.length)
21
- throw new Error(`The Style Pack has no Exemplar Map ${unknown.join(", ")} (its Exemplar Maps: ${exemplars.map((exemplar) => exemplar.id).join(", ")})`);
22
- for (const exemplar of exemplars) {
23
- if (only.size > 0 && !only.has(exemplar.id))
24
- continue;
25
- if (!existsSync(exemplar.source))
26
- throw new Error(`Exemplar Map ${exemplar.id}: no source map at ${exemplar.source}`);
27
- const started = Date.now();
28
- const map = loadMapPackage(exemplar.source);
29
- const { study, images } = buildMapStudy(exemplar, map);
30
- await mkdir(exemplar.studyDir, { recursive: true });
31
- await writeFile(path.join(exemplar.studyDir, "study.json"), `${JSON.stringify(study, null, 2)}\n`);
32
- for (const [name, image] of Object.entries(images))
33
- await writeFile(path.join(exemplar.studyDir, name), writePng(image));
34
- console.log(`${exemplar.id}: ${exemplar.studyDir} (${((Date.now() - started) / 1000).toFixed(1)}s)`);
35
- }
15
+ await studyExemplars(workspace, { ...(ids.length ? { ids } : {}), onStudied: ({ id, studyDir, seconds }) => console.log(`${id}: ${studyDir} (${seconds.toFixed(1)}s)`) });
36
16
  }
37
17
  main().catch((error) => {
38
18
  console.error(error);