/ld26

To get this branch, use:
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
38 by Josh C
gate
14
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
14 by Josh C
some transitions in svg
33
    sel = CSSSelector('svg|rect[ink|label="transition"]', 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
        desc = ""
39
        descSel = CSSSelector('svg|desc', ns)
40
        for d in descSel(e):
41
            desc = desc + d.text
42
43
        print """
44
Transition:new{
45
  x = %f, y = %f,
46
  width = %f, height = %f,
47
  %s
48
},
49
""" % (x,y,w,h, desc)
50
19 by Josh C
inventory (and a flower)
51
    sel = CSSSelector('svg|rect[ink|label="flower"]', ns)
52
    for e in sel(t):
53
        x, y = float(e.get('x')), float(e.get('y'))
54
55
        print """
56
Flower:new{
57
  x = %f, y = %f,
58
},
59
""" % (x,y)
60
34 by Josh C
GET FISH
61
    sel = CSSSelector('svg|rect[ink|label="fish"]', ns)
62
    for e in sel(t):
63
        x, y = float(e.get('x')), float(e.get('y'))
64
        w, h = float(e.get('width')), float(e.get('height'))
65
66
        print """
67
Fish:new{
68
  x = %f, y = %f,
69
  width = %f, height = %f,
70
},
71
""" % (x,y,w,h)
72
36 by Josh C
flag
73
    sel = CSSSelector('svg|rect[ink|label="flag"]', ns)
74
    for e in sel(t):
75
        x, y = float(e.get('x')), float(e.get('y'))
76
        w, h = float(e.get('width')), float(e.get('height'))
77
78
        print """
79
Flag:new{
80
  x = %f, y = %f,
81
  width = %f, height = %f,
82
},
83
""" % (x,y,w,h)
84
38 by Josh C
gate
85
    sel = CSSSelector('svg|rect[ink|label="gatetrigger"]', ns)
86
    for e in sel(t):
87
        x, y = float(e.get('x')), float(e.get('y'))
88
        w, h = float(e.get('width')), float(e.get('height'))
89
90
        print """
91
GateTrigger:new{
92
  x = %f, y = %f,
93
  width = %f, height = %f,
94
},
95
""" % (x,y,w,h)
96
35 by Josh C
troll
97
    sel = CSSSelector('svg|rect[ink|label="troll"]', ns)
98
    for e in sel(t):
99
        x, y = float(e.get('x')), float(e.get('y'))
100
        #w, h = float(e.get('width')), float(e.get('height'))
101
102
        print """
103
Troll:new{
104
  x = %f, y = %f,
105
},
106
""" % (x,y)
107
34 by Josh C
GET FISH
108
13 by Josh C
pull data from svg to place objects into the world
109
    print '},'
110
38 by Josh C
gate
111
    # gate...
112
    sel = CSSSelector('svg|rect[ink|label="gateup"]', ns)
113
    for e in sel(t):
114
        x, y = float(e.get('x')), float(e.get('y'))
115
        w, h = float(e.get('width')), float(e.get('height'))
116
117
        gate = gate + """
118
gateup = Fill:new{
119
  x = %f, y = %f,
120
  width = %f, height = %f,
121
  fill = {108,57,22,255},
122
  gateup = true
123
}
124
""" % (x,y,w,h)
125
126
    sel = CSSSelector('svg|rect[ink|label="gatedown"]', ns)
127
    for e in sel(t):
128
        x, y = float(e.get('x')), float(e.get('y'))
129
        w, h = float(e.get('width')), float(e.get('height'))
130
131
        gate = gate + """
132
gatedown = Fill:new{
133
  x = %f, y = %f,
134
  width = %f, height = %f,
135
  fill = {108,57,22,255},
136
  visible = false
137
}
138
""" % (x,y,w,h)
139
140
13 by Josh C
pull data from svg to place objects into the world
141
print '}'
38 by Josh C
gate
142
143
print gate