-
Notifications
You must be signed in to change notification settings - Fork 11
/
GameGen.py
135 lines (118 loc) · 5.36 KB
/
GameGen.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'''
Master Game Gen
1.0b
'''
import os, glob
import PIL_Helper
import argparse
from OS_Helper import Delete, CleanDirectory, BuildPage, BuildBack
from sys import exit
#TSSSF Migration TODO:
#automagickally create vassal module :D
#individual artist naming
#.pon files have symbols like {ALICORN} and so on.
def main(folder="TSSSF", filepath="Core 1.0.3/deck.cards"):
'''
@param folder: The base game folder where we'll be working.
E.g. TSSSF, BaBOC
@param filepath: The filepath (relative to the base folder) where the
file that defines the different cards in the game are stored.
'''
CardFile = open(os.path.join(folder, filepath))
card_set = os.path.dirname(filepath)
# Read first line of file to determine module
first_line = CardFile.readline()
try:
module = __import__(first_line.strip())
except ValueError:
print "Failed to load module: " + str(ValueError)
return
module.CardSet = card_set
# Create workspace for card images
workspace_path = CleanDirectory(path=folder, mkdir="workspace", rmstring="*.*")
# Create image directories
bleed_path = CleanDirectory(path=folder+"/"+card_set, mkdir="bleed-images",rmstring="*.*")
module.BleedsPath = bleed_path
cropped_path = CleanDirectory(path=folder+"/"+card_set, mkdir="cropped-images",rmstring="*.*")
module.CropPath = cropped_path
vassal_path = CleanDirectory(path=folder+"/"+card_set, mkdir="vassal-images",rmstring="*.*")
module.VassalPath = vassal_path
# Create output directory
output_folder = CleanDirectory(path=folder, mkdir=card_set,rmstring="*.pdf")
# Load Card File and strip out comments
cardlines = [line for line in CardFile if not line[0] in ('#', ';', '/')]
CardFile.close()
## # Make a list of lists of cards, each one page in scale
## cardpages = []
## cardlines += ["BLANK" for i in range(1, module.TOTAL_CARDS)]
## cardlines.reverse()
## while len(cardlines) > module.TOTAL_CARDS:
## cardpages.append([cardlines.pop() for i in range(0,module.TOTAL_CARDS)])
# Make pages
card_list = []
back_list = []
page_num = 0
for line in cardlines:
card_list.append(module.BuildCard(line))
back_list.append(module.BuildBack(line))
# If the card_list is big enough to make a page
# do that now, and set the card list to empty again
if len(card_list) >= module.TOTAL_CARDS:
page_num += 1
print "Building Page {}...".format(page_num)
BuildPage(card_list, page_num, module.PAGE_WIDTH, module.PAGE_HEIGHT, workspace_path)
BuildBack(back_list, page_num, module.PAGE_WIDTH, module.PAGE_HEIGHT, workspace_path)
card_list = []
back_list = []
# If there are leftover cards, fill in the remaining
# card slots with blanks and gen the last page
if len(card_list) > 0:
# Fill in the missing slots with blanks
while len(card_list) < module.TOTAL_CARDS:
card_list.append(module.BuildCard("BLANK"))
back_list.append(module.BuildCard("BLANK"))
page_num += 1
print "Building Page {}...".format(page_num)
BuildPage(card_list, page_num, module.PAGE_WIDTH, module.PAGE_HEIGHT, workspace_path)
BuildBack(back_list, page_num, module.PAGE_WIDTH, module.PAGE_HEIGHT, workspace_path)
#Build Vassal
module.CompileVassalModule()
print "\nCreating PDF..."
os.system(r'convert "{}/page_*.png" "{}/{}.pdf"'.format(workspace_path, output_folder, card_set))
print "\nCreating PDF of backs..."
os.system(r'convert "{}/backs_*.png" "{}/backs_{}.pdf"'.format(workspace_path, output_folder, card_set))
print "Done!"
if __name__ == '__main__':
# To run this script, you have two options:
# 1) Run it from the command line with arguments. E.g.:
# python GameGen -b TSSSF -f "Core 1.0.3/cards.pon"
# 2) Comment out "main(args.basedir, args.set_file)" in this file
# and add a new line with the proper folder and card set
# in the arguments.
# See the main() docstring for more info on the use of the arguments
parser = argparse.ArgumentParser(prog="GameGen")
parser.add_argument('-f', '--set-file', \
help="Location of set file to be parsed",
default="cards.pon")
parser.add_argument('-b', '--basedir',
help="Workspace base directory with resources output directory",
default="TSSSF")
args = parser.parse_args()
main(args.basedir, args.set_file)
#main('TSSSF', '1.1.0 Patch/cards.pon')
#main('TSSSF', '2014 Con Exclusives/cards.pon')
#main('TSSSF', 'BABScon 2015/cards.pon')
#main('TSSSF', 'Core 1.0.5/cards.pon')
#main('TSSSF', 'Core 1.0.5 Delta/cards.pon')
#main('TSSSF', 'Core 1.1.0/cards.pon')
#main('TSSSF', 'Core 1.1.0 Test/cards.pon')
#main('TSSSF', 'Custom Card for/cards.pon')
#main('TSSSF', 'Extra Credit 0.10.4/cards.pon')
#main('TSSSF', 'Indiegogo/cards.pon')
#main('TSSSF', 'Patreon Expansion 1/cards.pon')
#main('TSSSF', 'Ponycon Panel 2015/cards.pon')
#main('TSSSF', 'Ponyville University 0.0.2/cards.pon')
#main('TSSSF', 'Ponyville University 1.0.1/cards.pon')
#main('TSSSF', 'Ponyville University 1.0.2/cards.pon')
#main('TSSSF', 'Thank You/cards.pon')
#main('BaBOC', 'BaBOC 0.1.0/deck.cards')