python_script
code:yukkuri_converter_for_YMM4.py
# YMM4における目パチ口パク時のリネーム作業を自動化するpythonスクリプトです
# 要Pillow、python3
# 新きつねゆっくりと神威式くらいしか確認してないので、動作の保証はありません
# このスクリプトにゆっくりのフォルダをD&Dすれば動きます(複数フォルダのD&Dには対応していません)
from pprint import pprint
import sys
from pathlib import Path
import re
import shutil
import string
from PIL import Image
# 必要なフォルダパスだけを取り出す
def makepath(parent):
genpath = (p for p in Path(r"{}".format(sys.argv1)).glob(
parent+'/*.png'))
return genpath
# リネーム
def rename(targetgen):
animlist = next(targetgen)
for i in targetgen:
if animlist0.stem:2 == i.stem:2 and animlist0.parent == i.parent:
animlist.append(i)
elif i.name2 == 'v':
animlist = i
else:
if len(animlist) >= 3:
if animlist0.stem:2 == animlist1.stem:2:
temp = animlist0.stem
# animlist内のファイルの親フォルダが「目」ならanimlistの順番を反転。これやらないとYMM4の目パチ仕様の違いにより目が閉じっぱなしになる。
if animlist0.parent.stem == '目':
animlist.reverse()
animlist2 = [r.with_name(temp+f'zex.{p}'+r.suffix)
for p, r in enumerate(animlist)]
animlist2len(animlist2)-1 = animlist2[len(animlist2) -
1].with_name(temp+'zex'+animlist2len(animlist2)-1.suffix)
for s, t in zip(animlist, animlist2):
if s != t:
shutil.copy(s, t)
# animlistを書き換え、animlist2を念のためクリア
animlist = i
animlist2.clear()
# YMM4上では使えないフォルダからファイルを移す
def moving(targetgen, tofolder):
animlist = []
predict = {'顔': 'face_', '後': 'back_', '口': 'mouth_', '全': 'all_', '他': 'other_',
'髪': 'hair_', '眉': 'brow_', '服下': 'under_', '服上': 'over_', '目': 'eye_'}
for i in targetgen:
if i.parent.stem == '目' and i.name2 == 'v':
animlist.append(i)
elif i.parent.stem != '目':
animlist.append(i)
animlist2 = [Path(str(p.parent.with_name(
tofolder))+'/'+predictp.parent.stem+p.stem+p.suffix) for p in animlist]
for s, t in zip(animlist, animlist2):
if s != t:
shutil.move(str(s), str(t))
# 目と口以外のアニメーションファイルをwebpファイルに変換して動かす
def makewebp(targetgen):
animlist = next(targetgen)
for i in targetgen:
if i.parent.stem == '他' and animlist0.stem:2 == i.stem:2:
animlist.append(i)
else:
animlist = i
if len(animlist) >= 3:
for p, q in enumerate(animlist):
if len(q.stem) < 3:
animlist.pop(p)
im = Image.open(p) for p in animlist
im0.save(animlist0.with_suffix('.webp'), append_images=im,
save_all=True, duration=30, minimize_size=True)
# YMM4に存在しない髪や服上といったパーツをまとめて、体として使えるファイルに変換する
def blendbody(targetgen):
backlist = Path('N')
bodylist = Path('N')
hairlist = Path('N')
overlist = Path('N')
underlist = Path('N')
for q in targetgen:
if re.match('back_', q.stem):
backlist.append(q)
elif re.match('hair_', q.stem):
hairlist.append(q)
elif re.match('over_', q.stem):
overlist.append(q)
elif re.match('under_', q.stem):
underlist.append(q)
elif re.match('all_', q.stem):
pass
else:
bodylist.append(q)
dummy = Image.new('RGBA', Image.open(bodylist1).size, (0, 0, 0, 0))
for a in backlist:
for b in bodylist:
for c in hairlist:
for d in overlist:
for e in underlist:
if a.name != 'N':
templist = a, b, c, d, e
webpim = []
for ext in templist:
if ext.name != 'N':
webpim.append(Image.open(ext))
else:
webpim.append(dummy)
for ex in range(4):
webpim0.paste(
webpimex+1, (0, 0), webpimex+1)
webpim0.save(a.with_name(
a.stem+'body_'+b.stem+c.stem+d.stem+e.stem+'.png'))
def main():
rename(makepath('口'))
makewebp(makepath('他'))
rename(makepath('目'))
moving(makepath('後'), '体')
moving(makepath('全'), '体')
moving(makepath('髪'), '体')
moving(makepath('服下'), '体')
moving(makepath('服上'), '体')
blendbody(makepath('体'))
if __name__ == '__main__':
main()