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
|
#!/usr/bin/python
# ./svg_levels.py >svg_levels.lua
import os, glob
from lxml import etree
from lxml.cssselect import CSSSelector
print '-- autogenerated by svg_levels.py\n\nsvg_objects = {'
ns = {'svg': 'http://www.w3.org/2000/svg',
'ink': 'http://www.inkscape.org/namespaces/inkscape'}
gate = ''
for svg in glob.glob('data/*.svg'):
t = etree.parse(svg)
basefile = os.path.basename(svg).split('.')[0]
print '%s = {' % basefile
sel = CSSSelector('svg|rect[ink|label="displace"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
Displacer:new{
x = %f, y = %f,
width = %f, height = %f
},
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="transition"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
desc = ""
descSel = CSSSelector('svg|desc', ns)
for d in descSel(e):
desc = desc + d.text
print """
Transition:new{
x = %f, y = %f,
width = %f, height = %f,
%s
},
""" % (x,y,w,h, desc)
sel = CSSSelector('svg|rect[ink|label="flower"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
print """
Flower:new{
x = %f, y = %f,
},
""" % (x,y)
sel = CSSSelector('svg|rect[ink|label="cat"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
print """
Cat:new{
x = %f, y = %f,
},
""" % (x,y)
sel = CSSSelector('svg|rect[ink|label="fish"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
Fish:new{
x = %f, y = %f,
width = %f, height = %f,
},
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="flag"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
Flag:new{
x = %f, y = %f,
width = %f, height = %f,
},
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="fairy"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
Fairy:new{
x = %f, y = %f,
width = %f, height = %f,
},
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="gatetrigger"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
GateTrigger:new{
x = %f, y = %f,
width = %f, height = %f,
},
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="troll"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
#w, h = float(e.get('width')), float(e.get('height'))
print """
Troll:new{
x = %f, y = %f,
},
""" % (x,y)
print '},'
# gate...
sel = CSSSelector('svg|rect[ink|label="gateup"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
gate = gate + """
gateup = Fill:new{
x = %f, y = %f,
width = %f, height = %f,
fill = {108,57,22,255},
gateup = true
}
""" % (x,y,w,h)
sel = CSSSelector('svg|rect[ink|label="gatedown"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
gate = gate + """
gatedown = Fill:new{
x = %f, y = %f,
width = %f, height = %f,
fill = {108,57,22,255},
visible = false
}
""" % (x,y,w,h)
print '}'
print gate
|