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 |
|
13
by Josh C
pull data from svg to place objects into the world |
14 |
for svg in glob.glob('data/*.svg'): |
15 |
t = etree.parse(svg) |
|
16 |
basefile = os.path.basename(svg).split('.')[0] |
|
17 |
print '%s = {' % basefile |
|
18 |
||
19 |
sel = CSSSelector('svg|rect[ink|label="displace"]', ns) |
|
20 |
for e in sel(t): |
|
21 |
x, y = float(e.get('x')), float(e.get('y')) |
|
22 |
w, h = float(e.get('width')), float(e.get('height')) |
|
14
by Josh C
some transitions in svg |
23 |
|
13
by Josh C
pull data from svg to place objects into the world |
24 |
print """ |
25 |
Displacer:new{ |
|
26 |
x = %f, y = %f, |
|
27 |
width = %f, height = %f |
|
14
by Josh C
some transitions in svg |
28 |
}, |
13
by Josh C
pull data from svg to place objects into the world |
29 |
""" % (x,y,w,h) |
30 |
||
14
by Josh C
some transitions in svg |
31 |
sel = CSSSelector('svg|rect[ink|label="transition"]', ns) |
32 |
for e in sel(t): |
|
33 |
x, y = float(e.get('x')), float(e.get('y')) |
|
34 |
w, h = float(e.get('width')), float(e.get('height')) |
|
35 |
||
36 |
desc = "" |
|
37 |
descSel = CSSSelector('svg|desc', ns) |
|
38 |
for d in descSel(e): |
|
39 |
desc = desc + d.text |
|
40 |
||
41 |
print """ |
|
42 |
Transition:new{ |
|
43 |
x = %f, y = %f, |
|
44 |
width = %f, height = %f, |
|
45 |
%s |
|
46 |
}, |
|
47 |
""" % (x,y,w,h, desc) |
|
48 |
||
19
by Josh C
inventory (and a flower) |
49 |
sel = CSSSelector('svg|rect[ink|label="flower"]', ns) |
50 |
for e in sel(t): |
|
51 |
x, y = float(e.get('x')), float(e.get('y')) |
|
52 |
||
53 |
print """ |
|
54 |
Flower:new{ |
|
55 |
x = %f, y = %f, |
|
56 |
}, |
|
57 |
""" % (x,y) |
|
58 |
||
34
by Josh C
GET FISH |
59 |
sel = CSSSelector('svg|rect[ink|label="fish"]', ns) |
60 |
for e in sel(t): |
|
61 |
x, y = float(e.get('x')), float(e.get('y')) |
|
62 |
w, h = float(e.get('width')), float(e.get('height')) |
|
63 |
||
64 |
print """ |
|
65 |
Fish:new{ |
|
66 |
x = %f, y = %f, |
|
67 |
width = %f, height = %f, |
|
68 |
}, |
|
69 |
""" % (x,y,w,h) |
|
70 |
||
35
by Josh C
troll |
71 |
sel = CSSSelector('svg|rect[ink|label="troll"]', ns) |
72 |
for e in sel(t): |
|
73 |
x, y = float(e.get('x')), float(e.get('y')) |
|
74 |
#w, h = float(e.get('width')), float(e.get('height')) |
|
75 |
||
76 |
print """ |
|
77 |
Troll:new{ |
|
78 |
x = %f, y = %f, |
|
79 |
}, |
|
80 |
""" % (x,y) |
|
81 |
||
34
by Josh C
GET FISH |
82 |
|
13
by Josh C
pull data from svg to place objects into the world |
83 |
print '},' |
84 |
||
85 |
print '}' |