/ld26

To get this branch, use:
bzr branch http://9ix.org/bzr/ld26

« back to all changes in this revision

Viewing changes to svg_levels.py

  • Committer: Josh C
  • Date: 2013-04-28 23:19:25 UTC
  • Revision ID: josh@9ix.org-20130428231925-m2rgt3n1dg9gryz2
cat

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
ns = {'svg': 'http://www.w3.org/2000/svg',
12
12
      'ink': 'http://www.inkscape.org/namespaces/inkscape'}
13
13
 
 
14
gate = ''
 
15
 
14
16
for svg in glob.glob('data/*.svg'):
15
17
    t = etree.parse(svg)
16
18
    basefile = os.path.basename(svg).split('.')[0]
56
58
},
57
59
""" % (x,y)
58
60
 
 
61
    sel = CSSSelector('svg|rect[ink|label="cat"]', ns)
 
62
    for e in sel(t):
 
63
        x, y = float(e.get('x')), float(e.get('y'))
 
64
 
 
65
        print """
 
66
Cat:new{
 
67
  x = %f, y = %f,
 
68
},
 
69
""" % (x,y)
 
70
 
59
71
    sel = CSSSelector('svg|rect[ink|label="fish"]', ns)
60
72
    for e in sel(t):
61
73
        x, y = float(e.get('x')), float(e.get('y'))
68
80
},
69
81
""" % (x,y,w,h)
70
82
 
 
83
    sel = CSSSelector('svg|rect[ink|label="flag"]', 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
Flag:new{
 
90
  x = %f, y = %f,
 
91
  width = %f, height = %f,
 
92
},
 
93
""" % (x,y,w,h)
 
94
 
 
95
    sel = CSSSelector('svg|rect[ink|label="gatetrigger"]', 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
GateTrigger:new{
 
102
  x = %f, y = %f,
 
103
  width = %f, height = %f,
 
104
},
 
105
""" % (x,y,w,h)
 
106
 
71
107
    sel = CSSSelector('svg|rect[ink|label="troll"]', ns)
72
108
    for e in sel(t):
73
109
        x, y = float(e.get('x')), float(e.get('y'))
82
118
 
83
119
    print '},'
84
120
 
 
121
    # gate...
 
122
    sel = CSSSelector('svg|rect[ink|label="gateup"]', ns)
 
123
    for e in sel(t):
 
124
        x, y = float(e.get('x')), float(e.get('y'))
 
125
        w, h = float(e.get('width')), float(e.get('height'))
 
126
 
 
127
        gate = gate + """
 
128
gateup = Fill:new{
 
129
  x = %f, y = %f,
 
130
  width = %f, height = %f,
 
131
  fill = {108,57,22,255},
 
132
  gateup = true
 
133
}
 
134
""" % (x,y,w,h)
 
135
 
 
136
    sel = CSSSelector('svg|rect[ink|label="gatedown"]', ns)
 
137
    for e in sel(t):
 
138
        x, y = float(e.get('x')), float(e.get('y'))
 
139
        w, h = float(e.get('width')), float(e.get('height'))
 
140
 
 
141
        gate = gate + """
 
142
gatedown = Fill:new{
 
143
  x = %f, y = %f,
 
144
  width = %f, height = %f,
 
145
  fill = {108,57,22,255},
 
146
  visible = false
 
147
}
 
148
""" % (x,y,w,h)
 
149
 
 
150
 
85
151
print '}'
 
152
 
 
153
print gate