Mercurial > fife-parpg
diff demos/rpg/scripts/scene.py @ 535:9fbe3dce925a
Added custom exceptions.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 31 May 2010 18:44:48 +0000 |
parents | 65a92a2449d5 |
children | 1afe46247ab1 |
line wrap: on
line diff
--- a/demos/rpg/scripts/scene.py Mon May 31 17:45:04 2010 +0000 +++ b/demos/rpg/scripts/scene.py Mon May 31 18:44:48 2010 +0000 @@ -37,6 +37,7 @@ from scripts.actors.player import Player from scripts.objects.baseobject import GameObjectTypes from scripts.objects.items import BaseItem, GoldStack +from scripts.misc.exceptions import ObjectNotFoundError class Scene(object): def __init__(self, gamecontroller): @@ -70,9 +71,8 @@ newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) - except (KeyError) as e: - print "Error: ", e - newitem = None + except KeyError, e: + raise FileFormatError return newitem @@ -104,20 +104,29 @@ actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) - except (KeyError) as e: - print "Error: ", e - actor = None + except KeyError, e: + raise ObjectNotFoundError return actor def loadItems(self, mapfilename): for item in self._objectsettings.get("items", "itemlist", []): - newitem = self.loadItem(item) + try: + newitem = self.loadItem(item) + except ObjectNotFoundError, e: + print "Error while loading item:", item + continue + self.addObjectToScene(newitem) def loadActors(self, mapfilename): for npc in self._objectsettings.get("npcs", "npclist", []): - actor = self.loadActor(npc) + try: + actor = self.loadActor(npc) + except ObjectNotFoundError, e: + print "Error while loading actor:", actor + continue + self.addObjectToScene(actor) def loadPlayer(self):