mirror of
https://github.com/bdnugget/rs-sdk.git
synced 2026-11-07 09:07:30 +00:00
716a9375f removed collision-data.json from tracking and gitignored it as
"regenerable", but sdk/pathfinding.ts imports it statically -- so a fresh
clone hard-failed on import with no way to know why. Nothing fetched it.
Re-track it. The anti-bloat rationale was already sunk cost: that commit
never rewrote history, so all 12 prior collision-data blobs remain reachable
and every clone already pays for them. One more version costs ~3.4MB packed
(23MB raw, but it's highly repetitive), against a 259MB .git.
Add sdk/fetch-collision-data.ts to regenerate it from a running server,
replacing the bare curl in DEVELOPERS.md -- it buffers before writing so an
interrupted download can't leave a truncated file that breaks the import,
and needs --force to clobber. The committed copy is a fresh export: 123,648
zones (= 483 mapsquares, full coverage), 1,068,791 tiles, 2,603 doors.
Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
#!/usr/bin/env bun
|
|
// Refreshes sdk/collision-data.json, which sdk/pathfinding.ts imports directly.
|
|
// The file IS tracked in git, so a clone already has a working copy — this script
|
|
// is for regenerating it after map changes, or pulling from a non-default server.
|
|
// Commit the result: a stale tracked copy is how 442-vs-483 mapsquare drift crept
|
|
// in before. Requires --force to overwrite an existing file.
|
|
import { existsSync, statSync } from 'fs';
|
|
import { writeFile } from 'fs/promises';
|
|
import { join } from 'path';
|
|
|
|
const DEFAULT_SERVER = 'https://rs-sdk-demo.fly.dev';
|
|
const OUTPUT_PATH = join(import.meta.dir, 'collision-data.json');
|
|
|
|
async function fetchCollisionData(server: string, force: boolean) {
|
|
if (existsSync(OUTPUT_PATH) && !force) {
|
|
const mb = (statSync(OUTPUT_PATH).size / 1_000_000).toFixed(1);
|
|
console.log(`collision-data.json already present (${mb}MB) - skipping. Use --force to refresh.`);
|
|
return;
|
|
}
|
|
|
|
const url = `${server}/api/exportCollision`;
|
|
console.log(`Fetching collision data from ${url} ...`);
|
|
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error(`${url} returned ${response.status} ${response.statusText}`);
|
|
}
|
|
|
|
// Buffer fully before writing so an interrupted download can't leave a
|
|
// truncated file behind — pathfinding.ts would fail to parse it on import.
|
|
const body = await response.arrayBuffer();
|
|
if (body.byteLength === 0) {
|
|
throw new Error(`${url} returned an empty body`);
|
|
}
|
|
|
|
await writeFile(OUTPUT_PATH, new Uint8Array(body));
|
|
const mb = (body.byteLength / 1_000_000).toFixed(1);
|
|
console.log(`Wrote ${OUTPUT_PATH} (${mb}MB)`);
|
|
}
|
|
|
|
const args = process.argv.slice(2);
|
|
const force = args.includes('--force');
|
|
const serverArg = args.find(a => a.startsWith('--server='))?.split('=')[1];
|
|
const server = serverArg || process.env.COLLISION_SERVER || DEFAULT_SERVER;
|
|
|
|
try {
|
|
await fetchCollisionData(server, force);
|
|
} catch (e) {
|
|
console.error(`\nFailed to fetch collision data: ${e instanceof Error ? e.message : e}`);
|
|
console.error('Pathfinding (sdk/pathfinding.ts) will not work until this file exists.');
|
|
console.error(`Retry with: bun sdk/fetch-collision-data.ts --force --server=${server}`);
|
|
process.exit(1);
|
|
}
|