changeset 120:1703dbb4fefb

Added Behaviour component. Fixed updateObjectDB of GameModel storing values about components the Entity doesn't have.
author KarstenBock@gmx.net
date Tue, 27 Sep 2011 15:23:43 +0200
parents 3564a46544bc
children 24edf5d53083
files src/parpg/components/__init__.py src/parpg/components/behaviour.py src/parpg/gamemodel.py
diffstat 3 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
--- /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 <http://www.gnu.org/licenses/>.
+
+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
--- 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