changeset 128:2a661e259b8b

updateObjectDB of GameModel now uses saveable_fields.
author KarstenBock@gmx.net
date Tue, 27 Sep 2011 16:29:39 +0200
parents 90b49fda0340
children 7583965ddcd6
files src/parpg/gamemodel.py
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/parpg/gamemodel.py	Tue Sep 27 16:27:36 2011 +0200
+++ b/src/parpg/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