Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
534:65a92a2449d5 | 535:9fbe3dce925a |
---|---|
35 from scripts.actors.questgiver import QuestGiver | 35 from scripts.actors.questgiver import QuestGiver |
36 from scripts.quests.basequest import Quest | 36 from scripts.quests.basequest import Quest |
37 from scripts.actors.player import Player | 37 from scripts.actors.player import Player |
38 from scripts.objects.baseobject import GameObjectTypes | 38 from scripts.objects.baseobject import GameObjectTypes |
39 from scripts.objects.items import BaseItem, GoldStack | 39 from scripts.objects.items import BaseItem, GoldStack |
40 from scripts.misc.exceptions import ObjectNotFoundError | |
40 | 41 |
41 class Scene(object): | 42 class Scene(object): |
42 def __init__(self, gamecontroller): | 43 def __init__(self, gamecontroller): |
43 self._gamecontroller = gamecontroller | 44 self._gamecontroller = gamecontroller |
44 | 45 |
68 else: | 69 else: |
69 newitem = BaseItem(self._gamecontroller, modeldict["model"], itemid) | 70 newitem = BaseItem(self._gamecontroller, modeldict["model"], itemid) |
70 | 71 |
71 newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) | 72 newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) |
72 | 73 |
73 except (KeyError) as e: | 74 except KeyError, e: |
74 print "Error: ", e | 75 raise FileFormatError |
75 newitem = None | |
76 | 76 |
77 return newitem | 77 return newitem |
78 | 78 |
79 def loadActor(self, actorid): | 79 def loadActor(self, actorid): |
80 try: | 80 try: |
102 elif modeldict["type"] == "NPC": | 102 elif modeldict["type"] == "NPC": |
103 actor = Actor(self._gamecontroller, modeldict["model"], npc, True) | 103 actor = Actor(self._gamecontroller, modeldict["model"], npc, True) |
104 | 104 |
105 actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) | 105 actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) |
106 | 106 |
107 except (KeyError) as e: | 107 except KeyError, e: |
108 print "Error: ", e | 108 raise ObjectNotFoundError |
109 actor = None | |
110 | 109 |
111 return actor | 110 return actor |
112 | 111 |
113 def loadItems(self, mapfilename): | 112 def loadItems(self, mapfilename): |
114 for item in self._objectsettings.get("items", "itemlist", []): | 113 for item in self._objectsettings.get("items", "itemlist", []): |
115 newitem = self.loadItem(item) | 114 try: |
115 newitem = self.loadItem(item) | |
116 except ObjectNotFoundError, e: | |
117 print "Error while loading item:", item | |
118 continue | |
119 | |
116 self.addObjectToScene(newitem) | 120 self.addObjectToScene(newitem) |
117 | 121 |
118 def loadActors(self, mapfilename): | 122 def loadActors(self, mapfilename): |
119 for npc in self._objectsettings.get("npcs", "npclist", []): | 123 for npc in self._objectsettings.get("npcs", "npclist", []): |
120 actor = self.loadActor(npc) | 124 try: |
125 actor = self.loadActor(npc) | |
126 except ObjectNotFoundError, e: | |
127 print "Error while loading actor:", actor | |
128 continue | |
129 | |
121 self.addObjectToScene(actor) | 130 self.addObjectToScene(actor) |
122 | 131 |
123 def loadPlayer(self): | 132 def loadPlayer(self): |
124 """ | 133 """ |
125 @todo: once we have all art assets this should be able to load one of 3 player models | 134 @todo: once we have all art assets this should be able to load one of 3 player models |