Mercurial > mamba
changeset 352:abd9a2ceadb7
Fix and extend sprite fiddling code
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 16 Sep 2011 23:28:28 +0200 |
parents | 03d0a7dbb724 |
children | 62a2a659c69b |
files | mamba/level.py |
diffstat | 1 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/level.py Fri Sep 16 23:27:49 2011 +0200 +++ b/mamba/level.py Fri Sep 16 23:28:28 2011 +0200 @@ -313,7 +313,7 @@ exist""" for sprite_ascii in self.sprites_ascii: try: - pos, _sep, rest = sprite_ascii.partition(':') + pos, _, rest = sprite_ascii.partition(':') pos = [int(x.strip()) for x in pos.split(',')] except ValueError: continue @@ -327,10 +327,13 @@ def validate_sprite(self, sprite): """Check that the sprite line is valid""" - pos, _sep, rest = sprite.partition(':') - pos = [int(x.strip()) for x in pos.split(',')] - class_name, rest = rest.split(None, 1) - args = rest.split() + try: + pos, _sep, rest = sprite.partition(':') + pos = [int(x.strip()) for x in pos.split(',')] + class_name, rest = rest.split(None, 1) + args = rest.split() + except ValueError: + raise InvalidMapError('Unable to determine sprite parameters.') sprite_id, args = args[0], args[1:] try: cls = sprites.find_sprite(class_name) @@ -339,5 +342,17 @@ sprite = cls(*args) if sprite_id in self.extra_sprites: # Check that duplicate id is not at the same position - if self.extra[sprite_id].tile_pos != pos: + if self.extra_sprites[sprite_id].tile_pos != pos: raise InvalidMapError('Duplicate sprite id: %s.' % sprite_id) + + def add_sprite(self, sprite): + self.sprites_ascii.append(sprite) + + def replace_sprite(self, sprite): + # Need to find the sprite at the same psoition + pos, _sep, rest = sprite.partition(':') + pos = [int(x.strip()) for x in pos.split(',')] + old_sprite = self.get_sprite_at(pos) + print sprite, old_sprite + self.sprites_ascii.remove(old_sprite) + self.sprites_ascii.append(sprite)