comparison mamba/level.py @ 508:6c61d5862310

Massive speical sprite editor rewrite
author Neil Muller <drnlmuller@gmail.com>
date Sun, 18 Sep 2011 00:11:30 +0200
parents e522db37e5c5
children 9afaa1969d6f
comparison
equal deleted inserted replaced
507:f4f883418ac2 508:6c61d5862310
334 pos, _, rest = sprite_ascii.partition(':') 334 pos, _, rest = sprite_ascii.partition(':')
335 pos = [int(x.strip()) for x in pos.split(',')] 335 pos = [int(x.strip()) for x in pos.split(',')]
336 except ValueError: 336 except ValueError:
337 continue 337 continue
338 if pos[0] == sprite_pos[0] and pos[1] == sprite_pos[1]: 338 if pos[0] == sprite_pos[0] and pos[1] == sprite_pos[1]:
339 return sprite_ascii 339 pos, _sep, rest = sprite_ascii.partition(':')
340 return None 340 class_name, rest = rest.split(None, 1)
341 args = rest.split()
342 sprite_cls = sprites.find_sprite(class_name)
343 sprite_id, args = args[0], args[1:]
344 return (class_name, sprite_cls, sprite_id, args), sprite_ascii
345 return None, None
341 346
342 def remove_sprite(self, sprite): 347 def remove_sprite(self, sprite):
343 """Remove the given sprite line from the list of sprites""" 348 """Remove the given sprite line from the list of sprites"""
344 self.sprites_ascii.remove(sprite) 349 self.sprites_ascii.remove(sprite)
345 350
364 raise InvalidMapError('Duplicate sprite id: %s.' % sprite_id) 369 raise InvalidMapError('Duplicate sprite id: %s.' % sprite_id)
365 370
366 def add_sprite(self, sprite): 371 def add_sprite(self, sprite):
367 self.sprites_ascii.append(sprite) 372 self.sprites_ascii.append(sprite)
368 373
369 def replace_sprite(self, sprite): 374 def replace_sprite(self, new_ascii):
370 # Need to find the sprite at the same psoition 375 # Need to find the sprite at the same psoition
371 pos, _sep, rest = sprite.partition(':') 376 pos, _sep, rest = new_ascii.partition(':')
372 pos = [int(x.strip()) for x in pos.split(',')] 377 pos = [int(x.strip()) for x in pos.split(',')]
373 old_sprite = self.get_sprite_at(pos) 378 old_sprite, old_ascii = self.get_sprite_at(pos)
374 self.sprites_ascii.remove(old_sprite) 379 self.sprites_ascii.remove(old_ascii)
375 self.sprites_ascii.append(sprite) 380 self.sprites_ascii.append(new_ascii)