deploy: spritename uses map for extra

This commit is contained in:
Christopher Monsanto
2020-08-23 03:38:29 -04:00
parent e98d42d0cf
commit b900864e11

View File

@@ -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()?