-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
77 lines (73 loc) · 2.98 KB
/
build.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
from configuration.setup import black_stars_rise
import shutil
import os
import codecs
if __name__ == '__main__':
# Always build from scratch.
# We're just doing a little xml parsing, the work in making it incremental
# just doesn't seem worth it. Instead we invent the universe to make an
# apple pie.
if os.path.isdir('build'):
shutil.rmtree('build')
if not os.path.isdir('build'):
os.mkdir('build')
for part in black_stars_rise.getParts():
# Check to see if it's a chapter
if hasattr(part, 'getSections'):
with codecs.open(os.path.join('build', part.getKey()+'.xml'), 'w', "utf-8") as f:
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
f.write('<chapter>')
for section in part.getSections():
f.write(section.getText())
f.write('\n')
f.write('</chapter>')
elif hasattr(part, 'getCareers'): # It's a setting
with codecs.open(os.path.join('build', part.getKey()+'.xml'), 'w', "utf-8") as f:
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
f.write('<setting><careers>')
for career in part.getCareers():
f.write('<career>')
f.write(career.getFullText())
f.write('</career>\n')
f.write('</careers>\n')
f.write('<setups>')
for setup in part.getSetups():
f.write('<setup>')
f.write(setup.getFullText())
f.write('</setup>\n')
f.write('</setups></setting>')
elif hasattr(part, 'getMoves'): # It's basic moves
with codecs.open(os.path.join('build', part.getKey()+'.xml'), 'w', "utf-8") as f:
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
f.write('<moves>')
for move in part.getMoves():
woundedVersions = move.getWoundedVersions()
# For now, assume a 9-per-page layout
for i in xrange(0,9):
f.write('<basicmovename>')
f.write(move.getName())
f.write('</basicmovename>\n')
f.write('<movebody>')
f.write(move.getNormal())
f.write('</movebody>\n')
for i in xrange(0,9):
f.write('<basicmovename>')
f.write(move.getName())
f.write('</basicmovename>\n')
f.write('<movebody>')
f.write(woundedVersions[i % len(woundedVersions)])
f.write('</movebody>\n')
f.write('</moves>')
elif hasattr(part, 'getBreaks'): # It's breaks
with codecs.open(os.path.join('build', part.getKey()+'.xml'), 'w', "utf-8") as f:
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')
f.write('<breaks>')
for b in part.getBreaks():
woundedVersions = move.getWoundedVersions()
f.write('<breakname>')
f.write(b.getName())
f.write('</breakname>\n')
f.write('<breakbody>')
f.write(b.getDescription())
f.write('</breakbody>\n')
f.write('</breaks>')