-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpriteHandler.py
More file actions
36 lines (32 loc) · 1.18 KB
/
SpriteHandler.py
File metadata and controls
36 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import yaml
import json
from PIL import Image
with open("SpriteGUID.json", 'r') as f:
spriteGuids = json.load(f)
with open("TextureGUID.json", 'r') as f:
texGuids = json.load(f)
def ripAllSprites():
for sprite in spriteGuids.values():
spriteName = sprite["file"]
ripSprite(spriteName)
def ripSprite(name):
if os.path.isfile(os.path.join("SpriteRip", name + ".png")):
return
assetname = os.path.join("Sprite", name + ".asset")
with open(assetname, 'r') as f:
spritedata = yaml.load(f, Loader=yaml.BaseLoader)
bb = spritedata["Sprite"]["m_RD"]["textureRect"]
tex = spritedata["Sprite"]["m_RD"]["texture"]
im = Image.open(os.path.join("Texture2D", texGuids[tex['guid']]+".png"))
left = round(float(bb['x']))
bottom = im.height - round(float(bb['y']))
top = bottom - round(float(bb['height']))
right = left + round(float(bb['width']))
cropped = im.crop((left, top, right, bottom))
cropped.save(os.path.join("SpriteRip", name + ".png"))
if __name__ == "__main__":
if not os.path.exists("SpriteRip"):
os.makedirs("SpriteRip")
ripSprite("Ayama_Crouch_0")
#ripAllSprites()