Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
Expand All @@ -29,7 +29,40 @@ jobs:
msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@1.95
- uses: Swatinem/rust-cache@v2
- run: cargo check --workspace

wasm:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['22.13.1', '24']
defaults:
run:
working-directory: broodmap-wasm
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: wasm-pack@0.15.0
- uses: pnpm/action-setup@v6
with:
package_json_file: broodmap-wasm/package.json
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: pnpm
cache-dependency-path: broodmap-wasm/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- run: pnpm test
- run: pnpm run build
- run: pnpm run test:package
- run: pnpm run test:types
- run: pnpm run build:demo
4 changes: 3 additions & 1 deletion broodmap-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# wasm-pack output
/pkg/
/pkg-node/
/node_modules/
# fetch-assets output: Blizzard game data, never committed
/examples/assets/
# Copied from the repository root by scripts/finalize-package.mjs
/LICENSE-APACHE
/LICENSE-MIT
43 changes: 41 additions & 2 deletions broodmap-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ WebAssembly bindings for rendering StarCraft: Brood War map previews in the brow
are CASC catalog paths, which double as URL suffixes), accepts the fetched bytes, and renders
previews, zero-asset minimaps, and render-plan JSON synchronously from memory.

## Map summary

`summarizeMapJson(mapBytes, options?)` reads a map's scenario facts without rendering anything or
needing game assets, for listing and filtering map files cheaply. `options` is optional
`MapLimitOptions` JSON overriding broodmap's default resource limits (`maxMapBytes`,
`maxMpqFileBytes`, `maxChkBytes`, `maxMergedChunkBytes`), for callers that accept larger maps;
`new MapRenderer(mapBytes, options?)` takes the same options. It returns `MapSummary` JSON (both
types are in the package's TypeScript declarations):

| Field | Meaning |
| ----- | ------- |
| `name`, `description` | Decoded scenario strings, color codes included. `null` when unset. |
| `width`, `height`, `tileset` | Dimensions in tiles and the ERA tileset id. |
| `stringEncoding` | How strings were decoded: `utf8`, `utf8-cp949`, `utf8-cp1252`, `cp949` or `cp1252`. |
| `players` | The 8 player slots: `controller` (`OWNR` value), `race` (`SIDE` value) and `force` (force index; 4 or more means none). |
| `forces` | The 4 forces' `name`s. |
| `usesEud` | Whether triggers read or write memory outside the death table. |
| `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. |
| `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. |

It throws if the file isn't a readable map within those limits, or lacks the name, player or
force sections. A `MapRenderer` gives the same JSON from `summaryJson()`, so a map that's also
rendered is only parsed once.

WebAssembly memory grows to fit the largest map parsed and never shrinks, so summarizing a folder
of maps (especially with raised limits) keeps that much memory for the life of the module. Scan
from a worker that can be terminated afterwards to give it back.

## Package

Published as `@shieldbattery/broodmap`, an ES module package built once with `wasm-pack --target
web`. Browsers and bundlers get `pkg/broodmap_wasm.js` and must `await init()` before using it.
Node gets `node.js`, which loads the same build synchronously from disk, so it's ready on import
(and `require()`, through Node's `require(esm)`); calling `init()` there is a harmless no-op. It
needs Node 22.13.1 or later.

`pnpm run build` builds `pkg/`; `pnpm run test:package` and `pnpm run test:types` check the built
package through its entry points.

## Browser example

```bash
Expand All @@ -22,13 +61,13 @@ request — any static file host works as an asset origin.
## Node

```bash
pnpm run build:node
pnpm run build
node examples/node.mjs ../broodmap/assets/lt.scm examples/assets out.png
```

WASM renders are byte-identical to the native CLI's (verified against `broodmap-cli render`).

`pkg/`, `pkg-node/` and `examples/assets/` are build/game-data artifacts and are gitignored;
`pkg/` and `examples/assets/` are build/game-data artifacts and are gitignored;
the assets are Blizzard's and must never be committed.

## Terrain inspector (experimental)
Expand Down
7 changes: 2 additions & 5 deletions broodmap-wasm/examples/node.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Node usage example: the same prefetch -> render flow as the browser, with assets read from a
// `fetch-assets` directory on disk. Build the node package first: `pnpm run build:node`.
// `fetch-assets` directory on disk. Build the package first: `pnpm run build`.
//
// node examples/node.mjs <map.scm> <assets-dir> [out.png]
import { readFileSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'

const require = createRequire(import.meta.url)
const { MapRenderer } = require('../pkg-node/broodmap_wasm.js')
import { MapRenderer } from '@shieldbattery/broodmap'

const [mapPath, assetsDir, outPath = 'preview.png'] = process.argv.slice(2)
if (!mapPath || !assetsDir) {
Expand Down
10 changes: 10 additions & 0 deletions broodmap-wasm/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// The package's Node entry: the web build, initialized synchronously from disk so it can be used
// as soon as it's imported (or required). Calling the default init export again is a no-op, so code
// shared with the browser can still `await init()`.
import { readFileSync } from 'node:fs'
import { initSync } from './pkg/broodmap_wasm.js'

initSync({ module: readFileSync(new URL('./pkg/broodmap_wasm_bg.wasm', import.meta.url)) })

export * from './pkg/broodmap_wasm.js'
export { default } from './pkg/broodmap_wasm.js'
53 changes: 43 additions & 10 deletions broodmap-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
{
"name": "broodmap-wasm",
"name": "@shieldbattery/broodmap",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "WebAssembly bindings for rendering StarCraft: Brood War map previews",
"description": "WebAssembly bindings for broodmap: StarCraft: Brood War map summaries, previews and terrain analysis",
"main": "./node.js",
"types": "./pkg/broodmap_wasm.d.ts",
"exports": {
".": {
"types": "./pkg/broodmap_wasm.d.ts",
"node": "./node.js",
"default": "./pkg/broodmap_wasm.js"
}
},
"files": [
"pkg/broodmap_wasm*",
"node.js",
"LICENSE-APACHE",
"LICENSE-MIT"
],
"engines": {
"node": ">=22.13.1"
},
"scripts": {
"build": "pnpm run build:web && pnpm run build:node",
"build:web": "wasm-pack build --target web",
"build:node": "wasm-pack build --target nodejs --out-dir pkg-node",
"build": "wasm-pack build --target web --no-pack && node scripts/finalize-package.mjs",
"clean": "node -e \"require('node:fs').rmSync('pkg', { recursive: true, force: true })\"",
"assets:analysis": "cargo run --release -p broodmap-cli -- fetch-assets --analysis-only --out examples/assets",
"assets": "cargo run --release -p broodmap-cli -- fetch-assets --out examples/assets",
"dev": "pnpm run build:web && vite",
"build:demo": "pnpm run build:web && vite build",
"test": "node --test examples/*.test.mjs tests/topology-reference/*.test.mjs"
"dev": "pnpm run build && vite",
"build:demo": "pnpm run build && vite build",
"test": "node --test examples/*.test.mjs tests/topology-reference/*.test.mjs",
"test:package": "node --test scripts/package.test.mjs",
"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",
"prepublishOnly": "pnpm run clean && pnpm run build && pnpm test && pnpm run test:package && pnpm run test:types"
},
"repository": {
"type": "git",
"url": "https://github.com/ShieldBattery/broodmap.git",
"directory": "broodmap-wasm"
},
"keywords": [
"starcraft",
"map",
"parser",
"wasm",
"webassembly"
],
"license": "MIT OR Apache-2.0",
"packageManager": "pnpm@12.15.0+sha512.b3951d6d6ff4a9f13dc7cf56cd28d2b8eb37dbcc9c68e52e1e1191873ea9f82a017287ab50baadc5ccc494f036c67c0e47eb13608c2fa36f47711b61ea128e61",
"devDependencies": {
"vite": "^7.1.5"
"typescript": "7.0.2",
"vite": "^8.3.5"
}
}
Loading
Loading