Something went wrong. Try again.
Web frontend and supporting services for lance.blue
Something went wrong. Try again.
1.9 kB · 45 lines
JavaScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546/** * The units every vendored scenario file names, in either of the two forms a * `.mms` comes in. * * The catalog is the `.mms` files themselves now, not a transcription of them * in Rust, so this reads what MegaMek reads. V1 names a unit on a * `Unit_<faction>_<n>=` line whose first comma-separated field is the chassis * and whose rest is the crew. V2 names it as `fullname:` inside a faction's * `units:` list, and the whole value is the name — a V2 unit's crew is its own * `crew:` mapping rather than more fields on the same line. * * Both, and not one: every scenario in the catalog is V1 and every daily * challenge is V2, so a reader that knew only V1 saw none of the dailies and * reported every one of their machines as needing no art. */export function scenarioUnits(sources) { const units = new Set(); for (const text of sources) { for (const line of text.split(/\r?\n/)) { const trimmed = line.trim(); const v1 = /^Unit_[^=]+=([^,]+)/.exec(trimmed); if (v1) units.add(v1[1].trim()); // Only a list item, so a `fullname:` under some other key is not one of // these. Comments are stripped first: `#` starts one anywhere in a V2 // file, and the dailies carry long ones. const v2 = /^-\s+fullname:\s*(.+)$/.exec(trimmed.replace(/\s+#.*$/, "")); if (v2) units.add(v2[1].trim()); } } return units;}
/** Every vendored scenario file's text, from the API's catalog directory. */export async function scenarioSources(repo, readFile, readdir, join) { const root = join(repo, "services/api/src/matches/scenarios"); const entries = await readdir(root, { recursive: true, withFileTypes: true }); const out = []; for (const entry of entries) { if (!entry.isFile() || !entry.name.endsWith(".mms")) continue; out.push( await readFile(join(entry.parentPath ?? root, entry.name), "utf8"), ); } return out;}