116 |
self.parsear_nombre(self.source) |
self.parsear_nombre(self.source) |
117 |
self.parsear_descripcion(self.source) |
self.parsear_descripcion(self.source) |
118 |
self.parsear_propiedades(self.source) |
self.parsear_propiedades(self.source) |
119 |
self.parsear_requisitos(self.source) |
self.parsear_usos(self.source) |
|
self.parsear_efectos(self.source) |
|
120 |
|
|
121 |
del self.source |
del self.source |
122 |
del self.descripcion |
del self.descripcion |
123 |
del self.reqs |
del self.usos_posibles |
|
del self.efcts |
|
|
|
|
124 |
|
|
125 |
|
|
126 |
def iniciar_parseador(self, fuente): |
def iniciar_parseador(self, fuente): |
182 |
def parsear_propiedades(self, fuente): |
def parsear_propiedades(self, fuente): |
183 |
|
|
184 |
self.aura=int(fuente.childNodes[3].attributes["aura"].value) |
self.aura=int(fuente.childNodes[3].attributes["aura"].value) |
185 |
self.volumen=int(fuente.childNodes[3].attributes["volumen"].value) |
self.volumen=float(fuente.childNodes[3].attributes["volumen"].value) |
186 |
self.peso=int(fuente.childNodes[3].attributes["peso"].value) |
self.peso=float(fuente.childNodes[3].attributes["peso"].value) |
187 |
self.consumible=fuente.childNodes[3].attributes["consumible"].value.encode('ISO-8859-1') |
try: |
188 |
self.cargas=int(fuente.childNodes[3].attributes["cargas"].value) |
self.cargas=int(fuente.childNodes[3].attributes["cargas"].value) |
189 |
|
except: |
190 |
|
self.cargas=1 |
191 |
self.valor=int(fuente.childNodes[3].attributes["valor"].value) |
self.valor=int(fuente.childNodes[3].attributes["valor"].value) |
192 |
self.estado=int(fuente.childNodes[3].attributes["estado"].value) |
self.estado=int(fuente.childNodes[3].attributes["estado"].value) |
193 |
|
|
194 |
|
|
195 |
def parsear_requisitos(self, fuente): |
def parsear_usos(self, fuente): |
196 |
|
|
197 |
for node in fuente.childNodes[4].childNodes[:]: |
for node in fuente.childNodes[4].childNodes[:]: |
198 |
if 'Element:' not in str(node).split(): fuente.childNodes[4].childNodes.remove(node) |
if 'Element:' not in str(node).split(): fuente.childNodes[4].childNodes.remove(node) |
199 |
|
|
200 |
self.reqs=fuente.childNodes[4] |
self.usos_posibles=fuente.childNodes[4] |
201 |
|
|
202 |
self.requisitos=[] |
self.usos=[] |
203 |
for node in self.reqs.childNodes[:]: |
for node in self.usos_posibles.childNodes[:]: |
204 |
try: |
try: |
205 |
req_id=node._attrs.get('atributo').value.encode('ISO-8859-1') |
uso_descripcion=node.data.value.encode('ISO-8859-1') |
206 |
except: print 'algo anda mal, este objeto no tiene requisito!!' |
except: uso_descripcion = 'Uso desconocido' |
|
try: |
|
|
req_valor=int(node._attrs.get('valor').value) |
|
|
except: req_valor=0 |
|
|
|
|
|
self.requisitos.append({req_id:req_valor}) |
|
|
|
|
|
def parsear_efectos(self, fuente): |
|
|
|
|
|
for node in fuente.childNodes[5].childNodes[:]: |
|
|
if 'Element:' not in str(node).split(): fuente.childNodes[5].childNodes.remove(node) |
|
|
|
|
|
self.efcts=fuente.childNodes[5] |
|
207 |
|
|
|
self.efectos=[] |
|
|
for node in self.efcts.childNodes[:]: |
|
208 |
try: |
try: |
209 |
efecto_id=node._attrs.get('atributo').value.encode('ISO-8859-1') |
uso_tipo=node._attrs.get('tipo').value.encode('ISO-8859-1') |
210 |
except: print 'algo anda mal, este objeto no tiene atributo que modificar!!' |
except: print 'algo anda mal, este uso de objeto no tiene tipo!!' |
211 |
try: |
try: |
212 |
efecto_valor=node._attrs.get('valor').value |
uso_posicion=node._attrs.get('posicion').value.encode('ISO-8859-1') |
213 |
except: req_valor=0 |
except: uso_posicion='mano_der' |
214 |
|
try: |
215 |
self.efectos.append({efecto_id:efecto_valor}) |
uso_gasto=int(node._attrs.get('gasto').value.encode('ISO-8859-1')) |
216 |
|
except: uso_gasto='1' |
217 |
|
|
218 |
|
uso_efectos_requisitos = node.childNodes[:] |
219 |
|
for node in uso_efectos_requisitos: |
220 |
|
if 'Element:' not in str(node).split(): uso_efectos_requisitos.remove(node) |
221 |
|
efectos = [] |
222 |
|
requisitos = [] |
223 |
|
for node in uso_efectos_requisitos[:]: |
224 |
|
if str(node).find('efecto') > -1: |
225 |
|
efectos.append({'atributo':node._attrs.get('atributo'),'valor':node._attrs.get('valor'),'msg':node._attrs.get('msg'),'duracion':node._attrs.get('duracion')}) |
226 |
|
elif str(node).find('requisito') > -1: |
227 |
|
requisitos.append({'atributo':node._attrs.get('atributo'),'valor':node._attrs.get('valor'),'msg':node._attrs.get('msg')}) |
228 |
|
else: |
229 |
|
pass |
230 |
|
|
231 |
|
self.usos.append({'descripcion':uso_descripcion,'tipo':uso_tipo,'posicion':uso_posicion,'gasto':uso_gasto,'requisitos':requisitos,'efectos':efectos}) |
232 |
|
del uso_descripcion,uso_tipo,uso_posicion,uso_gasto,uso_efectos_requisitos |
233 |
|
|
234 |
|
|
235 |
def salvar(self): |
def salvar(self): |
236 |
"""Graba en un fichero de DIR_OBJETOS el objeto con todo su contenido.""" |
"""Graba en un fichero de DIR_OBJETOS el objeto con todo su contenido.""" |