import fs from "node:fs"; import { PATHS } from "./shared"; let DATA: { [key: string]: any } = {}; for (const chapter of fs.readdirSync(PATHS.ORIGINAL)) DATA[chapter] = {}; function add_singles(path: string) { const chapter_sprites = fs.readdirSync(path, "utf-8"); const temp: { [key: string]: any } = {}; for (const sprite of chapter_sprites) if (sprite.includes(".png")) temp[sprite.slice(0, -4)] = [0]; return temp; } function add_animations(path: string) { const chapter_sprites = fs.readdirSync(path, "utf-8"); const temp: { [key: string]: any } = {}; for (const sprite of chapter_sprites) { if (!sprite.endsWith(".png")) { const frames = new Array(); const animated_sprite = fs.readdirSync(`${path}/${sprite}`, "utf-8"); for (let frame of animated_sprite) { let frame_number = frame.split("_").at(-1); if (frame.endsWith(".png") && frame_number !== undefined) frames.push(Number(frame_number.slice(0, -4))); } temp[sprite] = frames.sort(); } } return temp; } for (const chapter of Object.keys(DATA)) { const chapter_path = `${PATHS.ORIGINAL}/${chapter}`; DATA[chapter] = { ...add_animations(chapter_path), ...add_singles(chapter_path), }; } fs.writeFileSync("./data.json", JSON.stringify(DATA));