diff gamemodel.py @ 98:c0db5f521695

updateObjectDB of GameModel now uses saveable_fields.
author KarstenBock@gmx.net
date Tue, 27 Sep 2011 16:29:39 +0200
parents 84b5808d995c
children 6e4daff93e7d
line wrap: on
line diff
--- a/gamemodel.py	Tue Sep 27 16:27:36 2011 +0200
+++ b/gamemodel.py	Tue Sep 27 16:29:39 2011 +0200
@@ -678,9 +678,22 @@
             for name, component in components.components.iteritems():
                 if getattr(entity, name):
                     comp_data = {}
+                    comp_vals = getattr(entity, name)
+                    #Items that are in containers will be saved with them.
+                    if name == "equipable" and entity.equipable.wearer or \
+                       name == "containable" and entity.containable.container:
+                        continue
+                    else:
+                        for field in component.saveable_fields:
+                            try:
+                                comp_data[field] = getattr(comp_vals, field)
+                            except AttributeError:                            
+                                #The entity doesn't have this specific value,
+                                #ignore it
+                                pass
+                        if comp_data:
+                            entity_data[name] = comp_data
                     if name == "fifeagent":
-                        if agent_data["Entity"].has_key("fifeagent"):
-                            comp_data = agent_data["Entity"]["fifeagent"]
                         if entity.fifeagent.layer:
                             layer = entity.fifeagent.layer
                             inst = layer.getInstance(identifier)
@@ -694,17 +707,6 @@
                     elif name == "equip":
                         #TODO: Save Equipment
                         pass                        
-                    else:
-                        comp_vals = getattr(entity, name)
-                        for field in component.saveable_fields:
-                            try:
-                                comp_data[field] = getattr(comp_vals, field)
-                            except AttributeError:                            
-                                #The entity doesn't have this specific value,
-                                #ignore it
-                                pass
-                    if comp_data:
-                        entity_data[name] = comp_data
             agent_data["Entity"] = entity_data