adding merged sorted zip
This commit is contained in:
60
scripts/merge.py
Executable file
60
scripts/merge.py
Executable file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from PIL import Image
|
||||
|
||||
in_dir = sys.argv[1]
|
||||
out_dir = sys.argv[2]
|
||||
|
||||
os.makedirs(in_dir, exist_ok=True)
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
|
||||
sprs = {}
|
||||
|
||||
for item in os.listdir(in_dir):
|
||||
item_path = os.path.join(in_dir, item)
|
||||
|
||||
if os.path.isfile(item_path) and item.lower().endswith('.png'):
|
||||
shutil.copy2(item_path, os.path.join(out_dir, item))
|
||||
continue
|
||||
|
||||
if not os.path.isdir(item_path):
|
||||
continue
|
||||
|
||||
frames = []
|
||||
for frame_file in os.listdir(item_path):
|
||||
if not frame_file.lower().endswith('.png'):
|
||||
continue
|
||||
|
||||
try:
|
||||
frame_num = int(frame_file.split('_')[-1].split('.')[0])
|
||||
frames.append((frame_num, frame_file))
|
||||
except (IndexError, ValueError):
|
||||
continue
|
||||
|
||||
frames.sort(key=lambda x: x[0])
|
||||
sprs[item] = []
|
||||
|
||||
for _, frame_file in frames:
|
||||
try:
|
||||
img = Image.open(os.path.join(item_path, frame_file))
|
||||
sprs[item].append(img)
|
||||
except Exception as e:
|
||||
print(f"Ошибка загрузки {frame_file}: {e}")
|
||||
|
||||
for spr_name, images in sprs.items():
|
||||
if not images:
|
||||
continue
|
||||
|
||||
width = images[0].width
|
||||
height = images[0].height
|
||||
total_width = width * len(images)
|
||||
|
||||
sprite_sheet = Image.new('RGBA', (total_width, height))
|
||||
|
||||
for i, img in enumerate(images):
|
||||
sprite_sheet.paste(img, (i * width, 0))
|
||||
|
||||
output_path = os.path.join(out_dir, f"{spr_name}.png")
|
||||
sprite_sheet.save(output_path)
|
||||
print(f"Создан: {output_path} ({len(images)} кадров)")
|
||||
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import { spawn } from "child_process";
|
||||
|
||||
const SPECIALS = ["sp", "spm"];
|
||||
const DATA = JSON.parse(fs.readFileSync("./data.json", "utf-8"));
|
||||
@@ -19,8 +20,6 @@ UNIQUES_FRAMES?.shift();
|
||||
while (UNIQUES_NAMES?.at(-1) == "") UNIQUES_NAMES?.pop();
|
||||
while (UNIQUES_FRAMES?.at(-1) == "") UNIQUES_FRAMES?.pop();
|
||||
|
||||
export const SHARED = UNIQUES_FRAMES;
|
||||
|
||||
function add_singles(chapter, sprite_name) {
|
||||
const img_name = `${sprite_name}.png`;
|
||||
if (!fs.existsSync(`../_sprites/translation/${img_name}`)) return;
|
||||
@@ -141,3 +140,11 @@ if (UNIQUES_NAMES != undefined) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const chapter of chapters) {
|
||||
spawn("python3", [
|
||||
"merge.py",
|
||||
`../_sprites/sorted/${chapter}`,
|
||||
`../_sprites/sorted-merged/${chapter}`,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2,30 +2,6 @@ import fs from "node:fs";
|
||||
|
||||
const CHAPTERS = JSON.parse(fs.readFileSync("./data.json", "utf-8"));
|
||||
|
||||
const DELETE = fs
|
||||
.readFileSync("../_sprites/delete.txt", "utf-8")
|
||||
.split("DELETE:")
|
||||
.at(-1)
|
||||
?.split("\n");
|
||||
|
||||
DELETE?.shift();
|
||||
if (DELETE?.at(-1) == "") DELETE?.pop();
|
||||
|
||||
if (DELETE != undefined) {
|
||||
for (const del of DELETE) {
|
||||
if (fs.existsSync(`../_sprites/${del}`))
|
||||
fs.rmSync(`../_sprites/${del}`, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
else if (fs.existsSync(`../_sprites/${del}.png`))
|
||||
fs.rmSync(`../_sprites/${del}.png`, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const UNIQUES = fs
|
||||
.readFileSync("../_sprites/unique.txt", "utf-8")
|
||||
.split("UNIQUE FOR SORTING:")
|
||||
Reference in New Issue
Block a user