# HG changeset patch # User KarstenBock@gmx.net # Date 1317129823 -7200 # Node ID 1703dbb4fefb64ecc6a1bd16328fdc1f1a72f7f5 # Parent 3564a46544bc74617c642493656e1a49232cf773 Added Behaviour component. Fixed updateObjectDB of GameModel storing values about components the Entity doesn't have. diff -r 3564a46544bc -r 1703dbb4fefb src/parpg/components/__init__.py --- a/src/parpg/components/__init__.py Tue Sep 27 14:58:03 2011 +0200 +++ b/src/parpg/components/__init__.py Tue Sep 27 15:23:43 2011 +0200 @@ -10,6 +10,7 @@ from equipable import Equipable from equip import Equip from general import General +from behaviour import Behaviour components = { "general": General(), @@ -24,4 +25,5 @@ "change_map": ChangeMap(), "equipable": Equipable(), "equip": Equip(), + "behaviour": Behaviour(), } \ No newline at end of file diff -r 3564a46544bc -r 1703dbb4fefb src/parpg/components/behaviour.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parpg/components/behaviour.py Tue Sep 27 15:23:43 2011 +0200 @@ -0,0 +1,22 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from base import Base + +class Behaviour(Base): + """Component that stores the values of the behaviour""" + + def __init__(self): + """Constructor""" + Base.__init__(self, behaviour_type=str) + self.behaviour_type = "Base" \ No newline at end of file diff -r 3564a46544bc -r 1703dbb4fefb src/parpg/gamemodel.py --- a/src/parpg/gamemodel.py Tue Sep 27 14:58:03 2011 +0200 +++ b/src/parpg/gamemodel.py Tue Sep 27 15:23:43 2011 +0200 @@ -437,9 +437,10 @@ target = fife.Location(self.active_map.agent_layer) inst.act('default', target, True) - - if entity_data["fifeagent"].has_key("behaviour"): - entity_data["fifeagent"]["behaviour"] = getattr(behaviours, entity_data["fifeagent"]["behaviour"])() + if entity_data.has_key("behaviour"): + entity_data["fifeagent"]["behaviour"] = \ + getattr(behaviours, + entity_data["behaviour"]["behaviour_type"])() else: entity_data["fifeagent"]["behaviour"] = behaviours.Base() if self.dialogues.has_key(inst_id): @@ -674,7 +675,7 @@ entity_data = {} entity_data["general"] = {"identifier": identifier} for name, component in components.components.iteritems(): - if hasattr(entity, name): + if getattr(entity, name): comp_data = {} if name == "fifeagent": if agent_data["Entity"].has_key("fifeagent"): @@ -701,7 +702,8 @@ #The entity doesn't have this specific value, #ignore it pass - entity_data[name] = comp_data + if comp_data: + entity_data[name] = comp_data agent_data["Entity"] = entity_data