mirror of
https://github.com/smogon/sprites.git
synced 2026-08-20 00:34:22 -05:00
deploy: spritename uses map for extra
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
|
||||
export type SpriteName = {id : number | string, extra : [string, string][]};
|
||||
export type SpriteName = {id : number | string, extra : Map<string, string>};
|
||||
|
||||
export function parse(s : string) : SpriteName {
|
||||
const parts = s.split("-");
|
||||
const id = parts[0].match(/^[0-9]+$/) ? parseInt(parts[0], 10) : parts[0];
|
||||
const extra : [string, string][] = [];
|
||||
const extra = new Map<string, string>();
|
||||
for (const part of parts.slice(1)) {
|
||||
if (part.length === 0)
|
||||
throw new Error(`Can't parse ${s}`);
|
||||
extra.push([part[0], part.slice(1)]);
|
||||
extra.set(part[0], part.slice(1));
|
||||
}
|
||||
return {id, extra};
|
||||
}
|
||||
@@ -16,11 +16,9 @@ export function parse(s : string) : SpriteName {
|
||||
export function format(si : SpriteName) {
|
||||
let s = si.id.toString();
|
||||
const extra = [];
|
||||
for (const [k, v] of si.extra) {
|
||||
for (const [k, v] of si.extra.entries()) {
|
||||
extra.push(`-${k}${v}`);
|
||||
}
|
||||
extra.sort();
|
||||
return s + extra.join('');
|
||||
}
|
||||
|
||||
// TODO: update()?
|
||||
|
||||
Reference in New Issue
Block a user