formulabun / api

central api of everything formulabun
0 stars 0 forks source link

endpoint for characters #1

Open Fl0GUI opened 2 years ago

Fl0GUI commented 2 years ago

Since srb2kartjs has a wadparse now, it's possible to get character metadata out of them. The endpoint would work similar to the maps endpoint, so just write a script and the static endpoint itself. Throw in all the metadata you can find

Fl0GUI commented 2 years ago

Kinda have this already

async function getSkinFilesFromZip(zip) {
  return (await Promise.all(zip.file(/.*S_SKIN/).map(f => f.async('string')))).map(lines => ini.parse(lines).realname);
}

(async () => {
  const allfiles = (await readdir('chars'));
  const wadfiles = allfiles.filter(f => f.endsWith('wad'));
  const pk3files = allfiles.filter(f => f.endsWith('pk3'));
  (await Promise.all(wadfiles.map(w => getLump(`chars/${w}`, 'S_SKIN')))).map(b => ini.parse(b.toString()).realname).forEach((w) => console.log(w));
  _.flatten(await Promise.all(pk3files.map(async function(f) {
    const file = await readFile(`chars/${f}`);
    const zip = await JsZip.loadAsync(file);
    return getSkinFilesFromZip(zip);
  }))).forEach(w => console.log(w));
})()

This is an ugly script I wrote for the survey.