/
gamePage.py
66 lines (45 loc) · 1.99 KB
/
gamePage.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
#gamePage.py
#generation of static game content
from mako_defs import gp_template
import databeast
import os
root = '/var/www/Project-EFH/'
beast = databeast.dataBeast("funkyTrain", "games")
scripts = ['jquery', 'gamequery', '../js/Subject.js', '../js/shuffler.js', '../js/gameFuncs.js', '../js/common.js', '../js/sprintf.js', '../js/makeCueList.js', '../css/common.css', '../css/gamePage.css']
for gid in beast.distinct('gid'):
#get some game info
filename = beast.select("filename", {'gid':gid})
game = beast.select("name", {'gid':gid})
instructions = beast.select("notes", {'gid':gid})
#build the header
extrascripts = ['%s.css' % filename, '%s_constants.js' % filename, '%s.js' % filename]
arg = scripts + extrascripts
output = gp_template.get_def("head").render(title=game, scripts=arg)
info_content = []
header = gp_template.get_def("header").render(user="")
#game info div
controls = beast.select("controls", {'gid':gid})
info_content.append(['Controls', controls])
#links
#links="<a href='../index.html'>Your Home Page</a><br/>"
#info_content.append(['', links])
info_content.append(['', gp_template.get_def("game_stats").render()])
#instructions button
info_content.append(['', "<br/><button id='insButton' type='button'>Show instructions</button>"])
#instructions
info_content.append(['Instructions', instructions])
info = ""
for ic in info_content:
info += gp_template.get_def("title_div").render(ID=ic[0].lower(), title=ic[0], data=ic[1], title_lvl=3)
info_div = gp_template.get_def("title_div").render(ID="left", title=game, data=info, title_lvl=2)
game_window = gp_template.get_def("game_window").render()
footer = gp_template.get_def("footer").render()
#add it to the body
output += gp_template.get_def("body").render(data=header + info_div + game_window + footer)
#open a file and write the contents to the right place
url = beast.select("url", {'gid':gid})
f = open(os.path.join(root, url), "w")
f.write("<html>")
f.write(output)
f.write("</html>")
f.close()