67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
import xml.etree.ElementTree
|
|
import copy
|
|
import sys
|
|
import subprocess
|
|
import pathlib
|
|
|
|
thecrewSvgFile = sys.argv[1]
|
|
thecrewModifiersSvgFile = sys.argv[2]
|
|
|
|
def withShownHidden(origXML,toShow,toHide,recolorize={}):
|
|
|
|
outXML = copy.deepcopy(origXML)
|
|
|
|
for th in toHide:
|
|
node = outXML.find(f".//{{http://www.w3.org/2000/svg}}*[@{{http://www.inkscape.org/namespaces/inkscape}}label='{th}']")
|
|
if node is None:
|
|
print(f"Could not hide node with label {th} : Not Found")
|
|
exit(1)
|
|
node.attrib['style'] = "display: none"
|
|
for ts in toShow:
|
|
node = outXML.find(f".//{{http://www.w3.org/2000/svg}}*[@{{http://www.inkscape.org/namespaces/inkscape}}label='{ts}']")
|
|
if node is None:
|
|
print(f"Could not show node with label {ts} : Not Found")
|
|
exit(1)
|
|
nodes = outXML.findall(f".//{{http://www.w3.org/2000/svg}}*[@style]")
|
|
for node in nodes:
|
|
for rc in recolorize:
|
|
node.attrib['style'] = node.attrib['style'].replace(rc,recolorize[rc])
|
|
return outXML
|
|
|
|
def inkscapeToPng(fi,fo):
|
|
subprocess.run(["inkscape","--export-type","png","--export-dpi","300","--export-filename",fo,fi])
|
|
|
|
|
|
|
|
|
|
# Reading file:
|
|
origXML = xml.etree.ElementTree.parse(thecrewSvgFile)
|
|
|
|
suits = ["Hearts","Spades","Diamonds","Clubs","Square","Circle","Triangle","Cross"]
|
|
suitColors = ["e36a6a","545454","e36a6a","545454","e87caf","0085ca","94c11e","e6b436"]
|
|
numbers = ["One","Two","Three","Four","Five","Six","Seven","Eight","Nine"]
|
|
modifiers = numbers + ["Omega","OneArrow","TwoArrow","ThreeArrow","FourArrow"]
|
|
|
|
for s,sc in zip(suits,suitColors):
|
|
for n in numbers:
|
|
outFile = f"{n.lower()}-of-{s.lower()}.png"
|
|
toShow = [s,n]
|
|
toHide = list(set(suits+numbers) - set(toShow))
|
|
out = withShownHidden(origXML,toShow,toHide, recolorize = {
|
|
"123456": sc
|
|
})
|
|
out.write('card.tmp.svg')
|
|
inkscapeToPng('card.tmp.svg',outFile)
|
|
|
|
origXML = xml.etree.ElementTree.parse(thecrewModifiersSvgFile)
|
|
for m in modifiers:
|
|
outFile = f"{m.lower()}.png"
|
|
toShow = [m]
|
|
toHide = list(set(modifiers) - set(toShow))
|
|
out = withShownHidden(origXML,toShow,toHide)
|
|
out.write('card.tmp.svg')
|
|
inkscapeToPng('card.tmp.svg',outFile)
|
|
pathlib.Path.unlink('card.tmp.svg')
|
|
print("Done !")
|
|
|