refactor: just updated scripts for better reading

This commit is contained in:
snus xD
2025-12-24 09:35:53 +03:00
parent 14a1b9d5e7
commit f0b87a6da0
4 changed files with 95 additions and 105 deletions

View File

@@ -1,76 +1,60 @@
import fs from "node:fs";
import { PATHS, DATA, CHAPTERS, UNIQUES_NAMES, UNIQUES_FRAMES } from "./shared";
import { spawn } from "child_process";
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("UNIQUE FOR SORTING:")
.at(-1)
?.split("UNIQUE FRAME COUNT:");
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) {
function add_singles(chapter: string, sprite_name: string) {
const img_name = `${sprite_name}.png`;
if (!fs.existsSync(`../_sprites/translation/${img_name}`)) return;
if (!fs.existsSync(`${PATHS.TRANSLATION}/${img_name}`)) return;
fs.copyFileSync(
`../_sprites/translation/${img_name}`,
`../_sprites/sorted/${chapter}/${img_name}`
`${PATHS.TRANSLATION}/${img_name}`,
`${PATHS.SORTED}/${chapter}/${img_name}`
);
for (const special of SPECIALS) {
if (fs.existsSync(`../_sprites/translation/${special}_${img_name}`)) {
if (fs.existsSync(`${PATHS.TRANSLATION}/${special}_${img_name}`)) {
fs.copyFileSync(
`../_sprites/translation/${special}_${img_name}`,
`../_sprites/sorted/${chapter}/${special}_${img_name}`
`${PATHS.TRANSLATION}/${special}_${img_name}`,
`${PATHS.SORTED}/${chapter}/${special}_${img_name}`
);
}
}
}
function add_animations(chapter, sprite_name) {
function add_animations(chapter: string, sprite_name: string) {
if (
fs.existsSync(`../_sprites/translation/${sprite_name}`) &&
!fs.existsSync(`../_sprites/sorted/${chapter}/${sprite_name}`)
fs.existsSync(`${PATHS.TRANSLATION}/${sprite_name}`) &&
!fs.existsSync(`${PATHS.SORTED}/${chapter}/${sprite_name}`)
) {
if (UNIQUES_FRAMES.includes(sprite_name))
fs.cpSync(
`../_sprites/translation/${sprite_name}`,
`../_sprites/sorted/${chapter}/${sprite_name}`,
`${PATHS.TRANSLATION}/${sprite_name}`,
`${PATHS.SORTED}/${chapter}/${sprite_name}`,
{ recursive: true, force: true }
);
else
fs.cpSync(
`../_sprites/original/${chapter}/${sprite_name}`,
`../_sprites/sorted/${chapter}/${sprite_name}`,
`${PATHS.SORTED}/${chapter}/${sprite_name}`,
{ recursive: true, force: true }
);
} else return;
for (const special of SPECIALS) {
if (fs.existsSync(`../_sprites/translation/${special}_${sprite_name}`)) {
if (fs.existsSync(`${PATHS.TRANSLATION}/${special}_${sprite_name}`)) {
fs.cpSync(
`../_sprites/original/${chapter}/${sprite_name}`,
`../_sprites/sorted/${chapter}/${special}_${sprite_name}`,
`${PATHS.SORTED}/${chapter}/${special}_${sprite_name}`,
{ recursive: true, force: true }
);
for (const file of fs.readdirSync(
`../_sprites/sorted/${chapter}/${special}_${sprite_name}`
`${PATHS.SORTED}/${chapter}/${special}_${sprite_name}`
)) {
const oldPath = `../_sprites/sorted/${chapter}/${special}_${sprite_name}/${file}`;
const newPath = `../_sprites/sorted/${chapter}/${special}_${sprite_name}/${special}_${file}`;
const oldPath = `${PATHS.SORTED}/${chapter}/${special}_${sprite_name}/${file}`;
const newPath = `${PATHS.SORTED}/${chapter}/${special}_${sprite_name}/${special}_${file}`;
fs.renameSync(oldPath, newPath);
}
@@ -82,35 +66,34 @@ function add_animations(chapter, sprite_name) {
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}`))
if (!fs.existsSync(`${PATHS.TRANSLATION}/${sprite_name}/${img_name}`))
continue;
for (const special of SPECIALS) {
if (
fs.existsSync(
`../_sprites/translation/${special}_${sprite_name}/${special}_${img_name}`
`${PATHS.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}`
`${PATHS.TRANSLATION}/${special}_${sprite_name}/${special}_${img_name}`,
`${PATHS.SORTED}/${chapter}/${special}_${sprite_name}/${special}_${img_name}`
);
}
}
fs.copyFileSync(
`../_sprites/translation/${sprite_name}/${img_name}`,
`../_sprites/sorted/${chapter}/${sprite_name}/${img_name}`
`${PATHS.TRANSLATION}/${sprite_name}/${img_name}`,
`${PATHS.SORTED}/${chapter}/${sprite_name}/${img_name}`
);
}
}
for (const chapter of chapters) {
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}`);
if (!fs.existsSync(`${PATHS.SORTED}`)) fs.mkdirSync(`${PATHS.SORTED}`);
if (!fs.existsSync(`${PATHS.SORTED}/${chapter}`))
fs.mkdirSync(`${PATHS.SORTED}/${chapter}`);
for (const sprite of Object.keys(DATA[chapter])) {
const frames: any[] = DATA[chapter][sprite];
@@ -126,26 +109,26 @@ if (UNIQUES_NAMES != undefined) {
const uniqueChapter = unique.split("/")[0];
const uniqueName = unique.split("/")[1];
if (fs.existsSync(`../_sprites/translation/${uniqueName}.png`))
if (fs.existsSync(`${PATHS.TRANSLATION}/${uniqueName}.png`))
fs.copyFileSync(
`../_sprites/translation/${uniqueName}.png`,
`../_sprites/sorted/${uniqueChapter}/${uniqueName}.png`
`${PATHS.TRANSLATION}/${uniqueName}.png`,
`${PATHS.SORTED}/${uniqueChapter}/${uniqueName}.png`
);
if (fs.existsSync(`../_sprites/translation/${uniqueName}`))
if (fs.existsSync(`${PATHS.TRANSLATION}/${uniqueName}`))
fs.cpSync(
`../_sprites/translation/${uniqueName}`,
`../_sprites/sorted/${uniqueChapter}/${uniqueName}`,
`${PATHS.TRANSLATION}/${uniqueName}`,
`${PATHS.SORTED}/${uniqueChapter}/${uniqueName}`,
{ recursive: true, force: true }
);
}
}
for (const chapter of chapters) {
for (const chapter of CHAPTERS) {
spawn("python3", [
"merge.py",
`../_sprites/sorted/${chapter}`,
`../_sprites/sorted-merged/${chapter}`,
`${PATHS.SORTED}/${chapter}`,
`${PATHS.SORTED}-merged/${chapter}`,
]);
}