move deploy/spritename to data

This commit is contained in:
Christopher Monsanto
2020-08-26 08:21:33 -04:00
parent 2f0556f4fa
commit 164d0e090e
5 changed files with 27 additions and 28 deletions

View File

@@ -33,3 +33,28 @@ export function get(id : number) : Type {
export function entries() : [number, Type][] {
return Array.from(result.entries());
}
// TODO Moved here from deploy/spritename.ts, better place to put these??
export type SpriteFilename = {id : number | string, extra : Map<string, string>};
export function parseFilename(s : string) : SpriteFilename {
const parts = s.split("-");
const id = parts[0].match(/^[0-9]+$/) ? parseInt(parts[0], 10) : parts[0];
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.set(part[0], part.slice(1));
}
return {id, extra};
}
export function formatFilename(si : SpriteFilename) {
let s = si.id.toString();
const extra = [];
for (const [k, v] of si.extra.entries()) {
extra.push(`-${k}${v}`);
}
extra.sort();
return s + extra.join('');
}

View File

@@ -4,7 +4,7 @@ function toID(name) {
}
function spritecopy(f, {dir, ext}) {
const sn = spritename.parse(f.name);
const sn = spritedata.parseFilename(f.name);
let name;
if (typeof sn.id === 'string') {
name = toID(sn.id);

View File

@@ -6,7 +6,7 @@ function toSmogonAlias(name) {
}
function spritecopy(f, {dir, ext}) {
const sn = spritename.parse(f.name);
const sn = spritedata.parseFilename(f.name);
let name;
// Skip asymmetrical for now

View File

@@ -3,7 +3,6 @@ import fs from 'fs';
import nodePath from 'path';
import vm from 'vm';
import * as pathlib from './path.js';
import * as spritename from './spritename.js';
import * as spritedata from '@smogon/sprite-data';
@@ -172,7 +171,6 @@ export class Script extends vm.Script {
const SKIP = {};
const ENV0 = {
spritename,
spritedata,
SKIP,
// Because throw SKIP isn't an expression

View File

@@ -1,24 +0,0 @@
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 = new Map<string, string>();
for (const part of parts.slice(1)) {
if (part.length === 0)
throw new Error(`Can't parse ${s}`);
extra.set(part[0], part.slice(1));
}
return {id, extra};
}
export function format(si : SpriteName) {
let s = si.id.toString();
const extra = [];
for (const [k, v] of si.extra.entries()) {
extra.push(`-${k}${v}`);
}
extra.sort();
return s + extra.join('');
}