Files
deltasprite/scripts/write.ts
2025-07-20 16:23:48 +05:00

57 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from "node:fs";
const PATHS = {
ORIGINAL: "../sprites/original",
TRANSLATE: "../sprites/translation",
};
let DATA = {};
// Сбор списка глав
for (const chapter of fs.readdirSync(PATHS.ORIGINAL)) {
if (chapter != ".DS_Store") DATA[chapter] = {};
}
// Внос всех одно-кадровых спрайтов
function add_singles(path) {
const chapter_dir = fs.readdirSync(path, "utf-8");
let temp = {};
for (const sprite of chapter_dir)
if (sprite.includes(".png")) temp[sprite.slice(0, -4)] = [0];
return temp;
}
// Внос всех много-кадровых спрайтов
function add_animations(path) {
const chapter_dir = fs.readdirSync(path, "utf-8");
let temp = {};
for (const sprite of chapter_dir) {
if (!(sprite.endsWith(".png") || sprite.endsWith(".DS_Store"))) {
let frames = new Array();
const animation_dir = fs.readdirSync(`${path}/${sprite}`, "utf-8");
for (let frame of animation_dir) {
let frame_number = frame.split("_").at(-1) ?? "fuck";
if (frame.endsWith(".png"))
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));