@shieldbattery/broodmap 0.0.0-stage → 0.2.0
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/LICENSE-APACHE +177 -0
- package/LICENSE-MIT +19 -0
- package/README.md +235 -2
- package/node-entry.js +13 -0
- package/package.json +53 -3
- package/pkg/broodmap_wasm.d.ts +565 -0
- package/pkg/broodmap_wasm.js +1659 -0
- package/pkg/broodmap_wasm_bg.wasm +0 -0
- package/pkg/broodmap_wasm_bg.wasm.d.ts +77 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,236 @@
|
|
|
1
|
-
#
|
|
1
|
+
# broodmap-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebAssembly bindings for rendering StarCraft: Brood War map previews in the browser (or Node):
|
|
4
|
+
`MapRenderer` parses a map, names the assets it needs (the two-round prefetch API — asset keys
|
|
5
|
+
are CASC catalog paths, which double as URL suffixes), accepts the fetched bytes, and renders
|
|
6
|
+
previews, zero-asset minimaps, and render-plan JSON synchronously from memory.
|
|
7
|
+
|
|
8
|
+
## Map summary
|
|
9
|
+
|
|
10
|
+
`summarizeMapJson(mapBytes, options?)` reads a map's scenario facts without rendering anything or
|
|
11
|
+
needing game assets, for listing and filtering map files cheaply. `options` is optional
|
|
12
|
+
`MapLimitOptions` JSON overriding broodmap's default resource limits (`maxMapBytes`,
|
|
13
|
+
`maxMpqFileBytes`, `maxChkBytes`, `maxMergedChunkBytes`), for callers that accept larger maps;
|
|
14
|
+
`new MapRenderer(mapBytes, options?)` takes the same options. It returns `MapSummary` JSON (both
|
|
15
|
+
types are in the package's TypeScript declarations):
|
|
16
|
+
|
|
17
|
+
| Field | Meaning |
|
|
18
|
+
| ----- | ------- |
|
|
19
|
+
| `name`, `description` | Decoded scenario strings, color codes included. `null` when unset. |
|
|
20
|
+
| `width`, `height`, `tileset` | Dimensions in tiles and the ERA tileset id. |
|
|
21
|
+
| `stringEncoding` | How strings were decoded: `utf8`, `utf8-cp949`, `utf8-cp1252`, `cp949` or `cp1252`. |
|
|
22
|
+
| `players` | The 8 player slots: `controller` (`OWNR` value), `race` (`SIDE` value) and `force` (force index; 4 or more means none). |
|
|
23
|
+
| `forces` | The 4 forces' `name`s. |
|
|
24
|
+
| `usesEud` | Whether triggers read or write memory outside the death table. |
|
|
25
|
+
| `triggerActionKinds`, `triggerCount` | The distinct trigger action kinds used (names such as `CreateUnit`, sorted; empty `NoAction` slots don't count), and how many triggers there are. |
|
|
26
|
+
| `placedUnits`, `playerUnits`, `startLocations` | Placed units (and those owned by one of the 8 player slots), not counting start locations, and the number of start locations. |
|
|
27
|
+
|
|
28
|
+
It throws if the file isn't a readable map within those limits, or lacks the name, player or
|
|
29
|
+
force sections. A `MapRenderer` gives the same JSON from `summaryJson()`, so a map that's also
|
|
30
|
+
rendered is only parsed once.
|
|
31
|
+
|
|
32
|
+
WebAssembly memory grows to fit the largest map parsed and never shrinks, so summarizing a folder
|
|
33
|
+
of maps (especially with raised limits) keeps that much memory for the life of the module. Scan
|
|
34
|
+
from a worker that can be terminated afterwards to give it back.
|
|
35
|
+
|
|
36
|
+
## Package
|
|
37
|
+
|
|
38
|
+
Published as `@shieldbattery/broodmap`, an ES module package built once with `wasm-pack --target
|
|
39
|
+
web`. Browsers and bundlers get `pkg/broodmap_wasm.js` and must `await init()` before using it.
|
|
40
|
+
Node gets `node-entry.js`, which loads the same build synchronously from disk, so it's ready on
|
|
41
|
+
import (and `require()`, through Node's `require(esm)`); calling `init()` there is a harmless no-op.
|
|
42
|
+
It needs Node 22.13.1 or later.
|
|
43
|
+
|
|
44
|
+
`pnpm run build` builds `pkg/`; `pnpm run test:package` and `pnpm run test:types` check the built
|
|
45
|
+
package through its entry points.
|
|
46
|
+
|
|
47
|
+
## Browser example
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pnpm install
|
|
51
|
+
pnpm run assets:analysis # terrain tables and units.dat (~2.2 MB); minimap-backed analysis needs no artwork
|
|
52
|
+
pnpm run assets # fetch the style-complete SD asset set (~98 MB) into examples/assets
|
|
53
|
+
# (uses a local SC:R install; add -- --cdn for no install)
|
|
54
|
+
pnpm run dev # build the wasm package and serve examples/ with vite
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Pick a `.scm`/`.scx` map (e.g. `../broodmap/assets/lt.scm`) and render. The asset directory is
|
|
58
|
+
produced by `broodmap-cli fetch-assets`, which writes files at exactly the paths the bindings
|
|
59
|
+
request — any static file host works as an asset origin.
|
|
60
|
+
|
|
61
|
+
## Node
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm run build
|
|
65
|
+
node examples/node.mjs ../broodmap/assets/lt.scm examples/assets out.png
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
WASM renders are byte-identical to the native CLI's (verified against `broodmap-cli render`).
|
|
69
|
+
|
|
70
|
+
### Reading a SC:R install
|
|
71
|
+
|
|
72
|
+
Where the game install is readable synchronously (Node, Electron), `CascStorage` reads assets
|
|
73
|
+
straight from its CASC storage, so no prefetch or extracted asset directory is needed:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
const storage = new CascStorage(files) // opens .build.info, indices and catalogs (~55 ms)
|
|
77
|
+
const map = new MapRenderer(mapBytes)
|
|
78
|
+
const missing = map.loadAssets(storage, opts) // art assets the install lacks; those degrade
|
|
79
|
+
const png = map.renderPng(opts)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`files` is the sync file access broodcasc reads through, with paths relative to the install
|
|
83
|
+
directory (the one containing `.build.info`): `open(path)` returns a handle, `size(handle)`,
|
|
84
|
+
`read(handle, buffer, position)` returns the bytes read, `close(handle)`, and `listDir(path)`
|
|
85
|
+
returns names (`[]` when the directory doesn't exist). `read` fills a view of WASM memory in
|
|
86
|
+
place, so the callbacks mustn't call back into the module. `examples/casc-files.mjs` implements
|
|
87
|
+
it over `node:fs`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm run build
|
|
91
|
+
node examples/node-casc.mjs "C:/Program Files (x86)/StarCraft" ../broodmap/assets/lt.scm
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Decoded assets are cached per `CascStorage` and shared by every map loaded from it (every render
|
|
95
|
+
needs the ~38 MB `SD/mainSD.anim`). `new CascStorage(files, '{"cacheBytes": N}')` bounds the
|
|
96
|
+
cache (default 128 MiB, about the whole `original`-style set). `storage.version` is the
|
|
97
|
+
install's game version, for keying rendered-image caches. `free()` the storage to close its files.
|
|
98
|
+
|
|
99
|
+
`pkg/` and `examples/assets/` are build/game-data artifacts and are gitignored;
|
|
100
|
+
the assets are Blizzard's and must never be committed.
|
|
101
|
+
|
|
102
|
+
## Terrain inspector (experimental)
|
|
103
|
+
|
|
104
|
+
Choose a map and click **Analyze terrain**. That tileset's CV5/VF4 and the small `arr/units.dat` collision table are fetched.
|
|
105
|
+
The inspector starts with a minimap backdrop; **Render** adds the full preview artwork.
|
|
106
|
+
Toggle walkability, static obstacles, elevation, terrain buildability, or ramps; hover for cell attributes.
|
|
107
|
+
**Respect map obstacles** is enabled by default; turn it off to compare terrain-only routes.
|
|
108
|
+
Click two walkable cells to compare a ground route with the straight air-distance line.
|
|
109
|
+
A third click starts a new route. Parsing, rendering, and routing run in a worker.
|
|
110
|
+
|
|
111
|
+
Click **Find bases** to discover resource clusters and candidate depot footprints. Select **Base A**
|
|
112
|
+
and **Base B**, then **Compare bases** for an orange ground route and dashed air-distance line.
|
|
113
|
+
The obstacle toggle preserves base IDs and recomputes the selected comparison. Base labels include
|
|
114
|
+
mineral/geyser counts and nearby start players; they do not assign main/natural roles.
|
|
115
|
+
|
|
116
|
+
Discovery clusters resources by terrain connectivity and uses a stock 4x3 depot footprint.
|
|
117
|
+
Candidate scoring accounts for static blockers and balances mineral and gas access. Sites marked
|
|
118
|
+
`*` require clearing small mineral patches or overlapping buildings, highlighted in orange when
|
|
119
|
+
selected. Exact start sites can clear overlapping objects automatically when occupied, including
|
|
120
|
+
invincible ones. Current routes retain all these objects because this snapshot does not know the
|
|
121
|
+
active starting assignments. Creep/power, full placement
|
|
122
|
+
legality, and optimal gathering are not established. Small mineral groups may be omitted as bases,
|
|
123
|
+
and qualifying clusters with no suitable site are reported.
|
|
124
|
+
|
|
125
|
+
The routing model is an 8-pixel point grid with eight directions and no diagonal corner
|
|
126
|
+
cutting. Resources and grounded neutral buildings from UNIT/THG2 block intersecting cells
|
|
127
|
+
using caller-supplied units.dat collision bounds. It ignores moving units, mover sizes,
|
|
128
|
+
and exact engine movement; narrow gaps can be overblocked. Turning obstacles off ignores
|
|
129
|
+
all of them, including invincible buildings, rather than simulating their destruction. Ground distance uses fixed-point step costs (8 px orthogonal, 11.312 px diagonal),
|
|
130
|
+
not travel time. Clicks snap to cell centers; distances use logical pixels, not output-image
|
|
131
|
+
pixels (32 logical pixels = one map tile). Terrain buildability is a CV5 flag hint, not a
|
|
132
|
+
building-placement validator. See [the analysis design](../docs/analysis-design.md).
|
|
133
|
+
|
|
134
|
+
Existing terrain-only exports need `arr/units.dat` added. To refresh the small analysis tables:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pnpm run assets:analysis
|
|
138
|
+
# Or just one map's tileset, from the repository root:
|
|
139
|
+
cargo run -p broodmap-cli -- fetch-assets --analysis-only --out broodmap-wasm/examples/assets broodmap/assets/lt.scm
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The usual `--install`, `--assets-dir`, and `--cdn` sources work with `--analysis-only`.
|
|
143
|
+
Full `fetch-assets` bundles now include VF4 as well. Nothing is uploaded by the demo.
|
|
144
|
+
|
|
145
|
+
Missing UNIT/THG2 chunks contribute no obstacles. The underlying parsers ignore incomplete
|
|
146
|
+
trailing records; `obstacleCount` is not a map-integrity check. Definitions with negative
|
|
147
|
+
collision extents are unsupported and skipped.
|
|
148
|
+
|
|
149
|
+
The independent WASM snapshot can also be used outside the example:
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
const [cv5Path, vf4Path, unitsPath] = map.requiredMapAnalysisAssets()
|
|
153
|
+
const analysis = map.analyzeMap(
|
|
154
|
+
await fetchBytes(cv5Path), await fetchBytes(vf4Path), await fetchBytes(unitsPath),
|
|
155
|
+
)
|
|
156
|
+
// analysis.setObstaclesEnabled(false) selects terrain-only routes and clearance.
|
|
157
|
+
const flags = analysis.cellFlags() // row-major; see generated TypeScript docs for bit layout
|
|
158
|
+
const clearance = analysis.clearancePixels() // Uint16Array, row-major square radii in logical pixels
|
|
159
|
+
// 0 = blocked; 4 = next to a blocker/map edge. Not unit passability or corridor width.
|
|
160
|
+
const regions = analysis.analyzeRegions(32, 40) // minimum drop: 32 pixels AND 40% of peak radius
|
|
161
|
+
try {
|
|
162
|
+
const labels = regions.labels() // owned Uint32Array; 0 blocked, region IDs start at 1
|
|
163
|
+
const graph = JSON.parse(regions.metadataJson()) // regions and representative passages
|
|
164
|
+
} finally {
|
|
165
|
+
regions.free()
|
|
166
|
+
}
|
|
167
|
+
const route = JSON.parse(analysis.routeJson(10, 20, 30, 40)) // walk-cell coordinates
|
|
168
|
+
// null groundDistancePixels means disconnected; invalid/blocked endpoints throw.
|
|
169
|
+
const catalog = JSON.parse(analysis.findBasesJson('{}'))
|
|
170
|
+
// Options: {depotWidthTiles:4,depotHeightTiles:3,maxMineralBlockerAmount:8}; unknown options throw.
|
|
171
|
+
// Use maxMineralBlockerAmount:null, allowDestructibleClearing:false, and
|
|
172
|
+
// allowStartObstacleClearing:false for strict current placement. See each base.requiredMinerals,
|
|
173
|
+
// requiredObstacles, and startClearedObstacles.
|
|
174
|
+
const bases = catalog.bases.filter(base => base.routeAnchor !== null)
|
|
175
|
+
if (bases.length >= 2) {
|
|
176
|
+
const baseRoute = JSON.parse(analysis.baseRouteJson(bases[0].id, bases[1].id))
|
|
177
|
+
const [ax, ay] = bases[0].routeAnchor
|
|
178
|
+
const [bx, by] = bases[1].routeAnchor
|
|
179
|
+
const entrances = JSON.parse(analysis.entrancesJson(ax, ay, bx, by, 25))
|
|
180
|
+
// Batch multiple destinations per origin to share route searches; outputs keep query order.
|
|
181
|
+
const surveys = JSON.parse(analysis.entrancesBatchJson(JSON.stringify([
|
|
182
|
+
[[ax, ay], [bx, by]], [[bx, by], [ax, ay]],
|
|
183
|
+
]), 25))
|
|
184
|
+
// Terrain-only survey from A toward B. Span endpoints are pixels; route points are walk cells.
|
|
185
|
+
// An outward width marked outwardWidthIsLowerBound is not an exact measured opening width.
|
|
186
|
+
const areas = analysis.partitionAreas(JSON.stringify(entrances.candidates.map(c => c.endpoints)))
|
|
187
|
+
try {
|
|
188
|
+
const labels = areas.labels() // every terrain-walkable cell keeps a positive component ID
|
|
189
|
+
const evidence = JSON.parse(areas.metadataJson()) // areas and effects of all supplied cuts
|
|
190
|
+
} finally {
|
|
191
|
+
areas.free()
|
|
192
|
+
}
|
|
193
|
+
// These virtual partition boundaries do not change ordinary routes or clearance regions.
|
|
194
|
+
}
|
|
195
|
+
analysis.free()
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`requiredAnalysisAssets()` / `analyzeTerrain(cv5, vf4)` remain available for terrain-only callers.
|
|
199
|
+
|
|
200
|
+
Select **Clearance** in the demo overlay menu to inspect narrow passages and open areas.
|
|
201
|
+
Hover details include the numerical clearance radius with any overlay.
|
|
202
|
+
The heatmap and hover radius follow **Respect map obstacles**. **Color scale maximum** defaults
|
|
203
|
+
to 256px; choose a smaller range for tight gaps or a larger range for open areas. It changes
|
|
204
|
+
only the colors, not the measured radii. Radius measures a centered,
|
|
205
|
+
axis-aligned empty square and includes the map boundary; it is not an engine movement test.
|
|
206
|
+
|
|
207
|
+
Use **Find regions** to color open-area partitions and mark candidate passages. Increase
|
|
208
|
+
peak prominence or minimum relative narrowing to merge minor clearance peaks. Relative narrowing
|
|
209
|
+
(default 40%) suppresses shallow splits in broad rooms, including those around resources.
|
|
210
|
+
Base descriptions show their route anchor's region when available. Changing either threshold
|
|
211
|
+
or obstacle mode clears the partition; run
|
|
212
|
+
**Find regions** again to compare. Passage radii are square clearance values, not choke widths.
|
|
213
|
+
|
|
214
|
+
After **Find bases**, select A and B and choose **Inspect entrances at A and B** to test the
|
|
215
|
+
one-sided width detector in both directions. It searches the first 32 build tiles outward from
|
|
216
|
+
each base along terrain-only survey routes. Labels A1/B1 identify the surveyed end, with widths
|
|
217
|
+
and outward widening reported separately for each direction. Adjust **Minimum widening**
|
|
218
|
+
to compare candidates. Region prominence settings do not affect this experiment. The detector
|
|
219
|
+
can miss other exits and does not establish a sealed chokepoint or legal building wall.
|
|
220
|
+
|
|
221
|
+
**Test base areas at A and B** also surveys each selected base's three nearest anchored bases.
|
|
222
|
+
These connections are batched by origin. The terrain snapshot reuses prepared clearance and its
|
|
223
|
+
original connected components across calls; changing maps creates a fresh snapshot.
|
|
224
|
+
The public batch API accepts up to 256 queries, but each distinct origin can still require a
|
|
225
|
+
full-grid search. The query/output limits are not a CPU budget; callers needing responsive
|
|
226
|
+
cancellation should submit smaller origin groups and yield between synchronous calls.
|
|
227
|
+
It closes the proposed crossings for an experimental terrain-only component flood and selects
|
|
228
|
+
**Experimental base areas** in the overlay menu. Cyan/purple show the two selected components;
|
|
229
|
+
amber means both bases remain in the same component. Green boundary lines separate components
|
|
230
|
+
with all cuts applied; dashed amber lines retain bypassed crossings. The summary lists the known
|
|
231
|
+
bases still connected inside each selected area. This local experiment can miss exits and does
|
|
232
|
+
not alter normal routes, certify wallability, or replace the clearance region overlay.
|
|
233
|
+
|
|
234
|
+
For a static demo build, run `pnpm run build:demo`. The output is `examples/dist/`.
|
|
235
|
+
Game assets are not bundled: serve an exported asset directory separately and set the
|
|
236
|
+
asset-base field to its URL (with CORS enabled when hosted on a different origin).
|
package/node-entry.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The package's Node entry: the web build, initialized synchronously from disk so it can be used
|
|
2
|
+
// as soon as it's imported (or required). Calling the default init export again is a no-op, so code
|
|
3
|
+
// shared with the browser can still `await init()`.
|
|
4
|
+
//
|
|
5
|
+
// Not named node.js: cmd.exe looks in the current directory before PATH and .JS is in PATHEXT, so
|
|
6
|
+
// a bare `node` in this package's scripts would open this file instead of running Node.
|
|
7
|
+
import { readFileSync } from 'node:fs'
|
|
8
|
+
import { initSync } from './pkg/broodmap_wasm.js'
|
|
9
|
+
|
|
10
|
+
initSync({ module: readFileSync(new URL('./pkg/broodmap_wasm_bg.wasm', import.meta.url)) })
|
|
11
|
+
|
|
12
|
+
export * from './pkg/broodmap_wasm.js'
|
|
13
|
+
export { default } from './pkg/broodmap_wasm.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shieldbattery/broodmap",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "WebAssembly bindings for broodmap: StarCraft: Brood War map summaries, previews and terrain analysis",
|
|
6
|
+
"main": "./node-entry.js",
|
|
7
|
+
"types": "./pkg/broodmap_wasm.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./pkg/broodmap_wasm.d.ts",
|
|
11
|
+
"node": "./node-entry.js",
|
|
12
|
+
"default": "./pkg/broodmap_wasm.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"pkg/broodmap_wasm*",
|
|
17
|
+
"node-entry.js",
|
|
18
|
+
"LICENSE-APACHE",
|
|
19
|
+
"LICENSE-MIT"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.13.1"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/ShieldBattery/broodmap.git",
|
|
30
|
+
"directory": "broodmap-wasm"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"starcraft",
|
|
34
|
+
"map",
|
|
35
|
+
"parser",
|
|
36
|
+
"wasm",
|
|
37
|
+
"webassembly"
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT OR Apache-2.0",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "7.0.2",
|
|
42
|
+
"vite": "^8.3.5"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "wasm-pack build --target web --no-pack && node scripts/finalize-package.mjs",
|
|
46
|
+
"clean": "node -e \"require('node:fs').rmSync('pkg', { recursive: true, force: true })\"",
|
|
47
|
+
"assets:analysis": "cargo run --release -p broodmap-cli -- fetch-assets --analysis-only --out examples/assets",
|
|
48
|
+
"assets": "cargo run --release -p broodmap-cli -- fetch-assets --out examples/assets",
|
|
49
|
+
"dev": "pnpm run build && vite",
|
|
50
|
+
"build:demo": "pnpm run build && vite build",
|
|
51
|
+
"check:versions": "node scripts/check-versions.mjs",
|
|
52
|
+
"test": "pnpm run check:versions && node --test examples/*.test.mjs tests/topology-reference/*.test.mjs",
|
|
53
|
+
"test:package": "node --test scripts/package.test.mjs",
|
|
54
|
+
"test:types": "tsc --noEmit --strict --target ES2022 --module NodeNext --moduleResolution NodeNext scripts/types-consumer.ts && tsc --noEmit --strict --target ES2022 --module ESNext --moduleResolution Bundler scripts/types-consumer.ts"
|
|
55
|
+
}
|
|
6
56
|
}
|