@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,306 @@
1
+ // Place-finding: an Exemplar Map's dressed places and what each is made of (which types an author
2
+ // used, in what roles and shares, how dense and how far apart), so a generator can make a new
3
+ // arrangement in the same mood rather than copy the layout.
4
+ //
5
+ // A place is a cluster of doodads within 2.5 cells of each other (helpers other than point lights
6
+ // left out); clusters wider than one capture frame are split into 16x16-cell tiles. Places under 8
7
+ // visible members are dropped. A place has a mood only when the caller passes mood rules: moods are a
8
+ // Style Pack's own, not core's.
9
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
10
+ import path from "node:path";
11
+ import { round } from "./stats.js";
12
+ /** Helpers that never show in game: left out of places. */
13
+ const HIDDEN = /Curtain|Blocker|PlacementDoodad|^PathingBlocker|^SightBlocker/i;
14
+ /** Point lights: kept in a place, but not counted as its visible members. */
15
+ const LIGHT = /^LightOmni|^LightSpot/i;
16
+ const RADIUS = 2.5;
17
+ /** A cluster wider than this, either way, is wider than one capture frame. */
18
+ const FRAME_SPAN = 18;
19
+ const TILE = 16;
20
+ const MIN_SIZE = 8;
21
+ const SNAP = Math.PI / 4;
22
+ const r2 = (v) => round(v, 2);
23
+ // Motifs: what a type is for, whatever its planet, so a mixture can be regenerated with another
24
+ // tileset's assets. First match wins; matched on the type name, so a few will be wrong.
25
+ const MOTIFS = [
26
+ ["carnage", /Corpse|Carcass|Blood|Bone|Ragdoll|Skeleton|Bodybag|Death|Drained|Petrified|Fossil|Crow|FlySwarm|Yeti/],
27
+ ["fire", /Fire|Smoke|Ember|Lava|ElectricalArcs|Lightning/],
28
+ ["wreck", /RuinedShips|Cockpit|WingPiece|Hanger_Bay|Wreck|Destroyed|Broken|Debris|Rubble|Scrap|Junk|Crack|Crater|Blast|Torn|Abandoned|Collaps|Garbage|Trash|Dumpster|Glass_Splat|MeteorImpact/],
29
+ ["military", /Gun|Rocket|Missile|Stationary|Siege|Goliath|Dragoon|Reaver|Target|Killwall|Military|Barracks|Sandbag|Fidgeting|Probe/],
30
+ ["creep", /Creep|Zerg|^Char(?!Crystal|Floor)|Combs|TIM|Blister|Spore|Worm/],
31
+ ["lab", /Monitor|Console|Terminal|Lab|Stasis|Display|Holo|Workstation|Screen|Camera|Cabinet|Flask|TestTube|PrisonCell|HoldingPen|Lightboard|Containment/],
32
+ ["civic", /Bench|StoreFront|Billboard|Sign|Streetlight|Car(s|$)|Truck|Vehicle|Mono|Furniture|Couch|Table|Book|Game_|Carpet|Banister|Coffee|Hut|Garage|Flag|Podium|GroundProps|GroundMix|Tires|Mengsk|MarineStatue|Topiary|Chef|Outhouse|Bar$|Fuel|Resort|Downtown|Interior|Vase|Portrait|Wraith|Wolf|Subway|Charger|Station$|Panda|Fish|Eel|Small_Props|SeaShell|Palmtree|Birds/],
33
+ ["cargo", /Crate|Container|Supplies|Pallete|Cart|Storage|Barrel|Palette|Equipment|Misc/],
34
+ ["machinery", /Pipe|Piping|Protector|RepairBay|Cable|Hose|Vent|Fan|Generator|Reactor|Turbine|Conduit|Power|Tank|Crane|Welder|Factory|Girder|Scaffold|Mechanism|Conveyor|Exhaust|Dock|Antenna|Radar|Solar|Steam|Compactor|Coolant|Arm$|Beam\d?$|Bullhorn|Mining/],
35
+ ["light", /Light|Lantern|Strobe|Floodlight|Searchlight|Alarm|Fireflies/],
36
+ ["masonry", /Brick|Temple|Column|Pillar|Arch|Statue|Shrine|Obelisk|Monlyth|Sarcophag|Altar|Brazier|Banner|Inlay|Reliquary|Sanctum|Summoning|Spout|Facades|Tower|City_Structure|Buildings?|ZhakulDas|Pyramid|Spires?$|Hex/],
37
+ ["structure", /Curb|Trim|Tarmac|Pad|Road|Railing|Wall|Gate|Door|Fence|Plates?|Plating|Platform|Floor|Deck|Bridge|Ramp|Barrier|Entrance|Roof|Hull|Window|Ornate|Skybox|Matrix|Core|Overpass|SkyScrapers|Building/],
38
+ ["vegetation", /Tree|Foliage|Bush|Brush|Plant|Vine|Bramble|Grass|Flower|Underbrush|Crops|Weeds|Overgrowth|GroundCover|Tendril|Log|Cactus|Fauna|Leaves/],
39
+ ["weather", /Snow|Ice(?!World)|Fog|Mist|Rain|Wind|Cloud|Water|River|Gust|Dust|Drift|Air$/],
40
+ ["rock", /Rock|Stone|Crystal|Spire|Glacier|Cliff|GapFiller|Icicle|Formation/],
41
+ ["decal", /Decal|Splat|Crack|Sludge|Arrow|GroundScar/],
42
+ ];
43
+ /** A type's motif, from its name: what it is for, whatever its planet; "other" when none matches. */
44
+ export const motifOf = (type) => MOTIFS.find(([, re]) => re.test(type))?.[0] ?? "other";
45
+ function clusters(ds) {
46
+ const key = (x, y) => `${Math.floor(x / RADIUS)},${Math.floor(y / RADIUS)}`;
47
+ const buckets = new Map();
48
+ ds.forEach((d, i) => {
49
+ const k = key(d.position.x, d.position.y);
50
+ if (!buckets.has(k))
51
+ buckets.set(k, []);
52
+ buckets.get(k).push(i);
53
+ });
54
+ const seen = new Uint8Array(ds.length);
55
+ const out = [];
56
+ for (let s = 0; s < ds.length; s++) {
57
+ if (seen[s])
58
+ continue;
59
+ const members = [s];
60
+ seen[s] = 1;
61
+ for (let h = 0; h < members.length; h++) {
62
+ const { x, y } = ds[members[h]].position;
63
+ const bx = Math.floor(x / RADIUS);
64
+ const by = Math.floor(y / RADIUS);
65
+ for (let dx = -1; dx <= 1; dx++)
66
+ for (let dy = -1; dy <= 1; dy++)
67
+ for (const j of buckets.get(`${bx + dx},${by + dy}`) ?? []) {
68
+ if (seen[j])
69
+ continue;
70
+ const p = ds[j].position;
71
+ if ((p.x - x) ** 2 + (p.y - y) ** 2 <= RADIUS * RADIUS) {
72
+ seen[j] = 1;
73
+ members.push(j);
74
+ }
75
+ }
76
+ }
77
+ out.push(members.map((i) => ds[i]));
78
+ }
79
+ return out;
80
+ }
81
+ /** Max minus min, with a loop: a map-wide cluster is too big to spread into Math.max. */
82
+ function extent(values) {
83
+ let lo = Infinity;
84
+ let hi = -Infinity;
85
+ for (const v of values) {
86
+ if (v < lo)
87
+ lo = v;
88
+ if (v > hi)
89
+ hi = v;
90
+ }
91
+ return hi - lo;
92
+ }
93
+ /** A cluster wider than one capture frame, split into 16x16-cell tiles. */
94
+ function splitWide(group) {
95
+ if (extent(group.map((d) => d.position.x)) <= FRAME_SPAN && extent(group.map((d) => d.position.y)) <= FRAME_SPAN)
96
+ return [group];
97
+ const tiles = new Map();
98
+ for (const d of group) {
99
+ const k = `${Math.floor(d.position.x / TILE)},${Math.floor(d.position.y / TILE)}`;
100
+ if (!tiles.has(k))
101
+ tiles.set(k, []);
102
+ tiles.get(k).push(d);
103
+ }
104
+ return [...tiles.values()];
105
+ }
106
+ function lightColour(type) {
107
+ const m = type.match(/^Light(?:Omni|Spot)([A-Z][a-z]+)/);
108
+ return m ? m[1] : "White";
109
+ }
110
+ const median = (a) => {
111
+ if (!a.length)
112
+ return null;
113
+ const s = [...a].sort((x, y) => x - y);
114
+ return s[Math.floor(s.length / 2)];
115
+ };
116
+ const increment = (counts, key) => counts.set(key, (counts.get(key) ?? 0) + 1);
117
+ function profile(map, members) {
118
+ const visible = members.filter((d) => !LIGHT.test(d.type));
119
+ const lights = members.filter((d) => LIGHT.test(d.type));
120
+ const xs = members.map((d) => d.position.x);
121
+ const ys = members.map((d) => d.position.y);
122
+ const w = extent(xs) + 1;
123
+ const h = extent(ys) + 1;
124
+ const byType = new Map();
125
+ for (const d of visible) {
126
+ if (!byType.has(d.type))
127
+ byType.set(d.type, []);
128
+ byType.get(d.type).push(d);
129
+ }
130
+ const roles = { anchor: [], fill: [], scatter: [] };
131
+ for (const [type, list] of byType) {
132
+ const role = list[0].kind === "decal" || list.length >= 6 ? "scatter" : list.length <= 2 ? "anchor" : "fill";
133
+ roles[role].push({ type, motif: motifOf(type), count: list.length, share: r2(list.length / visible.length) });
134
+ }
135
+ for (const r of Object.values(roles))
136
+ r.sort((a, b) => b.count - a.count);
137
+ const nn = visible
138
+ .map((d, i) => {
139
+ let best = Infinity;
140
+ for (let j = 0; j < visible.length; j++) {
141
+ if (j === i)
142
+ continue;
143
+ const dd = Math.hypot(visible[j].position.x - d.position.x, visible[j].position.y - d.position.y);
144
+ if (dd < best)
145
+ best = dd;
146
+ }
147
+ return best;
148
+ })
149
+ .filter(Number.isFinite);
150
+ const offSnap = (yaw) => ((yaw % SNAP) + SNAP) % SNAP;
151
+ const snapped = visible.filter((d) => Math.abs(offSnap(d.yaw)) < 0.02 || Math.abs(offSnap(d.yaw) - SNAP) < 0.02);
152
+ const scales = visible.map((d) => d.scale.z);
153
+ const manip = new Map();
154
+ for (const d of visible)
155
+ for (const m of d.manipulations)
156
+ increment(manip, m);
157
+ const colours = new Map();
158
+ for (const d of lights)
159
+ increment(colours, lightColour(d.type));
160
+ const motifs = new Map();
161
+ for (const d of visible)
162
+ increment(motifs, motifOf(d.type));
163
+ return {
164
+ map,
165
+ center: [r2(xs.reduce((a, b) => a + b, 0) / xs.length), r2(ys.reduce((a, b) => a + b, 0) / ys.length)],
166
+ size: [r2(w), r2(h)],
167
+ visible: visible.length,
168
+ distinctTypes: byType.size,
169
+ perHundredCells: r2((visible.length / (w * h)) * 100),
170
+ spacing: { median: nn.length ? r2(median(nn)) : null },
171
+ motifs: Object.fromEntries([...motifs].sort((a, b) => b[1] - a[1]).map(([k, n]) => [k, r2(n / visible.length)])),
172
+ roles,
173
+ yawSnapped45: visible.length ? r2(snapped.length / visible.length) : null,
174
+ scale: scales.length ? [r2(scales.reduce((a, b) => Math.min(a, b))), r2(scales.reduce((a, b) => Math.max(a, b)))] : null,
175
+ manipulations: Object.fromEntries([...manip].map(([m, n]) => [m, r2(n / visible.length)])),
176
+ lights: { count: lights.length, colours: Object.fromEntries(colours) },
177
+ };
178
+ }
179
+ const holds = (motifs, { motifs: names, atLeast }) => names.reduce((sum, name) => sum + (motifs[name] ?? 0), 0) >= atLeast;
180
+ /** The mood rule a recorded mood stands for. */
181
+ export function moodRuleOf({ name, when }) {
182
+ return { name, test: (motifs) => when === undefined || when.some((conditions) => conditions.every((condition) => holds(motifs, condition))) };
183
+ }
184
+ /**
185
+ * The stops of one map's tours under `captureDir` (`<captureDir>/<map>/captures/<tour>/stops.txt`,
186
+ * else the same under `frames/`): every place tour when the map has any (a map lit by zone has one
187
+ * per lighting), else its first grid tour. Undefined when the map has no tours.
188
+ */
189
+ export function readCaptureStops(captureDir, map) {
190
+ for (const sub of ["captures", "frames"]) {
191
+ const dir = path.join(captureDir, map, sub);
192
+ if (!existsSync(dir))
193
+ continue;
194
+ const tours = readdirSync(dir)
195
+ .filter((t) => existsSync(path.join(dir, t, "stops.txt")))
196
+ .sort();
197
+ const placeTours = tours.filter((t) => t.startsWith("places"));
198
+ const use = placeTours.length ? placeTours : tours.slice(0, 1);
199
+ if (!use.length)
200
+ continue;
201
+ const stops = use.flatMap((tour) => readFileSync(path.join(dir, tour, "stops.txt"), "utf8")
202
+ .trim()
203
+ .split("\n")
204
+ .map((line) => line.trim().split(/\s+/).map(Number))
205
+ .filter(([n, x, y]) => [n, x, y].every(Number.isFinite))
206
+ .map(([n, x, y]) => ({ tour, n: n, x: x, y: y })));
207
+ return { stops, placeTours: placeTours.length > 0 };
208
+ }
209
+ return undefined;
210
+ }
211
+ /**
212
+ * The frames near a place, as paths under the captures folder (`<map>/frames/<tour>/<nnn>.jpg`):
213
+ * from a place tour, the stop within a cell of its centre; from a grid tour, the two nearest within 8 cells.
214
+ */
215
+ function framesNear(map, center, { stops, placeTours }) {
216
+ return stops
217
+ .map((s) => ({ ...s, d: Math.hypot(s.x - center[0], s.y - center[1]) }))
218
+ .sort((a, b) => a.d - b.d)
219
+ .slice(0, placeTours ? 1 : 2)
220
+ .filter((s) => s.d <= (placeTours ? 1 : 8))
221
+ .map((s) => `${map}/frames/${s.tour}/${String(s.n).padStart(3, "0")}.jpg`);
222
+ }
223
+ /** The dressed places among one map's doodads (from `studyDoodads`), largest first. */
224
+ export function findPlaces(map, doodads, options = {}) {
225
+ return clusters(doodads.filter((d) => !HIDDEN.test(d.type)))
226
+ .flatMap(splitWide)
227
+ .filter((g) => g.filter((d) => !LIGHT.test(d.type)).length >= MIN_SIZE)
228
+ .map((g) => {
229
+ const found = profile(map, g);
230
+ const place = options.stops ? { ...found, frames: framesNear(map, found.center, options.stops) } : found;
231
+ const mood = options.moods?.find((rule) => rule.test(place.motifs))?.name;
232
+ return mood === undefined ? place : { ...place, mood };
233
+ })
234
+ .sort((a, b) => b.visible - a.visible);
235
+ }
236
+ const quartiles = (a) => {
237
+ const s = [...a].sort((x, y) => x - y);
238
+ return s.length ? [r2(s[Math.floor(s.length / 4)]), r2(s[Math.floor(s.length / 2)]), r2(s[Math.floor((3 * s.length) / 4)])] : null;
239
+ };
240
+ function moodMixture(ps) {
241
+ const motifNames = new Set(ps.flatMap((p) => Object.keys(p.motifs)));
242
+ const pools = {};
243
+ for (const p of ps)
244
+ for (const r of Object.values(p.roles))
245
+ for (const t of r) {
246
+ const byMap = (pools[t.motif] ??= {});
247
+ const types = (byMap[p.map] ??= {});
248
+ types[t.type] = (types[t.type] ?? 0) + t.count;
249
+ }
250
+ const colours = {};
251
+ for (const p of ps)
252
+ for (const [c, n] of Object.entries(p.lights.colours))
253
+ colours[c] = (colours[c] ?? 0) + n;
254
+ return {
255
+ places: ps.length,
256
+ maps: [...new Set(ps.map((p) => p.map))],
257
+ motifs: Object.fromEntries([...motifNames]
258
+ .map((k) => [k, quartiles(ps.map((p) => p.motifs[k] ?? 0))])
259
+ .filter(([, q]) => q[2] > 0)
260
+ .sort((a, b) => b[1][1] - a[1][1] || b[1][2] - a[1][2])),
261
+ visible: quartiles(ps.map((p) => p.visible)),
262
+ distinctTypes: quartiles(ps.map((p) => p.distinctTypes)),
263
+ anchors: quartiles(ps.map((p) => p.roles.anchor.length)),
264
+ perHundredCells: quartiles(ps.map((p) => p.perHundredCells)),
265
+ spacing: quartiles(ps.flatMap((p) => (p.spacing.median == null ? [] : [p.spacing.median]))),
266
+ yawSnapped45: quartiles(ps.flatMap((p) => (p.yawSnapped45 == null ? [] : [p.yawSnapped45]))),
267
+ lightsPerPlace: quartiles(ps.map((p) => p.lights.count)),
268
+ lightColours: colours,
269
+ pools: Object.fromEntries(Object.entries(pools).map(([motif, byMap]) => [
270
+ motif,
271
+ Object.fromEntries(Object.entries(byMap).map(([m, types]) => [
272
+ m,
273
+ Object.entries(types)
274
+ .sort((a, b) => b[1] - a[1])
275
+ .slice(0, 8)
276
+ .map(([t, n]) => `${t} ${n}`),
277
+ ])),
278
+ ])),
279
+ examples: ps.flatMap((p) => (p.frames?.length ? [{ map: p.map, center: p.center, frames: p.frames }] : [])).slice(0, 6),
280
+ };
281
+ }
282
+ /**
283
+ * A Style Pack's mixtures from its places: per mood, in `moods` order, the typical mixture of the
284
+ * places that have it (a mood with none is left out), and every place in brief.
285
+ */
286
+ export function buildMixtures(places, moods) {
287
+ const library = {};
288
+ for (const mood of moods) {
289
+ const ps = places.filter((p) => p.mood === mood);
290
+ if (ps.length)
291
+ library[mood] = moodMixture(ps);
292
+ }
293
+ return {
294
+ moods: library,
295
+ places: places.map((p) => ({
296
+ map: p.map,
297
+ ...(p.mood === undefined ? {} : { mood: p.mood }),
298
+ center: p.center,
299
+ size: p.size,
300
+ visible: p.visible,
301
+ motifs: p.motifs,
302
+ top: [...p.roles.anchor.slice(0, 3), ...p.roles.fill.slice(0, 3), ...p.roles.scatter.slice(0, 3)].map((t) => `${t.type} ${t.count}`),
303
+ ...(p.frames?.length ? { frames: p.frames } : {}),
304
+ })),
305
+ };
306
+ }
@@ -1,5 +1,6 @@
1
1
  import { type MapInfoSummary } from "../map/read-map-info.js";
2
2
  import { type ObjectsFile } from "../map/read-objects-xml.js";
3
+ import { type WaterArea } from "../map/write-water.js";
3
4
  import { type RgbImage } from "../map/read-tga.js";
4
5
  import { type T3HeightMap } from "../terrain/read-t3-height-map.js";
5
6
  import { type T3SyncCliffLevel } from "../terrain/read-t3-sync-cliff-level.js";
@@ -27,6 +28,8 @@ export type LoadedMapPackage = {
27
28
  readonly noPathing?: Uint8Array;
28
29
  /** Body count from the t3Water header. */
29
30
  readonly waterBodies: number;
31
+ /** The t3Water areas, empty when the map has none or its t3Water can't be read. */
32
+ readonly waterAreas: readonly WaterArea[];
30
33
  readonly mapScript: string;
31
34
  readonly terrainData: string;
32
35
  readonly lightData: string;
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { readMapInfo } from "../map/read-map-info.js";
4
4
  import { readObjectsXml } from "../map/read-objects-xml.js";
5
+ import { readT3Water } from "../map/write-water.js";
5
6
  import { readTga } from "../map/read-tga.js";
6
7
  import { readT3FluffDoodad } from "../terrain/read-t3-fluff-doodad.js";
7
8
  import { readT3HeightMap } from "../terrain/read-t3-height-map.js";
@@ -13,6 +14,15 @@ import { readT3VertCol, readT3VertColHeader, vertexValueGrid } from "../terrain/
13
14
  function readOptional(file) {
14
15
  return existsSync(file) ? readFileSync(file) : undefined;
15
16
  }
17
+ /** A study leaves out water it can't read, as it does a painted layer, rather than fail. */
18
+ function readWaterAreas(water) {
19
+ try {
20
+ return readT3Water(water);
21
+ }
22
+ catch {
23
+ return [];
24
+ }
25
+ }
16
26
  export function loadMapPackage(dir) {
17
27
  const at = (name) => path.join(dir, name);
18
28
  const terrain = readT3TerrainXml(readFileSync(at("t3Terrain.xml"), "utf8"));
@@ -39,6 +49,7 @@ export function loadMapPackage(dir) {
39
49
  ...(pathing && cellAttributeFits(pathing, terrain.width, terrain.height) ? { noPathing: readCellAttribute(pathing, terrain.width, terrain.height) } : {}),
40
50
  fluffCount: fluff ? readT3FluffDoodad(fluff).entries.length : 0,
41
51
  waterBodies: water && water.length >= 16 ? water.readUInt32LE(12) : 0,
52
+ waterAreas: water ? readWaterAreas(water) : [],
42
53
  mapScript: readOptional(at("MapScript.galaxy"))?.toString("utf8") ?? "",
43
54
  terrainData: gameData("TerrainData.xml"),
44
55
  lightData: gameData("LightData.xml"),
@@ -295,6 +295,7 @@ export declare function buildMapStudy(exemplar: ExemplarEntry, map: LoadedMapPac
295
295
  };
296
296
  points: number;
297
297
  };
298
+ measures: import("./measures.js").MapMeasures;
298
299
  };
299
300
  images: Record<string, RgbImage>;
300
301
  };
@@ -3,6 +3,7 @@ import { measureComposition } from "./measure-composition.js";
3
3
  import { measureDoodads, studyDoodads } from "./measure-doodads.js";
4
4
  import { measureLighting } from "./measure-lighting.js";
5
5
  import { measureTexturing } from "./measure-texturing.js";
6
+ import { measureMap } from "./measures.js";
6
7
  import { PX, renderDoodads, renderElevation, renderHeight, CONTOUR, renderPathing, renderTextures, renderVertexShading } from "./render-layers.js";
7
8
  import { buildTerrainGrid } from "./terrain-grid.js";
8
9
  export const MAP_STUDY_VERSION = 1;
@@ -35,6 +36,8 @@ export function buildMapStudy(exemplar, map) {
35
36
  doodads: measureDoodads(map, grid, doodads),
36
37
  lighting: measureLighting(map),
37
38
  composition: measureComposition(map, grid),
39
+ // The lesson-neutral measures (measures.ts), which a consistency report reads from the study, so it needs no source map.
40
+ measures: measureMap(map),
38
41
  };
39
42
  return { study, images };
40
43
  }
@@ -1,4 +1,10 @@
1
1
  import type { LoadedMapPackage } from "./load-map-package.js";
2
+ /** Each GameSetLighting call in MapScript.galaxy with the function that makes it. */
3
+ export declare function lightingCalls(script: string): {
4
+ light: string;
5
+ blendSeconds: number | string;
6
+ inFunction: string;
7
+ }[];
2
8
  export declare function measureLighting(map: LoadedMapPackage): {
3
9
  note: string;
4
10
  lightsUsed: string[];
@@ -3,7 +3,7 @@ function value(body, tag) {
3
3
  return xmlElement(body, tag)?.attrs.value;
4
4
  }
5
5
  /** Each GameSetLighting call in MapScript.galaxy with the function that makes it. */
6
- function lightingCalls(script) {
6
+ export function lightingCalls(script) {
7
7
  const calls = [];
8
8
  let fn = "";
9
9
  for (const line of script.split("\n")) {
@@ -0,0 +1,225 @@
1
+ import { type Catalog } from "../catalog/catalog-layer.js";
2
+ import type { LoadedMapPackage } from "./load-map-package.js";
3
+ import { type StudiedDoodad } from "./measure-doodads.js";
4
+ import { type TerrainGrid } from "./terrain-grid.js";
5
+ /** Whether a doodad type is a helper a player doesn't see as dressing: a light, curtain, blocker or marker. */
6
+ export declare const isHelperDoodad: (type: string) => boolean;
7
+ /** The facts every measure reads, worked out once per map. */
8
+ export type MeasureInput = {
9
+ readonly map: LoadedMapPackage;
10
+ readonly grid: TerrainGrid;
11
+ /** Every doodad, helpers included. */
12
+ readonly doodads: readonly StudiedDoodad[];
13
+ /** The doodads that aren't helpers. */
14
+ readonly visible: readonly StudiedDoodad[];
15
+ /** The texture with the largest share of each cell. */
16
+ readonly dominant: readonly string[];
17
+ /** The whole cliff levels with playable, non-ramp cells, lowest first. */
18
+ readonly levels: readonly number[];
19
+ /** Playable, non-ramp cells per level. */
20
+ readonly levelCells: ReadonlyMap<number, number>;
21
+ /** Playable, non-ramp cells in all. */
22
+ readonly playable: number;
23
+ readonly main: number;
24
+ };
25
+ /** `catalog`: whose doodads it knows, for their kinds; a map studied alone uses the game's. */
26
+ export declare function measureInput(map: LoadedMapPackage, catalog?: Catalog): MeasureInput;
27
+ /** The texture with the largest share of each cell (the first layer on a tie). */
28
+ export declare function dominantTextures(grid: TerrainGrid): string[];
29
+ /** Each level's top texture by dominant cells, its share of the level, and the level's share of the playable ground. */
30
+ export declare function topTextureByLevel(input: MeasureInput): {
31
+ level: number;
32
+ texture: string;
33
+ share: number;
34
+ cellShare: number;
35
+ }[];
36
+ /** The visible doodads standing on playable ground. */
37
+ export declare function visibleOnPlayable(input: MeasureInput): StudiedDoodad[];
38
+ /**
39
+ * A level's share of the visible doodads against its share of the ground: 1 is as dense as the
40
+ * map, below 1 sparser. NaN on a map with no visible doodads.
41
+ */
42
+ export declare function doodadDensityRatio(input: MeasureInput, level: number): number;
43
+ /** An area the size of one capture frame, in cells. */
44
+ export declare const FRAME_AREA: {
45
+ readonly width: 18;
46
+ readonly height: 12;
47
+ };
48
+ /** Frame-sized areas on the main level, by how many textures they hold, with the doodads in each kind. */
49
+ export type FrameAreaTexturing = {
50
+ /** Areas at least 80% on the main level's playable, non-ramp cells. */
51
+ readonly areas: number;
52
+ /** Those holding one texture. */
53
+ readonly singleTexture: number;
54
+ /** Per kind of area: [areas, non-decal visible doodads, decals]. */
55
+ readonly doodads: {
56
+ readonly single: [number, number, number];
57
+ readonly mixed: [number, number, number];
58
+ };
59
+ };
60
+ /**
61
+ * Tiles the map with frame-sized areas from its south-west corner, keeps those mostly on the main
62
+ * level, and counts a texture as in an area once it gives 0.5% of the area's main-level cells.
63
+ */
64
+ export declare function frameAreaTexturing(input: MeasureInput): FrameAreaTexturing;
65
+ /** Playable cells by how many textures they blend, and where the blended ones sit. */
66
+ export type BlendPlacement = {
67
+ readonly cells: number;
68
+ /** Cells with one texture at 10% or more. */
69
+ readonly singleTexture: number;
70
+ /** Cells with two or more. */
71
+ readonly blended: number;
72
+ /** Blended cells within 2 cells (either way, diagonals too) of a border between dominant textures. */
73
+ readonly blendedNearBorder: number;
74
+ /** Cell sides between two playable cells of different dominant textures. */
75
+ readonly borderEdges: number;
76
+ };
77
+ export declare function blendPlacement(input: MeasureInput): BlendPlacement;
78
+ /** Doodad kinds a yaw-snapping measure groups: natural props, built props and decals. */
79
+ export declare const PROP_KINDS: {
80
+ readonly natural: readonly ["rock", "tree", "foliage"];
81
+ readonly built: readonly ["ruin", "other"];
82
+ readonly decal: readonly ["decal"];
83
+ };
84
+ /** Whether a yaw (radians) sits within a degree of a 45-degree step. */
85
+ export declare function isSnappedYaw(yaw: number): boolean;
86
+ /** The share of `doodads` on a 45-degree step; null when there are none. */
87
+ export declare function snappedShare(doodads: readonly StudiedDoodad[]): number | null;
88
+ /** The visible doodads of one group of PROP_KINDS. */
89
+ export declare function propsOfKind(input: MeasureInput, group: keyof typeof PROP_KINDS): StudiedDoodad[];
90
+ /** The ground below the main level, and what covers it. */
91
+ export type Backdrop = {
92
+ /** Playable, non-ramp cells below the main level. */
93
+ readonly cells: number;
94
+ /** Those under a t3Water area. */
95
+ readonly underWater: number;
96
+ /** Those on level 0 of a map that hides its lowest level, showing the sky. */
97
+ readonly underSky: number;
98
+ /** Those under either. */
99
+ readonly covered: number;
100
+ readonly hidesLowestLevel: boolean;
101
+ /** The tileset's fog density; 0 when its fog is switched off, undefined when nothing sets it. */
102
+ readonly fogDensity: number | undefined;
103
+ };
104
+ export declare function backdrop(input: MeasureInput): Backdrop;
105
+ /** Whether a doodad type is a point light (an omni light doodad). */
106
+ export declare const isPointLight: (type: string) => boolean;
107
+ /** The lighting changes the map's triggers make (GameSetLighting in MapScript.galaxy), and its point lights. */
108
+ export type LightingChanges = {
109
+ readonly lights: readonly string[];
110
+ readonly changes: number;
111
+ /** Changes with a blend time of 0. */
112
+ readonly instant: number;
113
+ /** The longest blend time given as a number; undefined with none. */
114
+ readonly longestBlendSeconds: number | undefined;
115
+ readonly pointLights: number;
116
+ };
117
+ export declare function lightingChanges(input: MeasureInput): LightingChanges;
118
+ /** Cliff crossings counted, and those whose dominant texture differs on the two sides: [crossings, changed]. */
119
+ export type CliffCrossings = {
120
+ readonly down: [number, number];
121
+ readonly up: [number, number];
122
+ readonly other: [number, number];
123
+ };
124
+ /**
125
+ * Every 4-neighbour step between two whole levels, with whether the dominant texture differs
126
+ * `back` cells behind the edge on each side. Split into crossings down into a pit (the low side
127
+ * below the main level), up onto a height (the high side above it) and the others. Edges in the
128
+ * map's outer two cells (three on the north and east) are left out, and so is a crossing whose
129
+ * sample cells fall off the map. The measures sample 2 cells back; the Antioch pack's lessons
130
+ * script lets its maintainer try others.
131
+ */
132
+ export declare function cliffCrossings(input: MeasureInput, back?: number): CliffCrossings;
133
+ /** What a lesson-neutral measure measures, for a report to say. */
134
+ export type MeasureDefinition = {
135
+ readonly id: string;
136
+ readonly description: string;
137
+ };
138
+ /** Every measure `measureMap` gives, in the order a report lists them. */
139
+ export declare const MEASURES: readonly [{
140
+ readonly id: "topTextureShare.lowestLevel";
141
+ readonly description: "share of the lowest level's cells whose dominant texture is its top texture; none when the lowest level is the main level";
142
+ }, {
143
+ readonly id: "topTextureShare.mainLevel";
144
+ readonly description: "share of the main level's cells whose dominant texture is its top texture";
145
+ }, {
146
+ readonly id: "topTextureShare.highestLevel";
147
+ readonly description: "share of the highest level's cells whose dominant texture is its top texture; none when the highest level is the main level";
148
+ }, {
149
+ readonly id: "cliffTextureChange.downIntoPit";
150
+ readonly description: "share of cliff crossings down into a pit (below the main level) whose dominant texture differs 2 cells back on each side";
151
+ }, {
152
+ readonly id: "cliffTextureChange.upOntoHeight";
153
+ readonly description: "share of cliff crossings up onto a height (above the main level) whose dominant texture differs 2 cells back on each side";
154
+ }, {
155
+ readonly id: "doodadDensity.lowestLevel";
156
+ readonly description: "the lowest level's share of the visible doodads over its share of the ground (1 = as dense as the map); none when the lowest level is the main level";
157
+ }, {
158
+ readonly id: "doodadDensity.mainLevel";
159
+ readonly description: "the main level's share of the visible doodads over its share of the ground (1 = as dense as the map)";
160
+ }, {
161
+ readonly id: "doodadDensity.highestLevel";
162
+ readonly description: "the highest level's share of the visible doodads over its share of the ground (1 = as dense as the map); none when the highest level is the main level";
163
+ }, {
164
+ readonly id: "doodadDensity.perHundredCells";
165
+ readonly description: "visible doodads on playable ground per 100 playable, non-ramp cells";
166
+ }, {
167
+ readonly id: "frameAreas.singleTextureShare";
168
+ readonly description: "share of frame-sized areas (18x12 cells) on the main level holding one texture, a texture counting from 0.5% of an area";
169
+ }, {
170
+ readonly id: "blend.nearBorderShare";
171
+ readonly description: "share of blended cells (two or more textures each giving 10%) within 2 cells of a border between dominant textures";
172
+ }, {
173
+ readonly id: "blend.width";
174
+ readonly description: "blended cells within 2 cells of a border, per cell side of border between dominant textures on playable ground: roughly the blend band's mean width in cells, from thin seams (near 0) to wide soft blends (at most about 5)";
175
+ }, {
176
+ readonly id: "blend.singleTextureCellShare";
177
+ readonly description: "share of playable cells with only one texture giving 10% or more";
178
+ }, {
179
+ readonly id: "yawSnapping.natural";
180
+ readonly description: "share of visible natural props (rocks, trees, foliage) turned to within a degree of a 45-degree step";
181
+ }, {
182
+ readonly id: "yawSnapping.built";
183
+ readonly description: "share of visible built props (ruins and other structures) turned to within a degree of a 45-degree step";
184
+ }, {
185
+ readonly id: "yawSnapping.decal";
186
+ readonly description: "share of visible decals turned to within a degree of a 45-degree step";
187
+ }, {
188
+ readonly id: "backdrop.share";
189
+ readonly description: "share of the playable, non-ramp ground below the main level (the backdrop: pits, abyss floors, void)";
190
+ }, {
191
+ readonly id: "backdrop.waterShare";
192
+ readonly description: "share of the backdrop under a water or lava area";
193
+ }, {
194
+ readonly id: "backdrop.skyShare";
195
+ readonly description: "share of the backdrop on a hidden lowest level, showing the sky";
196
+ }, {
197
+ readonly id: "backdrop.coveredShare";
198
+ readonly description: "share of the backdrop under water or lava or showing the sky";
199
+ }, {
200
+ readonly id: "backdrop.fogDensity";
201
+ readonly description: "the map's tileset fog density, its own CTerrain's where it sets one; 0 with fog off";
202
+ }, {
203
+ readonly id: "lighting.lightsSet";
204
+ readonly description: "distinct lights the map's triggers set (GameSetLighting)";
205
+ }, {
206
+ readonly id: "lighting.changes";
207
+ readonly description: "GameSetLighting calls in the map's triggers";
208
+ }, {
209
+ readonly id: "lighting.instantShare";
210
+ readonly description: "share of the triggers' lighting changes that cut at once (a blend time of 0)";
211
+ }, {
212
+ readonly id: "lighting.longestBlendSeconds";
213
+ readonly description: "the longest blend time of a trigger's lighting change, in seconds";
214
+ }, {
215
+ readonly id: "lighting.pointLightShare";
216
+ readonly description: "share of all doodads that are point lights (LightOmni)";
217
+ }, {
218
+ readonly id: "lighting.pointLightsPerHundredCells";
219
+ readonly description: "point lights (LightOmni) per 100 playable, non-ramp cells";
220
+ }];
221
+ export type MeasureId = (typeof MEASURES)[number]["id"];
222
+ /** One map's value of every measure; null where the map has nothing to measure (no pit, no props of a kind). */
223
+ export type MapMeasures = Record<MeasureId, number | null>;
224
+ /** Every lesson-neutral measure of one map. */
225
+ export declare function measureMap(map: LoadedMapPackage, catalog?: Catalog): MapMeasures;