bzr branch
http://9ix.org/bzr/ld26
13
by Josh C
pull data from svg to place objects into the world |
1 |
#!/usr/bin/python |
2 |
||
3 |
# ./svg_levels.py >svg_levels.lua |
|
4 |
||
5 |
import os, glob |
|
6 |
from lxml import etree |
|
7 |
from lxml.cssselect import CSSSelector |
|
8 |
||
9 |
print '-- autogenerated by svg_levels.py\n\nsvg_objects = {' |
|
10 |
||
11 |
ns = {'svg': 'http://www.w3.org/2000/svg', |
|
12 |
'ink': 'http://www.inkscape.org/namespaces/inkscape'} |
|
14
by Josh C
some transitions in svg |
13 |
|
42
by Josh C
be moved |
14 |
other = '' |
38
by Josh C
gate |
15 |
|
13
by Josh C
pull data from svg to place objects into the world |
16 |
for svg in glob.glob('data/*.svg'): |
17 |
t = etree.parse(svg) |
|
18 |
basefile = os.path.basename(svg).split('.')[0] |
|
19 |
print '%s = {' % basefile |
|
20 |
||
21 |
sel = CSSSelector('svg|rect[ink|label="displace"]', ns) |
|
22 |
for e in sel(t): |
|
23 |
x, y = float(e.get('x')), float(e.get('y')) |
|
24 |
w, h = float(e.get('width')), float(e.get('height')) |
|
14
by Josh C
some transitions in svg |
25 |
|
13
by Josh C
pull data from svg to place objects into the world |
26 |
print """ |
27 |
Displacer:new{ |
|
28 |
x = %f, y = %f, |
|
29 |
width = %f, height = %f |
|
14
by Josh C
some transitions in svg |
30 |
}, |
13
by Josh C
pull data from svg to place objects into the world |
31 |
""" % (x,y,w,h) |
32 |
||
42
by Josh C
be moved |
33 |
sel = CSSSelector('svg|rect[ink|label="maybedisplace"]', ns) |
34 |
for e in sel(t): |
|
35 |
x, y = float(e.get('x')), float(e.get('y')) |
|
36 |
w, h = float(e.get('width')), float(e.get('height')) |
|
37 |
||
38 |
print """ |
|
39 |
MaybeDisplacer:new{ |
|
40 |
x = %f, y = %f, |
|
41 |
width = %f, height = %f |
|
42 |
}, |
|
43 |
""" % (x,y,w,h) |
|
44 |
||
14
by Josh C
some transitions in svg |
45 |
sel = CSSSelector('svg|rect[ink|label="transition"]', ns) |
46 |
for e in sel(t): |
|
47 |
x, y = float(e.get('x')), float(e.get('y')) |
|
48 |
w, h = float(e.get('width')), float(e.get('height')) |
|
49 |
||
50 |
desc = "" |
|
51 |
descSel = CSSSelector('svg|desc', ns) |
|
52 |
for d in descSel(e): |
|
53 |
desc = desc + d.text |
|
54 |
||
55 |
print """ |
|
56 |
Transition:new{ |
|
57 |
x = %f, y = %f, |
|
58 |
width = %f, height = %f, |
|
59 |
%s |
|
60 |
}, |
|
61 |
""" % (x,y,w,h, desc) |
|
62 |
||
19
by Josh C
inventory (and a flower) |
63 |
sel = CSSSelector('svg|rect[ink|label="flower"]', ns) |
64 |
for e in sel(t): |
|
65 |
x, y = float(e.get('x')), float(e.get('y')) |
|
66 |
||
67 |
print """ |
|
68 |
Flower:new{ |
|
69 |
x = %f, y = %f, |
|
70 |
}, |
|
71 |
""" % (x,y) |
|
72 |
||
39
by Josh C
cat |
73 |
sel = CSSSelector('svg|rect[ink|label="cat"]', ns) |
74 |
for e in sel(t): |
|
75 |
x, y = float(e.get('x')), float(e.get('y')) |
|
76 |
||
77 |
print """ |
|
78 |
Cat:new{ |
|
79 |
x = %f, y = %f, |
|
80 |
}, |
|
81 |
""" % (x,y) |
|
82 |
||
34
by Josh C
GET FISH |
83 |
sel = CSSSelector('svg|rect[ink|label="fish"]', ns) |
84 |
for e in sel(t): |
|
85 |
x, y = float(e.get('x')), float(e.get('y')) |
|
86 |
w, h = float(e.get('width')), float(e.get('height')) |
|
87 |
||
88 |
print """ |
|
89 |
Fish:new{ |
|
90 |
x = %f, y = %f, |
|
91 |
width = %f, height = %f, |
|
92 |
}, |
|
93 |
""" % (x,y,w,h) |
|
94 |
||
36
by Josh C
flag |
95 |
sel = CSSSelector('svg|rect[ink|label="flag"]', ns) |
96 |
for e in sel(t): |
|
97 |
x, y = float(e.get('x')), float(e.get('y')) |
|
98 |
w, h = float(e.get('width')), float(e.get('height')) |
|
99 |
||
100 |
print """ |
|
101 |
Flag:new{ |
|
102 |
x = %f, y = %f, |
|
103 |
width = %f, height = %f, |
|
104 |
}, |
|
105 |
""" % (x,y,w,h) |
|
106 |
||
41
by Josh C
fairy |
107 |
sel = CSSSelector('svg|rect[ink|label="fairy"]', ns) |
108 |
for e in sel(t): |
|
109 |
x, y = float(e.get('x')), float(e.get('y')) |
|
110 |
w, h = float(e.get('width')), float(e.get('height')) |
|
111 |
||
112 |
print """ |
|
113 |
Fairy:new{ |
|
114 |
x = %f, y = %f, |
|
115 |
width = %f, height = %f, |
|
116 |
}, |
|
117 |
""" % (x,y,w,h) |
|
118 |
||
38
by Josh C
gate |
119 |
sel = CSSSelector('svg|rect[ink|label="gatetrigger"]', ns) |
120 |
for e in sel(t): |
|
121 |
x, y = float(e.get('x')), float(e.get('y')) |
|
122 |
w, h = float(e.get('width')), float(e.get('height')) |
|
123 |
||
124 |
print """ |
|
125 |
GateTrigger:new{ |
|
126 |
x = %f, y = %f, |
|
127 |
width = %f, height = %f, |
|
128 |
}, |
|
129 |
""" % (x,y,w,h) |
|
130 |
||
42
by Josh C
be moved |
131 |
sel = CSSSelector('svg|rect[ink|label="fairyactivator"]', ns) |
132 |
for e in sel(t): |
|
133 |
x, y = float(e.get('x')), float(e.get('y')) |
|
134 |
w, h = float(e.get('width')), float(e.get('height')) |
|
135 |
||
136 |
print """ |
|
137 |
FairyActivator:new{ |
|
138 |
x = %f, y = %f, |
|
139 |
width = %f, height = %f, |
|
140 |
}, |
|
141 |
""" % (x,y,w,h) |
|
142 |
||
45
by Josh C
boat |
143 |
sel = CSSSelector('svg|rect[ink|label="boat"]', ns) |
144 |
for e in sel(t): |
|
145 |
x, y = float(e.get('x')), float(e.get('y')) |
|
146 |
#w, h = float(e.get('width')), float(e.get('height')) |
|
147 |
||
148 |
print """ |
|
149 |
Boat:new{ |
|
150 |
x = %f, y = %f, |
|
151 |
}, |
|
152 |
""" % (x,y) |
|
153 |
||
35
by Josh C
troll |
154 |
sel = CSSSelector('svg|rect[ink|label="troll"]', ns) |
155 |
for e in sel(t): |
|
156 |
x, y = float(e.get('x')), float(e.get('y')) |
|
157 |
#w, h = float(e.get('width')), float(e.get('height')) |
|
158 |
||
159 |
print """ |
|
160 |
Troll:new{ |
|
161 |
x = %f, y = %f, |
|
162 |
}, |
|
163 |
""" % (x,y) |
|
164 |
||
34
by Josh C
GET FISH |
165 |
|
13
by Josh C
pull data from svg to place objects into the world |
166 |
print '},' |
167 |
||
38
by Josh C
gate |
168 |
# gate... |
169 |
sel = CSSSelector('svg|rect[ink|label="gateup"]', ns) |
|
170 |
for e in sel(t): |
|
171 |
x, y = float(e.get('x')), float(e.get('y')) |
|
172 |
w, h = float(e.get('width')), float(e.get('height')) |
|
173 |
||
42
by Josh C
be moved |
174 |
other = other + """ |
38
by Josh C
gate |
175 |
gateup = Fill:new{ |
176 |
x = %f, y = %f, |
|
177 |
width = %f, height = %f, |
|
178 |
fill = {108,57,22,255}, |
|
179 |
gateup = true |
|
180 |
} |
|
181 |
""" % (x,y,w,h) |
|
182 |
||
183 |
sel = CSSSelector('svg|rect[ink|label="gatedown"]', ns) |
|
184 |
for e in sel(t): |
|
185 |
x, y = float(e.get('x')), float(e.get('y')) |
|
186 |
w, h = float(e.get('width')), float(e.get('height')) |
|
187 |
||
42
by Josh C
be moved |
188 |
other = other + """ |
38
by Josh C
gate |
189 |
gatedown = Fill:new{ |
190 |
x = %f, y = %f, |
|
191 |
width = %f, height = %f, |
|
192 |
fill = {108,57,22,255}, |
|
193 |
visible = false |
|
194 |
} |
|
195 |
""" % (x,y,w,h) |
|
196 |
||
42
by Josh C
be moved |
197 |
sel = CSSSelector('svg|rect[ink|label="fairytarget"]', ns) |
198 |
for e in sel(t): |
|
199 |
x, y = float(e.get('x')), float(e.get('y')) |
|
200 |
w, h = float(e.get('width')), float(e.get('height')) |
|
201 |
||
202 |
other = other + """ |
|
203 |
fairytarget = Sprite:new{ |
|
204 |
x = %f, y = %f, |
|
205 |
width = %f, height = %f, |
|
206 |
visible = false |
|
207 |
} |
|
208 |
""" % (x,y,w,h) |
|
209 |
||
38
by Josh C
gate |
210 |
|
13
by Josh C
pull data from svg to place objects into the world |
211 |
print '}' |
38
by Josh C
gate |
212 |
|
42
by Josh C
be moved |
213 |
print other |