-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmkimages.py
executable file
·70 lines (59 loc) · 2.03 KB
/
mkimages.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import glob
import lupa
import os
import shutil
import zipfile
import subprocess
from os.path import isfile, join, dirname
def mkIcon(src, dest):
subprocess.run(["convert", "-size", "32x32", "canvas:transparent", "-background", "transparent",
"-alpha", "on",
"(",
src, "-resize", "26x26", "-repage", "+3+6",
"(", "+clone", "-repage", "+3+3", ")",
"(", "+clone", "-repage", "+3+0", ")",
")",
"-flatten", "-unsharp", "0x6+0.1+0", "png32:{}".format(dest)])
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
modPrefix = "__deadlocks-stacking-for-pyanadon__"
os.chdir("src/migrations")
lua = lupa.LuaRuntime()
modItems = lua.eval('require("shared")["STACKABLES"]')
os.chdir("../..")
#
for mod in list(modItems):
zips = sorted(glob.glob("{}graphics_*.zip".format(mod)))
if len(zips) == 0:
zips = sorted(glob.glob("{}_*.zip".format(mod)))
if len(zips) == 0:
print("missing zip file for", mod)
exit(1)
zipName = zips[len(zips)-1][0:-4]
withoutVersion = zipName[0:zipName.rfind('_')]
with zipfile.ZipFile("{}.zip".format(zipName), "r") as zf:
for e in modItems[mod].values():
icon = e.icon
if icon is None:
icon = "graphics/icons/stacked-{}.png".format(e.item)
else:
icon = remove_prefix(e.icon, modPrefix)
pyIcon = e.iconName
if pyIcon is None:
pyIcon = e.item
if not isfile(join("src", icon)):
pyPath = "{}/graphics/icons/{}.png".format(withoutVersion, pyIcon)
path = join("src", icon)
try:
zf.extract(pyPath, "tmp")
except KeyError:
pyPath = "{}/graphics/icons/{}.png".format(zipName, pyIcon)
zf.extract(pyPath, "tmp")
mkIcon(join("tmp", pyPath), path)
shutil.rmtree("tmp")
# print("generate image for", e.item, "( stage:", e.stage, ")")
# else:
# print("WARNING: {} ({}) - icon property not set, no image will be generated".format(e.item, mod))