/ld26

To get this branch, use:
bzr branch /bzr/ld26
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
#!/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'}

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="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="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 '},'

print '}'