comparison 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
comparison
equal deleted inserted replaced
97:f94d4577ca5e 98:c0db5f521695
676 entity_data = {} 676 entity_data = {}
677 entity_data["general"] = {"identifier": identifier} 677 entity_data["general"] = {"identifier": identifier}
678 for name, component in components.components.iteritems(): 678 for name, component in components.components.iteritems():
679 if getattr(entity, name): 679 if getattr(entity, name):
680 comp_data = {} 680 comp_data = {}
681 comp_vals = getattr(entity, name)
682 #Items that are in containers will be saved with them.
683 if name == "equipable" and entity.equipable.wearer or \
684 name == "containable" and entity.containable.container:
685 continue
686 else:
687 for field in component.saveable_fields:
688 try:
689 comp_data[field] = getattr(comp_vals, field)
690 except AttributeError:
691 #The entity doesn't have this specific value,
692 #ignore it
693 pass
694 if comp_data:
695 entity_data[name] = comp_data
681 if name == "fifeagent": 696 if name == "fifeagent":
682 if agent_data["Entity"].has_key("fifeagent"):
683 comp_data = agent_data["Entity"]["fifeagent"]
684 if entity.fifeagent.layer: 697 if entity.fifeagent.layer:
685 layer = entity.fifeagent.layer 698 layer = entity.fifeagent.layer
686 inst = layer.getInstance(identifier) 699 inst = layer.getInstance(identifier)
687 loc = inst.getLocation().getExactLayerCoordinates() 700 loc = inst.getLocation().getExactLayerCoordinates()
688 agent_data["Position"] = (loc.x, loc.y, loc.z) 701 agent_data["Position"] = (loc.x, loc.y, loc.z)
692 #TODO: Save Inventory 705 #TODO: Save Inventory
693 pass 706 pass
694 elif name == "equip": 707 elif name == "equip":
695 #TODO: Save Equipment 708 #TODO: Save Equipment
696 pass 709 pass
697 else:
698 comp_vals = getattr(entity, name)
699 for field in component.saveable_fields:
700 try:
701 comp_data[field] = getattr(comp_vals, field)
702 except AttributeError:
703 #The entity doesn't have this specific value,
704 #ignore it
705 pass
706 if comp_data:
707 entity_data[name] = comp_data
708 agent_data["Entity"] = entity_data 710 agent_data["Entity"] = entity_data
709 711
710 712
711 def getAgentImportFiles(self): 713 def getAgentImportFiles(self):
712 """Searches the agents directory for import files """ 714 """Searches the agents directory for import files """