/ld26

To get this branch, use:
bzr branch http://9ix.org/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
#!/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)

    print '},'

print '}'