BurningTimesAi/공유/기획/FirstRising/아이템/icon_pack.py

52 lines
2.6 KiB
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
# 2026-10-02 PD 지시(자율 반복) — 검토를 통과한 그림을 리소스 묶음으로 만든다.
# python icon_pack.py <출력 폴더 이름> <picks json 이름들 쉼표로> [시트 칸 수=10]
# 예: python icon_pack.py final_v4 picks_a13.json,picks_a14.json,picks_a17.json
# 결과: moba_anfg/<출력 폴더>/<종류>_<번호>.png (1024 투명 · 여백 통일) + final_sheet.png(종류 순서로 정렬)
import io, json, os, re, sys
from PIL import Image, ImageDraw
from icon_finalize import finalize
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.join(HERE, "moba_anfg")
# 시트에 놓는 순서: 무기 → 방어구 → 장신구 → 보조 장비
ORDER = ["sword", "dagger", "magic_dagger", "offhand_sword", "axe", "blunt", "hammer", "bow", "staff", "armor", "helmet", "gloves", "belt", "boots",
"ring", "necklace", "shield", "quiver", "spellbook", "throwing", "orb", "totem", "horn"]
def kind_of(fn):
m = re.match(r"^[a-z0-9]+_(.+)_s\d+_\d+\.png$", fn)
return m.group(1).split("-")[0] if m else "etc"
def main():
out = os.path.join(ROOT, sys.argv[1])
cols = int(sys.argv[3]) if len(sys.argv) > 3 else 10
files = []
for name in sys.argv[2].split(","):
files += list(json.load(io.open(os.path.join(ROOT, name), encoding="utf-8")).values())
files = sorted(set(files), key=lambda f: (ORDER.index(kind_of(f)) if kind_of(f) in ORDER else 99, f))
os.makedirs(out, exist_ok=True)
cell, pad = 180, 4
rows = (len(files) + cols - 1) // cols
sheet = Image.new("RGB", (cols * (cell + pad) + pad, rows * (cell + pad) + pad), (24, 24, 28))
draw = ImageDraw.Draw(sheet)
count, index = {}, []
for i, fn in enumerate(files):
k = kind_of(fn)
count[k] = count.get(k, 0) + 1
name = "%s_%02d" % (k, count[k])
im = finalize(os.path.join(ROOT, fn))
im.save(os.path.join(out, name + ".png"))
index.append({"icon": name + ".png", "source": fn})
bg = Image.new("RGB", (cell, cell), (40, 40, 46)); small = im.resize((cell, cell), Image.LANCZOS); bg.paste(small, (0, 0), small)
x, y = pad + (i % cols) * (cell + pad), pad + (i // cols) * (cell + pad)
sheet.paste(bg, (x, y)); draw.text((x + 3, y + 2), name, fill=(220, 220, 220))
sheet.save(os.path.join(out, "final_sheet.png"))
json.dump(index, io.open(os.path.join(out, "index.json"), "w", encoding="utf-8"), ensure_ascii=False, indent=1)
print("%d icons -> %s · 종류별 %s" % (len(files), out, sorted(count.items(), key=lambda x: -x[1])))
if __name__ == "__main__":
main()