# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1275331488 0 # Node ID 9fbe3dce925a966fc297ed8532e5a82b18945cea # Parent 65a92a2449d559180d6b7a958ebf6e6f5a36260c Added custom exceptions. diff -r 65a92a2449d5 -r 9fbe3dce925a demos/rpg/scripts/actors/baseactor.py --- a/demos/rpg/scripts/actors/baseactor.py Mon May 31 17:45:04 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Mon May 31 18:44:48 2010 +0000 @@ -34,7 +34,7 @@ Actions = {'NONE':0, 'PICKUP':1, 'TALK':2, - 'HIT':3, + 'ATTACK':3, 'OPEN':4, 'ENTER':5} diff -r 65a92a2449d5 -r 9fbe3dce925a demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Mon May 31 17:45:04 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Mon May 31 18:44:48 2010 +0000 @@ -35,6 +35,7 @@ from scripts.guicontroller import GUIController from scripts.actors.baseactor import TalkAction, PickUpItemAction from scripts.objects.baseobject import GameObjectTypes +from scripts.misc.exceptions import ObjectNotFoundError class KeyState(object): @@ -210,20 +211,22 @@ if cmd[0] == "spawn": result = "Usage: spawn [item|actor] [id] [posx] [posy]" if len(cmd) != 5: - print len(cmd) return result else: - if cmd[1] == "item": - obj = self._scene.loadItem(cmd[2]) - elif cmd[1] == "actor": - obj = self._scene.loadActor(cmd[2]) - else: - return result + try: + if cmd[1] == "item": + obj = self._scene.loadItem(cmd[2]) + elif cmd[1] == "actor": + obj = self._scene.loadActor(cmd[2]) + else: + return result + except ObjectNotFoundError, e: + result = "Error while loading object: " + cmd[2] + obj = None + if obj: self._scene.addObjectToScene(obj) result = "--OK--" - else: - result = "Error: Not Found!" return result diff -r 65a92a2449d5 -r 9fbe3dce925a demos/rpg/scripts/misc/__init__.py diff -r 65a92a2449d5 -r 9fbe3dce925a demos/rpg/scripts/misc/exceptions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/scripts/misc/exceptions.py Mon May 31 18:44:48 2010 +0000 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +# -*- coding: utf-8 -*- + +# #################################################################### +# Copyright (C) 2005-2010 by the FIFE team +# http://www.fifengine.net +# This file is part of FIFE. +# +# FIFE is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# #################################################################### +# This is the rio de hola client for FIFE. + + +class InvalidCommandError(Exception): + def __init__(self): + return + + def __str__(self): + print "","Command not found!" + +class ObjectNotFoundError(Exception): + def __init__(self): + return + + def __str__(self): + print "","Object was not found!" diff -r 65a92a2449d5 -r 9fbe3dce925a demos/rpg/scripts/scene.py --- 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):