-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateWebsite.py
357 lines (303 loc) · 13.9 KB
/
generateWebsite.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import os
import re
import sys
import json
import math
import datetime
import shutil
from ruamel.yaml import YAML
yaml = YAML()
from generalMoveNames import generalMoveNames
from generateFrameGraph import getFrameGraph
generatedAt = datetime.datetime.utcnow().strftime("%H:%M:%S UTC on %B %d, %Y")
with open("moveNames.json") as f:
moveNames = json.load(f)
# "Responsive IFrame"
gfycatEmbed = "<div style='position:relative; padding-bottom:calc(56.25% + 44px)'><iframe src='https://gfycat.com/ifr/{id}?autoplay=1&controls=1&hd=1&speed=0.5' frameborder='0' scrolling='no' width='100%' height='100%' style='position:absolute;top:0;left:0;' allowfullscreen></iframe></div>"
frameData = {}
frameDataPath = os.environ["FRAMEDATA"]
for file in os.listdir(frameDataPath):
path = os.path.join(frameDataPath, file)
if os.path.isfile(path):
with open(path) as f:
frameData[file.split(".")[0]] = json.load(f)
charConfigs = {}
sourcePath = "source"
for item in os.listdir(sourcePath):
path = os.path.join(sourcePath, item)
if os.path.isdir(path) and item != "Ice Climbers":
with open(os.path.join(path, "config.yaml")) as f:
charConfigs[item] = yaml.load(f)
charConfigs[item]["name"] = item
def write(path, content):
path = os.path.join("output", path)
dirname = os.path.dirname(path)
if len(dirname) > 0:
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
f.write(content)
def template(sourceFile, **kwargs):
kwargs["generatedAt"] = generatedAt
if not os.path.isfile(sourceFile):
#print("Template '{}' does not exist!".format(sourceFile))
return ""
with open(sourceFile) as f:
html = f.read()
for name, content in kwargs.items():
html = html.replace("{{" + name + "}}", str(content))
def templateIfMatch(match):
var = match.group(1)
if var in kwargs and kwargs[var]:
return match.group(2)
else:
return ""
html = re.sub(r"{{if (.*?)}}(.*?){{endif \1}}", templateIfMatch, html, flags=re.DOTALL)
return html
def tag(tag, content, **kwargs):
return "<{tag} {attrs}>{content}</{tag}>".format(
tag=tag, content=content, attrs=" ".join('{}="{}"'.format(
attr if not attr[0] == "_" else attr[1:], value) for attr, value in kwargs.items()))
def getCharLinks():
chars = list((name, charConfigs[name]["pathName"]) for name in sorted(charConfigs))
return "\n".join(tag("li", tag("a", name, _class="navlink",
href="/{}/index.html".format(path))) for name, path in chars)
def generateIndexSite():
navlinks = getCharLinks()
index = template("source/index.html", navlinks=navlinks)
nav = template("source/index.nav.html", navlinks=navlinks)
base = template("base.html", title="Melee Framedata", nav=nav, contentbreadcrumbs="", content=index)
write("index.html", base)
def frameRangeString(start, end):
if start == end:
return str(start)
else:
return "{}-{}".format(start, end)
def htmlAngle(angle):
# This is not really entirely customizable from CSS (because of the image path)
# I don't know how to fix this though
title = angle
if angle == 361:
title = "Sakurai Angle"
return '<span class="tip" title="{title}"><img class="angle" alt="{angle}" src="/angleIcons/{angle}.svg"></span>'.format(title=title, angle=angle)
# https://www.reddit.com/r/smashbros/comments/237zsv/formula_for_hitlag_in_melee/
def hitlag(damage, element, attacker, crouchCancel=False):
if attacker:
c = 1.0
e = 1.0
else: # character being hit
c = 2/3 if crouchCancel else 1.0
e = 1.5 if element == "electric" else 1.0
return math.floor(c * math.floor(e * math.floor(3.0 + damage/3.0)))
def shieldstun(damage):
return math.floor((damage + 4.45) / 2.235)
def getSummaryTable(moveData):
columns = [("Total Frames", moveData["totalFrames"])]
if moveData["iasa"] != None:
columns.append(("IASA", moveData["iasa"]))
if "landingLag" in moveData:
columns.extend([
("Auto-Cancel Before", moveData["autoCancelBefore"]),
("Auto-Cancel After", moveData["autoCancelAfter"]),
("Landing Lag", moveData["landingLag"]),
("L-cancelled", moveData["lcancelledLandingLag"]),
])
elif "throw" in moveData:
columns.extend([
("Damage", moveData["throw"]["damage"]),
("Angle", htmlAngle(moveData["throw"]["angle"])),
("Knockback Scaling", moveData["throw"]["kbGrowth"]),
("Weight Dep. Knockback", moveData["throw"]["weightDepKb"]),
("Base Knockback", moveData["throw"]["baseKb"]),
("Element", moveData["throw"]["element"]),
])
if "released" in moveData["throw"] and not moveData["throw"]["released"]:
columns.append(("Cargo", "yes"))
if "projectiles" in moveData:
columns.append(("Projectile comes out", ", ".join(map(str, moveData["projectiles"]))))
content = '<div class="summary">\n<h2>Summary</h2>\n<table>\n'
for colName, colVal in columns:
content += "\t<tr><th>{}</th><td>{}</td></tr>\n".format(colName, colVal)
content += "</table>\n</div>\n\n"
return content
hitboxGuidColors = [
"red", "green", "yellow", "blue", "orange", "purple", "cyan", "magenta", "lime",
"pink", "teal", "lavender", "brown", "beige", "maroon", "mint", "olive", "coral", "navy"
]
def getHitboxTables(moveData):
hitboxGuidToNameHTML = lambda x: '<span class="hitbox_{0}">{0}</span>'.format(hitboxGuidColors[x])
content = '<div class="hitboxes">\n<h2>Hitboxes</h2>\n'
hitFrames = moveData["hitFrames"]
sameHitboxesForAllHitframes = \
all(hitFrame["hitboxes"] == hitFrames[0]["hitboxes"] for hitFrame in hitFrames)
if sameHitboxesForAllHitframes:
content += '<table class="hitframes_nocolors">\n<tr>'
content += "<th>Hit Frames</th><td>{}</td>\n".format(
", ".join(frameRangeString(hitFrame["start"], hitFrame["end"]) for hitFrame in hitFrames))
content += "</tr>"
else:
content += '<table class="hitframes_colors">\n'
for hitFrame in hitFrames:
translatedHitboxes = map(hitboxGuidToNameHTML, hitFrame["hitboxes"])
content += "<tr><th>{}</th><td>{}</td></tr>\n".format(
frameRangeString(hitFrame["start"], hitFrame["end"]),
", ".join(translatedHitboxes))
content += "</table>\n\n"
hitboxNames = len(moveData["hitboxes"]) > 1
shieldDamage = any(hitbox["shieldDamage"] > 0 for hitbox in moveData["hitboxes"])
element = any(hitbox["element"] != "normal" for hitbox in moveData["hitboxes"])
wdkb = any(hitbox["weightDepKb"] > 0 for hitbox in moveData["hitboxes"])
hitlagTip = False
for hitbox in moveData["hitboxes"]:
hitlagAtk = hitlag(hitbox["damage"], hitbox["element"], attacker=True)
hitlagDef = hitlag(hitbox["damage"], hitbox["element"], attacker=False)
if hitlagAtk != hitlagDef:
hitlagTip = True
break
content += """
<table class="hitboxtable">
\t<tr class="headings">
\t{}
\t<th>Damage</th>
\t{}
\t<th>Angle</th>
\t<th><span class="tip" title="Base Knockback">BKB</span></th>
\t<th><span class="tip" title="Knockback Scaling/Growth">KBS</span></th>
\t{}
\t{}
\t<th><span class="tip" title="Clang">C</span></th>
\t<th><span class="tip" title="Rebound">R</span></th>
\t<th><span class="tip" title="Hits Grounded">G</span></th>
\t<th><span class="tip" title="Hits Airborne">A</span></th>
\t<th>{}</th>
\t<th>Shieldstun</th>
\t</tr>
""".format("<th>Hitbox</th>" if hitboxNames else "",
"<th>Shield Damage</th>" if shieldDamage else "",
'<th><span class="tip" title="Set Knockback">SKB</span></th>' if wdkb else "",
"<th>Element</th>" if element else "",
'<span class="tip" title="Attacker/Defender">Hitlag</span>' if hitlagTip else "Hitlag")
for i, hitbox in enumerate(moveData["hitboxes"]):
content += "\t<tr>\n"
if hitboxNames:
content += "\t<td>{}</td>\n".format(hitboxGuidToNameHTML(i))
content += "\t<td>{}</td>\n".format(hitbox["damage"])
if shieldDamage:
content += "\t<td>{}</td>\n".format(hitbox["shieldDamage"])
content += "\t<td>{}</td>\n".format(htmlAngle(hitbox["angle"]))
content += "\t<td>{}</td>\n".format(hitbox["baseKb"])
content += "\t<td>{}</td>\n".format(hitbox["kbGrowth"])
if wdkb:
content += "\t<td>{}</td>\n".format(hitbox["weightDepKb"])
if element:
content += "\t<td>{}</td>\n".format(hitbox["element"] if hitbox["element"] != "normal" else "")
clang = hitbox["hitboxInteraction"] >= 2
rebound = hitbox["hitboxInteraction"] == 3
yes, no, yesHeavy, noHeavy = "✓", "✔", "✗", "✘"
content += "\t<td>{}</td>\n".format(yes if clang else noHeavy)
content += "\t<td>{}</td>\n".format(yes if rebound else noHeavy)
content += "\t<td>{}</td>\n".format(yes if hitbox["hitGrounded"] else noHeavy)
content += "\t<td>{}</td>\n".format(yes if hitbox["hitAirborne"] else noHeavy)
hitlagAtk = hitlag(hitbox["damage"], hitbox["element"], attacker=True)
hitlagDef = hitlag(hitbox["damage"], hitbox["element"], attacker=False)
hitlagStr = str(hitlagAtk)
if hitlagAtk != hitlagDef:
hitlagStr += "/" + str(hitlagDef)
content += "\t<td>{}</td>\n".format(hitlagStr)
content += "\t<td>{}</td>\n".format(shieldstun(hitbox["damage"]))
content += "\t</tr>\n\n"
content += "</table>\n</div>\n\n"
return content
def getMoveContent(charConfig, moveName, moveData):
content = ""
gfycatLink = charConfig["gfycatLinks"].get(moveName, None)
if gfycatLink:
content += gfycatEmbed.format(id=gfycatLink) + "\n\n"
content += getSummaryTable(moveData)
frameGraphHtml, allTheSame = getFrameGraph(moveData)
if not allTheSame:
content += frameGraphHtml
if len(moveData["hitboxes"]) > 0:
content += getHitboxTables(moveData)
return content
def generateMovePage(charConfig, moveGroupName, moves):
charMoveNames = moveNames[charConfig["externalName"]]
moveNameBase = moveGroupName.split("_")[0]
realMoveName = charMoveNames.get(moveNameBase, None)
generalMoveName = generalMoveNames[moveGroupName]
breadcrumbs = breadcrumbs=tag("a", charConfig["externalName"], _class="navlink",
href="/{}/index.html".format(charConfig["pathName"]))
nav = template("source/movenav.html", zair=False, breadcrumbs=breadcrumbs,
nspecial=charMoveNames["nspecial"], sspecial=charMoveNames["sspecial"],
dspecial=charMoveNames["dspecial"], uspecial=charMoveNames["uspecial"])
content = '<h1 class="movename">{}{}</h1>\n\n'.format(generalMoveName,
" - " + realMoveName if realMoveName else "")
content += template("source/{}/{}.html".format(charConfig["pathName"], moveGroupName))
for move in moves:
moveData = frameData[charConfig["name"]].get(move)
if moveData:
content += "<div>"
if len(moves) > 1:
if move in charConfig["moveNames"]:
moveName = charConfig["moveNames"][move]
else:
moveName = generalMoveNames[move]
if move in charMoveNames:
moveName += " - " + charMoveNames[move]
content += '<h1 class="">{}</h1>\n\n'.format(moveName)
content += getMoveContent(charConfig, move, moveData)
content += "</div>"
base = template("base.html",
title="Melee Framedata - {} - {}".format(charConfig["externalName"], generalMoveName),
nav=nav, contentbreadcrumbs='<h3 class="contentbreadcrumbs">' + breadcrumbs + '</h3>',
content=content)
write("{}/{}.html".format(charConfig["pathName"], moveGroupName), base)
moveGroups = [
("jab", ["jab1", "jab2", "jab3", "rapidjabs_start", "rapidjabs_loop", "rapidjabs_end"]),
("ftilt", ["ftilt_h", "ftilt_m", "ftilt_l"]),
("utilt", ["utilt"]),
("dtilt", ["dtilt"]),
("fsmash", ["fsmash_h", "fsmash_m", "fsmash_l"]),
("usmash", ["usmash"]),
("dsmash", ["dsmash"]),
("dashattack", ["dashattack"]),
("grab", ["grab"]),
("dashgrab", ["dashgrab"]),
("nair", ["nair"]),
("fair", ["fair"]),
("bair", ["bair"]),
("uair", ["uair"]),
("dair", ["dair"]),
("fthrow", ["fthrow"]),
("bthrow", ["bthrow"]),
("uthrow", ["uthrow"]),
("dthrow", ["dthrow"]),
]
def generateCharacter(character):
charConfig = charConfigs[character]
charMoveNames = moveNames[charConfig["externalName"]]
breadcrumbs = breadcrumbs=tag("a", charConfig["externalName"], _class="navlink",
href="/{}/index.html".format(charConfig["pathName"]))
nav = template("source/movenav.html", zair=False, breadcrumbs=breadcrumbs,
nspecial=charMoveNames["nspecial"], sspecial=charMoveNames["sspecial"],
dspecial=charMoveNames["dspecial"], uspecial=charMoveNames["uspecial"])
characterIndex = "source/{}/index.html".format(character)
if os.path.isfile(characterIndex):
content = template(characterIndex)
else:
content = template("source/defaultCharIndex.html")
content += '<div class="showsmall">\n' + nav + "</div>\n"
base = template("base.html", title="Melee Framedata - " + charConfig["externalName"],
nav=nav, contentbreadcrumbs="", content=content)
write(charConfig["pathName"] + "/index.html", base)
charMoveGroups = list((group, charConfig["moveGroups"][group]) for group in charConfig["moveGroups"])
for moveGroupName, moves in moveGroups + charMoveGroups:
generateMovePage(charConfig, moveGroupName, moves)
def main():
shutil.copy2("source/style.css", "output")
shutil.copy2("source/frameGraph.css", "output")
generateIndexSite()
for character in sorted(charConfigs):
print("#", character)
generateCharacter(character)
if __name__ == "__main__":
main()