-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_index.py
285 lines (243 loc) · 8.65 KB
/
gen_index.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
from icon_lister import *
import time
ignore_list = [
"us_air_c47_para",
"civilianCar2",
"arg_jet_a1h_objective",
"ru_ahe_ka29t",
"ru_ahe_mi8amtsh",
"ch_ahe_z9wa"
]
def makeHead(title):
return [
"<!DOCTYPE html>",
"<html>",
"<head>",
"<title>{}</title>".format(title),
"<style>",
"html {"
" font: 1rem/1.5 Arial, sans-serif;",
" background: lightgray;",
"}",
"div.outer {",
" text-align: center;",
" margin-left: auto;",
" margin-right: auto;",
"}",
"div.inner {",
" display: inline-block;",
"}",
"img {",
" image-rendering: -moz-crisp-edges;",
" image-rendering: -webkit-optimize-contrast;",
" image-rendering: crisp-edges;",
" -ms-interpolation-mode: nearest-neighbor;",
" height: 64px;",
" text-align: center;",
"}",
"table {",
" display: table;",
" width: 100%;",
" text-align: left;",
"}",
"td {",
" border: 1px solid black;",
" vertical-align: top;",
" padding: 8px;",
"}",
"span {",
" display: block;",
"}",
"</style>",
"</head>",
"<body>",
"",
"<div class=\"outer\">",
"<div class=\"inner\">",
"",
"<h1>{}</h1>".format(title),
"",
]
tail = [
"",
"</div>",
"</div>",
"",
"</body>",
"</html>",
]
facTr = {
"civ": "Civilian",
"gb82": "GB",
"mil": "Militia",
"boat": "Generic"
}
def vehToFactionName(veh):
vehOrig = veh
fac = None
for i in range(2, 5):
if veh[i] == "_":
fac = veh[:i]
break
if veh in names_map:
veh = names_map[veh]
if veh[0] == "\"":
veh = veh[1:]
if veh[-1] == "\"":
veh = veh[:-1]
else:
print("No HUD name found for: {}".format(vehOrig))
if fac == None:
print("Unknown faction: {}".format(vehOrig))
return veh
if fac in facTr:
fac = facTr[fac]
else:
fac = fac.upper()
return (fac, veh)
if __name__ == "__main__":
# ########################################################################################
# index.html
# ########################################################################################
file = os.path.join(os.path.curdir + "/index.html")
print(file)
lines = []
lines.extend(makeHead("PR Assets Indexes"))
lines.extend([
"<h2>Automatically generated at {} using a script by CAS_ual_TY</h2>".format(time.asctime()),
"<h2>Vehicles</h2>",
"<span><a href=\"icon-to-asset_index.html\">PR Icon-to-Assets Index (click here)</a></span>",
"<span><a href=\"asset-to-icon_index.html\">PR Assets-to-Icon Index (click here)</a></span>"
"<span><a href=\"faction-asset-to-icon_index.html\">PR Faction-Assets-to-Icon Index (click here)</a></span>",
"<h2>Kits</h2>",
"<span><a href=\"icon-to-kit_index.html\">PR Icon-to-Kit Index (click here)</a></span>",
])
lines.extend(tail)
with open(file, "w") as f:
f.writelines([l + "\n" for l in lines])
f.close()
# ########################################################################################
# Icon -> Asset Index
# ########################################################################################
file = os.path.join(os.path.curdir + "/icon-to-asset_index.html")
print(file)
lines = []
lines.extend(makeHead("PR Icon-to-Assets Index"))
lines.append("<a href=\"index.html\">Return to Index</a>")
lines.extend([
"<h3>Sorted alphabetically by asset name (ignoring faction identifier in front).</h3>",
"<table>",
"<hr>",
])
for k, v in icons_map.items():
v = [a for a in v if a not in ignore_list]
if k[:len("mini_")] == "mini_" and len(v) > 0:
i = k[len("mini_"):-len(".tga")]
lines.append("<tr>")
lines.append("<td><img src=\"./vehicles/{}\"></td>".format("mini_" + i + ".png"))
lines.append("<td>")
lines.append("<b>{}</b>:".format(i))
lines.append("<ul>")
for v2 in v:
if v2[-len(bf2):] != bf2 and v2[-len(prsp):] != prsp and v2[-len(sp):] != sp:
fac, veh = vehToFactionName(v2)
lines.append("<li>{} <b>{}</b> ({})</li>".format(fac, veh, v2))
lines.append("</ul>")
lines.append("</td>")
lines.append("</tr>")
lines.extend([
"",
"</table>"
])
lines.extend(tail)
with open(file, "w") as f:
f.writelines([l + "\n" for l in lines])
f.close()
# ########################################################################################
# Asset -> Icon Index
# ########################################################################################
file = os.path.join(os.path.curdir + "/asset-to-icon_index.html")
print(file)
lines = []
lines.extend(makeHead("PR Assets-to-Icon Index"))
lines.append("<a href=\"index.html\">Return to Index</a>")
lines.extend([
"<h3>Sorted alphabetically by asset name (ignoring faction identifier in front).</h3>",
"<hr>",
"<table>"
])
assets = []
for k, v in icons_map.items():
v = [a for a in v if a not in ignore_list]
if k[:len("mini_")] == "mini_" and len(v) > 0:
for v2 in v:
if v2[-len(bf2):] != bf2 and v2[-len(prsp):] != prsp and v2[-len(sp):] != sp:
assets.append(vehToFactionName(v2) + (v2, k[len("mini_"):-len(".tga")],))
sortedAssets = sorted(assets, key=lambda tup: tup[1])
for fac, name, veh, icon in sortedAssets:
lines.append("<tr>")
lines.append("<td><img src=\"./vehicles/{}\"></td>".format("mini_" + icon + ".png"))
lines.append("<td>{} <b>{}</b> ({}, {})</td>".format(fac, name, veh, icon))
lines.append("</tr>")
lines.extend([
"",
"</table>"
])
lines.extend(tail)
with open(file, "w") as f:
f.writelines([l + "\n" for l in lines])
f.close()
# ########################################################################################
# Faction, Asset -> Icon Index
# ########################################################################################
file = os.path.join(os.path.curdir + "/faction-asset-to-icon_index.html")
print(file)
lines = []
lines.extend(makeHead("PR Faction-Assets-to-Icon Index"))
lines.append("<a href=\"index.html\">Return to Index</a>")
lines.extend([
"<h3>Sorted alphabetically by factions and asset name.</h3>"
])
sortedAssets = sorted(assets, key=lambda tup: (tup[0], tup[1]))
fac0 = None
for fac, name, veh, icon in sortedAssets:
if fac0 != fac:
if fac0 != None:
lines.append("</table>")
fac0 = fac
lines.append("<hr>")
lines.append("<h2>{}</h2>".format(fac))
lines.append("<table>")
lines.append("<tr>")
lines.append("<td><img src=\"./vehicles/{}\"></td>".format("mini_" + icon + ".png"))
lines.append("<td>{} <b>{}</b> ({}, {})</td>".format(fac, name, veh, icon))
lines.append("</tr>")
lines.append("</table>")
lines.extend(tail)
with open(file, "w") as f:
f.writelines([l + "\n" for l in lines])
f.close()
# ########################################################################################
# Icon -> Kit Index
# ########################################################################################
file = os.path.join(os.path.curdir + "/icon-to-kit_index.html")
print(file)
lines = []
lines.extend(makeHead("PR Icon-to-Kit Index"))
lines.append("<a href=\"index.html\">Return to Index</a>")
lines.extend([
"<h3>Sorted alphabetically by kit identifier.</h3>"
"<hr>",
"<table>"
])
for f in os.listdir(os.path.join(os.path.curdir + "/kits")):
if f[-len("_outline.png"):] == "_outline.png":
lines.append("<tr>")
lines.append("<td><img src=\"./kits/{}\"></td>".format(f))
lines.append("<td>{}</td>".format(f[:-len("_outline.png")]))
lines.append("</tr>")
lines.append("</table>")
lines.extend(tail)
with open(file, "w") as f:
f.writelines([l + "\n" for l in lines])
f.close()