Files
deltasprite/scripts/sort.ts
snus xD 3409c45ad5 test
2025-08-16 22:13:00 +04:00

136 lines
4.3 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 SPECIALS = ["sp", "spm"];
const DATA = JSON.parse(fs.readFileSync("./data.json", "utf-8"));
const chapters = fs.readdirSync("../_sprites/original");
const UNIQUES = fs
.readFileSync("../_sprites/unique.txt", "utf-8")
.split("УНИКАЛЬНЫЕ ДЛЯ РУСИФИКАТОРА:")
.at(-1)
?.split("УНИКАЛЬНОЕ КОЛ-ВО КАДРОВ:");
const UNIQUES_NAMES = UNIQUES != undefined ? UNIQUES[0].split("\n") : [];
UNIQUES_NAMES?.shift();
const UNIQUES_FRAMES = UNIQUES != undefined ? UNIQUES[1].split("\n") : [];
UNIQUES_FRAMES?.shift();
while (UNIQUES_NAMES?.at(-1) == "") UNIQUES_NAMES?.pop();
while (UNIQUES_FRAMES?.at(-1) == "") UNIQUES_FRAMES?.pop();
function add_singles(chapter, sprite_name) {
const img_name = `${sprite_name}.png`;
if (!fs.existsSync(`../_sprites/translation/${img_name}`)) return;
fs.copyFileSync(
`../_sprites/translation/${img_name}`,
`../_sprites/sorted/${chapter}/${img_name}`
);
for (const special of SPECIALS) {
if (fs.existsSync(`../_sprites/translation/${special}_${img_name}`)) {
fs.copyFileSync(
`../_sprites/translation/${special}_${img_name}`,
`../_sprites/sorted/${chapter}/${special}_${img_name}`
);
}
}
}
function add_animations(chapter, sprite_name) {
if (
fs.existsSync(`../_sprites/translation/${sprite_name}`) &&
!fs.existsSync(`../_sprites/sorted/${chapter}/${sprite_name}`)
) {
if (UNIQUES_FRAMES.includes(sprite_name))
fs.mkdirSync(`../_sprites/sorted/${chapter}/${sprite_name}`);
else
fs.cpSync(
`../_sprites/original/${chapter}/${sprite_name}`,
`../_sprites/sorted/${chapter}/${sprite_name}`,
{ recursive: true, force: true }
);
} else return;
for (const special of SPECIALS) {
if (fs.existsSync(`../_sprites/translation/${special}_${sprite_name}`)) {
fs.cpSync(
`../_sprites/original/${chapter}/${sprite_name}`,
`../_sprites/sorted/${chapter}/${special}_${sprite_name}`,
{ recursive: true, force: true }
);
for (const file of fs.readdirSync(
`../_sprites/sorted/${chapter}/${special}_${sprite_name}`
)) {
const oldPath = `../_sprites/sorted/${chapter}/${special}_${sprite_name}/${file}`;
const newPath = `../_sprites/sorted/${chapter}/${special}_${sprite_name}/${special}_${file}`;
fs.renameSync(oldPath, newPath);
}
}
}
const sprite_frames = DATA[chapter][sprite_name];
for (let frame of sprite_frames) {
const img_name = `${sprite_name}_${frame}.png`;
if (!fs.existsSync(`../_sprites/translation/${sprite_name}/${img_name}`))
continue;
for (const special of SPECIALS) {
if (
fs.existsSync(
`../_sprites/translation/${special}_${sprite_name}/${special}_${img_name}`
)
) {
fs.copyFileSync(
`../_sprites/translation/${special}_${sprite_name}/${special}_${img_name}`,
`../_sprites/sorted/${chapter}/${special}_${sprite_name}/${special}_${img_name}`
);
}
}
fs.copyFileSync(
`../_sprites/translation/${sprite_name}/${img_name}`,
`../_sprites/sorted/${chapter}/${sprite_name}/${img_name}`
);
}
}
for (const chapter of chapters) {
if (!chapter.endsWith(".DS_Store")) {
if (!fs.existsSync(`../_sprites/sorted`))
fs.mkdirSync(`../_sprites/sorted`);
if (!fs.existsSync(`../_sprites/sorted/${chapter}`))
fs.mkdirSync(`../_sprites/sorted/${chapter}`);
for (const sprite of Object.keys(DATA[chapter])) {
const frames: any[] = DATA[chapter][sprite];
if (frames.length == 1) add_singles(chapter, sprite);
else add_animations(chapter, sprite);
}
}
}
if (UNIQUES_NAMES != undefined) {
for (const unique of UNIQUES_NAMES) {
const uniqueChapter = unique.split("/")[0];
const uniqueName = unique.split("/")[1];
if (fs.existsSync(`../_sprites/translation/${uniqueName}.png`))
fs.copyFileSync(
`../_sprites/translation/${uniqueName}.png`,
`../_sprites/sorted/${uniqueChapter}/${uniqueName}.png`
);
if (fs.existsSync(`../_sprites/translation/${uniqueName}`))
fs.cpSync(
`../_sprites/translation/${uniqueName}`,
`../_sprites/sorted/${uniqueChapter}/${uniqueName}`,
{ recursive: true, force: true }
);
}
}
// :P