/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 01:24:54 UTC
  • Revision ID: josh@9ix.org-20130428012454-b7kpooluezexnvde
fadeĀ out

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
 
 
16
14
for svg in glob.glob('data/*.svg'):
17
15
    t = etree.parse(svg)
18
16
    basefile = os.path.basename(svg).split('.')[0]
48
46
},
49
47
""" % (x,y,w,h, desc)
50
48
 
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
 
 
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
 
 
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
 
 
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
 
 
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
 
 
108
 
 
109
49
    print '},'
110
50
 
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
 
 
141
51
print '}'
142
 
 
143
 
print gate