Reads the map JSON, optionally loads --atlas-dir paths for name resolution, and prints the inspector report to stdout. Missing file, bad JSON, and missing --atlas-dir paths all produce labelled stderr errors with exit 1.
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const USAGE = `usage: sporel-mapper <subcommand> [args...]
|
|
|
|
Subcommands:
|
|
encode <atlas_idx> <tile_id> [rotation]
|
|
Print the packed-u32 GID for the given components.
|
|
|
|
decode <gid>
|
|
Print the (atlas, tile, rotation) components of a GID.
|
|
|
|
build <spec.txt> <out.json> [--atlas-dir <path> ...]
|
|
Compile a text-DSL map spec into a v2 map JSON file.
|
|
|
|
inspect <map.json> [--atlas-dir <path> ...]
|
|
Print a human-readable stats report for a v2 map.
|
|
|
|
Options:
|
|
-h, --help Show this message.
|
|
`;
|
|
|
|
function run(argv, { out, err }) {
|
|
if (argv.length === 0) {
|
|
err.write(USAGE);
|
|
return 1;
|
|
}
|
|
const [head, ...rest] = argv;
|
|
if (head === '-h' || head === '--help') {
|
|
out.write(USAGE);
|
|
return 0;
|
|
}
|
|
const handlers = {
|
|
encode: require('./commands/encode'),
|
|
decode: require('./commands/decode'),
|
|
build: require('./commands/build'),
|
|
inspect: require('./commands/inspect'),
|
|
};
|
|
const handler = handlers[head];
|
|
if (!handler) {
|
|
err.write(`unknown subcommand: ${head}\n${USAGE}`);
|
|
return 1;
|
|
}
|
|
return handler.run(rest, { out, err });
|
|
}
|
|
|
|
module.exports = { run };
|