Add an importable file for the default Foundry images
This commit is contained in:
parent
b1a6752238
commit
ef63860922
4 changed files with 198 additions and 1 deletions
100
importable/findFoundryFiles.mjs
Normal file
100
importable/findFoundryFiles.mjs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import { globSync } from "glob";
|
||||
import crypto from "crypto";
|
||||
import { createReadStream } from "fs";
|
||||
import { writeFile } from "fs/promises";
|
||||
|
||||
async function hashFile(path) {
|
||||
return new Promise((resolve) => {
|
||||
const stream = createReadStream(path);
|
||||
const hash = crypto.createHash(`sha1`);
|
||||
hash.setEncoding(`hex`);
|
||||
|
||||
stream.on(`end`, () => {
|
||||
hash.end();
|
||||
resolve(hash.read());
|
||||
});
|
||||
|
||||
stream.pipe(hash);
|
||||
});
|
||||
};
|
||||
|
||||
const skipFiles = [
|
||||
`vtt.png`,
|
||||
`vtt-512.png`,
|
||||
`anvil.png`,
|
||||
`fvtt.icns`,
|
||||
`fvtt.ico`,
|
||||
`logo-scifi.png`,
|
||||
`logo-scifi-blank.png`,
|
||||
`LICENSE`,
|
||||
];
|
||||
|
||||
const tagRenames = {
|
||||
weapons: `weapon`,
|
||||
wands: `wand`,
|
||||
swords: `sword`,
|
||||
cutlasses: `cutlass`,
|
||||
daggers: `dagger`,
|
||||
commodities: `commodity`,
|
||||
feathers: `feather`,
|
||||
dynamite: `explosive`,
|
||||
bomb: `explosive`,
|
||||
}
|
||||
|
||||
const purgeTags = new Set([
|
||||
// All of the colours
|
||||
`white`, `yellow`, `blue`, `red`, `green`, `black`, `brown`, `teal`, `silver`, `purple`, `gray`, `grey`, `orange`, `lime`, `crimson`, `magenta`, `gold`, `cyan`, `pink`, `tan`, `violet`,
|
||||
|
||||
// Terms that just suck as tags
|
||||
`simple`, `ringed`, `hollow`, `guard`, `pressure`, `gas`, `fuse`,
|
||||
`cloth`, `sharp`, `worn`,
|
||||
]);
|
||||
|
||||
async function main() {
|
||||
const imageList = globSync(`foundry/public/icons/**/*`, { nodir: true });
|
||||
const images = {};
|
||||
|
||||
for (const path of imageList) {
|
||||
if (skipFiles.some(file => path.endsWith(file))) continue;
|
||||
|
||||
const hash = await hashFile(path);
|
||||
const filename = path.split(`/`).at(-1);
|
||||
|
||||
const tags = new Set(
|
||||
path
|
||||
.replace(`foundry/public/icons/`, ``)
|
||||
.replace(/\.[a-z]+$/i, ``)
|
||||
.replaceAll(`-`, `/`)
|
||||
.split(`/`)
|
||||
.map(tag => tagRenames[tag] ?? tag)
|
||||
.filter(tag => !purgeTags.has(tag))
|
||||
);
|
||||
|
||||
images[hash] = {
|
||||
name: filename,
|
||||
tags: Array.from(tags),
|
||||
artists: [`FVTT`],
|
||||
path: path.replace(`foundry/public/`, ``),
|
||||
external: true
|
||||
};
|
||||
};
|
||||
|
||||
const data = {
|
||||
images,
|
||||
artists: {
|
||||
FVTT: { // Using a custom artist ID since this is an import anyway
|
||||
name: `Foundry Defaults`,
|
||||
links: [
|
||||
{ name: `FoundryVTT`, url: `https://foundryvtt.com` }
|
||||
]
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
await writeFile(
|
||||
`importable/foundry.json`,
|
||||
JSON.stringify(data),
|
||||
);
|
||||
};
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue