-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGenerateHybrid.py
307 lines (221 loc) · 8.89 KB
/
GenerateHybrid.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import datetime
import json
import os
import sys
import re
class Quest:
def __init__(self, title, icon, stype, body):
self.title = title
self.icon = icon
self.stype = stype
self.body = body
def __str__(self):
return self.title
def __repr__(self):
return str(self)
def asquest(self):
q = list()
q.append('{')
q.append(f' title: `%s`,' % self.title)
q.append(f' icon: `%s`,' % self.icon)
q.append(f' stype: %s,' % self.stype)
q.append(f' body: `%s`,' % self.body)
q.append('},')
q.reverse()
return q
def create_all_imports():
base_path='scripts'
folders = []
for r, d, f in os.walk(base_path):
for folder in d:
exists = os.path.isfile(os.path.join(r, folder, 'ignore_import.j'))
if not exists:
folders.append(os.path.join(r, folder))
template = list()
with open('scripts/Templates_GEN/imports_template.j') as f:
template = f.read().splitlines()
stripped_list = list(map(str.strip, template))
pivot = stripped_list.index("{{GENERATE}}")
for folder in folders:
filelist = os.listdir(folder)
to_be_imported = list()
for file in filelist:
if file[len(file)-2:] == '.j' and file != 'imports.j':
to_be_imported.append('//! import vjass \"'+file+'"')
folder_imports = template[0:pivot - 1]
folder_imports += to_be_imported
folder_imports += template[pivot + 1:]
with open(os.path.join(folder, 'imports.j'), 'w') as f:
for item in folder_imports:
f.write("%s\n" % item)
with open('scripts/Templates_GEN/imports_root_template.j') as f:
template = f.read().splitlines()
stripped_list = list(map(str.strip, template))
pivot = stripped_list.index("{{GENERATE}}")
to_be_imported = list()
for folder in folders:
to_be_imported.append('//! import vjass \"'+folder.replace(base_path+'/','')+'/imports.j"')
filelist = os.listdir(base_path)
for file in filelist:
if file[len(file) - 2:] == '.j' and file != 'imports.j' and file != 'main.j':
to_be_imported.append('//! import vjass \"' + file + '"')
folder_imports = template[0:pivot - 1]
folder_imports += to_be_imported
folder_imports += template[pivot + 1:]
with open(os.path.join(base_path, 'imports.j'), 'w') as f:
for item in folder_imports:
f.write("%s\n" % item)
def get_all_quests():
quest_list = list()
files = os.listdir('Quests')
files = [file for file in files if '.md' in file]
files = sorted(files)
for f in files:
with open(os.path.join('Quests', f)) as file:
lines = file.read().splitlines()
header = list()
body = list()
title = ""
icon = "ReplaceableTextures\\CommandButtons\\BTNAmbush.blp"
type = "bj_QUESTTYPE_REQ_DISCOVERED"
shouldread = False
readbody = False
for line in lines:
if line.find('---') != -1:
if(shouldread):
readbody = True
shouldread = True
elif(shouldread):
if(readbody):
if len(body) > 0 or len(line) > 0:
body.append(line)
else:
if line.find('title:') != -1:
title = re.findall("^.*'(.*)'.*$", line)[0]
if line.find('icon:') != -1:
icon = re.findall("^.*'(.*)'.*$", line)[0]
if line.find('type:') != -1:
intype = re.findall("^.*'(.*)'.*$", line)[0]
if intype == 'required':
type = "bj_QUESTTYPE_REQ_DISCOVERED"
header.append(line)
create_quest(title, icon, type, body, [0], quest_list)
template = list()
with open('templates/questsGEN.ts.template') as f:
template = f.read().splitlines()
stripped_list = list(map(str.strip, template))
pivot = stripped_list.index("{{GENERATE}}")
spaces = len(template[pivot]) - len("{{GENERATE}}")
spacer = " " * spaces
generated_quest_list = list()
for quest in quest_list:
for line in quest.asquest():
generated_quest_list.append(spacer + line)
generated_quest_list.reverse()
generated_library = template[0:pivot - 1]
generated_library += generated_quest_list
generated_library += template[pivot + 1:]
with open('src/Generated/questsGEN.ts', 'w') as f:
for item in generated_library:
f.write("%s\n" % item)
def create_quest(title, icon, type, body, number, quest_list):
s = '\\n'
if len(s.join(body)) >= 1000:
q_a, q_b = split_quest(body)
number[0] += 1
create_quest(title, icon, type, q_a, number, quest_list)
number[0] += 1
create_quest(title, icon, type, q_b, number, quest_list)
else:
if number[0] != 0:
title = title + ' - ' + str(number[0])
quest_list.append(Quest(title, icon, type, s.join(body)))
def split_quest(quest_body):
indices = [i for i, x in enumerate(quest_body) if x.find('Updates') != -1]
if len(indices) >= 2:
q_a = quest_body[indices[0]:indices[1]]
q_b = quest_body[indices[1]:]
return q_a, q_b
else:
half = int(len(quest_body) / 2)
q_a = quest_body[0:half]
q_b = [q_a[0]]
q_b = q_b + quest_body[half:]
return q_a, q_b
def get_buildnum_with_date():
buildnum = "NaN"
x = datetime.datetime.now()
if len(sys.argv) > 1:
buildnum = sys.argv[1]
generated_list = list()
generated_list.append(f'export const BUILD_DATE: string = "%s";' % (x.strftime("%b %d %Y")))
generated_list.append(f'export const BUILD_NUMBER: string = "%s";' % buildnum)
with open('src/Generated/Version.ts', 'w') as f:
for item in generated_list:
f.write("%s\n" % item)
def main():
if not os.path.exists('src/Generated/'):
os.makedirs('src/Generated/')
data = {}
builders = dict()
weeiz = ['e00I']
numbers = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight',
'Nine']
tier_limits = [15, 99, 149, 299, 399, 499, 699, 899, 0]
tier_towers = list()
template = list()
get_buildnum_with_date()
with open('templates/hybridRandom.ts.template') as f:
template = f.read().splitlines()
stripped_list = list(map(str.strip, template))
pivot = stripped_list.index("{{GENERATE}}")
spaces = len(template[pivot]) - len("{{GENERATE}}")
spacer = " " * spaces
generated_hybrid_list = list()
hybrid_towers = dict()
with open('units.json') as json_data:
data = json.load(json_data)
json_data.close()
for builder in data:
# print(builder['UnitFunc']['UnitId'] + ' - ' + builder['UnitFunc']['Name'])
builders[builder['UnitFunc']['UnitId']] = builder
for i in weeiz:
for tower in builders[i]["Builds"]:
hybrid_towers[tower["UnitFunc"]["UnitId"]] = tower
# print(i)
print(len(hybrid_towers))
for tier in range(0, len(tier_limits)):
towers = list()
if tier + 1 is len(tier_limits):
for tower in list(hybrid_towers.keys()):
towers.append(hybrid_towers.pop(tower, None))
else:
for tower in list(hybrid_towers.keys()):
if int(hybrid_towers[tower]['SLKUnit']['UnitBalance'][
'Goldcost']) <= tier_limits[tier]:
towers.append(
hybrid_towers.pop(tower, None))
tier_towers.append(towers)
for tier in range(0, len(tier_limits)):
# set udg_TierOneTowers[0] = 'h00Z' // Dragonkin
tier_string = numbers[tier]
generated_hybrid_list.append(
spacer + "export const HybridTier" + tier_string + ": HybridTower[] = [")
for tower in tier_towers[tier]:
number_in_tier = tier_towers[tier].index(tower)
unit_id = tower["UnitFunc"]["UnitId"]
unit_name = tower["UnitFunc"]["Name"][1:len(tower["UnitFunc"]["Name"])-1]
sttest = " { id: '"+unit_id+"', name: `"+unit_name+"` }, // " + unit_name
generated_hybrid_list.append(spacer + sttest)
generated_hybrid_list.append(spacer + "];")
generated_library = template[0:pivot - 1]
generated_library += generated_hybrid_list
generated_library += template[pivot + 1:]
with open('src/Generated/hybridRandomGEN.ts', 'w') as f:
for item in generated_library:
f.write("%s\n" % item)
# print(data[0]["Builds"])
get_all_quests()
# create_all_imports()
if __name__ == "__main__":
main()