First stab at packaging with pyinstaller
This commit is contained in:
parent
f4273338d8
commit
06a6cad980
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
/*.png
|
/*.png
|
||||||
/*.json
|
/*.json
|
||||||
|
/__pycache__/
|
||||||
|
/build/
|
||||||
|
/dist/
|
||||||
|
55
SotMDeckBuilder.py
Normal file → Executable file
55
SotMDeckBuilder.py
Normal file → Executable file
@ -10,17 +10,23 @@ from PIL import Image, ImageDraw, ImageFont
|
|||||||
import textwrap
|
import textwrap
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
IMG_HERO_CHAR_FRONT = Image.open("images/HeroCharFront.png")
|
if getattr(sys, 'frozen', False): # we are running in a bundle
|
||||||
IMG_HERO_CHAR_BACK = Image.open("images/HeroCharBack.png")
|
bundle_dir = sys._MEIPASS
|
||||||
IMG_HERO_DECK = Image.open("images/HeroCard.png")
|
else: # we are running in a normal Python environment
|
||||||
IMG_TARGET_HP = Image.open("images/targetHP.png")
|
bundle_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
FONT_KEYWORD = ImageFont.truetype("fonts/RedStateBlueStateBB_reg.otf", size=40)
|
IMG_HERO_CHAR_FRONT = Image.open(bundle_dir + "/images/HeroCharFront.png")
|
||||||
FONT_TITLE = ImageFont.truetype("fonts/CrashLandingBB.otf", size=60)
|
IMG_HERO_CHAR_BACK = Image.open(bundle_dir + "/images/HeroCharBack.png")
|
||||||
FONT_DESCRIPTION = ImageFont.truetype("fonts/RedStateBlueStateBB_reg.otf", size=30)
|
IMG_HERO_DECK = Image.open(bundle_dir + "/images/HeroCard.png")
|
||||||
FONT_TARGET_HP = ImageFont.truetype("fonts/CrashLandingBB.otf", size=120)
|
IMG_TARGET_HP = Image.open(bundle_dir + "/images/targetHP.png")
|
||||||
FONT_CHAR_HP = ImageFont.truetype("fonts/ap.ttf", size=120)
|
|
||||||
|
FONT_KEYWORD = ImageFont.truetype(bundle_dir + "/fonts/RedStateBlueStateBB_reg.otf", size=40)
|
||||||
|
FONT_TITLE = ImageFont.truetype(bundle_dir + "/fonts/CrashLandingBB.otf", size=60)
|
||||||
|
FONT_DESCRIPTION = ImageFont.truetype(bundle_dir + "/fonts/RedStateBlueStateBB_reg.otf", size=30)
|
||||||
|
FONT_TARGET_HP = ImageFont.truetype(bundle_dir + "/fonts/CrashLandingBB.otf", size=120)
|
||||||
|
FONT_CHAR_HP = ImageFont.truetype(bundle_dir + "/fonts/ap.ttf", size=120)
|
||||||
|
|
||||||
def drawTextIf(draw, position, font, card, key, wrap=False):
|
def drawTextIf(draw, position, font, card, key, wrap=False):
|
||||||
if key in card:
|
if key in card:
|
||||||
@ -84,9 +90,9 @@ def makeFaces(deckJson, outfile):
|
|||||||
return (baseX, baseX)
|
return (baseX, baseX)
|
||||||
|
|
||||||
def makeJson(deckJson, imgWidth, imgHeight, outfile):
|
def makeJson(deckJson, imgWidth, imgHeight, outfile):
|
||||||
with open("templates/deck.json") as f:
|
with open(bundle_dir + "/templates/deck.json") as f:
|
||||||
outJson = json.load(f)
|
outJson = json.load(f)
|
||||||
with open("templates/card.json") as f:
|
with open(bundle_dir + "/templates/card.json") as f:
|
||||||
cardTemplate = json.load(f)
|
cardTemplate = json.load(f)
|
||||||
|
|
||||||
# number of cards in x and y direction
|
# number of cards in x and y direction
|
||||||
@ -130,10 +136,27 @@ def makeJson(deckJson, imgWidth, imgHeight, outfile):
|
|||||||
with open(outfile + ".json", "w") as f:
|
with open(outfile + ".json", "w") as f:
|
||||||
json.dump(outJson, f)
|
json.dump(outJson, f)
|
||||||
|
|
||||||
with open("hero_3.json") as f:
|
if __name__ == '__main__':
|
||||||
deckJson = json.load(f)
|
if len(sys.argv) < 3:
|
||||||
|
print("not enough arguments!")
|
||||||
|
inputJson = input("Input file: ")
|
||||||
|
outfile = input("Output file (no suffix): ")
|
||||||
|
else:
|
||||||
|
inputJson = sys.argv[1]
|
||||||
|
outfile = sys.argv[2]
|
||||||
|
|
||||||
outfile = "out"
|
with open(inputJson) as f:
|
||||||
|
deckJson = json.load(f)
|
||||||
|
|
||||||
imgWidth, imgHeight = makeFaces(deckJson, outfile)
|
imgWidth, imgHeight = makeFaces(deckJson, outfile)
|
||||||
makeJson(deckJson, imgWidth, imgHeight, outfile)
|
makeJson(deckJson, imgWidth, imgHeight, outfile)
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
with open("hero_3.json") as f:
|
||||||
|
deckJson = json.load(f)
|
||||||
|
|
||||||
|
outfile = "out"
|
||||||
|
|
||||||
|
imgWidth, imgHeight = makeFaces(deckJson, outfile)
|
||||||
|
makeJson(deckJson, imgWidth, imgHeight, outfile)
|
||||||
|
36
SotMDeckBuilder.spec
Normal file
36
SotMDeckBuilder.spec
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# -*- mode: python -*-
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['SotMDeckBuilder.py'],
|
||||||
|
pathex=['Z:\\home\\adam\\scratch\\TTS_SotM_Deck'],
|
||||||
|
binaries=[],
|
||||||
|
datas=[('images/*.png', 'images'),
|
||||||
|
('fonts/*.ttf', 'fonts'),
|
||||||
|
('fonts/*.otf', 'fonts'),
|
||||||
|
('templates/*.json', 'templates')],
|
||||||
|
hiddenimports=['pillow'],
|
||||||
|
hookspath=[],
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data,
|
||||||
|
cipher=block_cipher)
|
||||||
|
exe = EXE(pyz,
|
||||||
|
a.scripts,
|
||||||
|
exclude_binaries=True,
|
||||||
|
name='SotMDeckBuilder',
|
||||||
|
debug=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
console=True )
|
||||||
|
coll = COLLECT(exe,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
name='SotMDeckBuilder')
|
Reference in New Issue
Block a user