diff gamestate.py @ 101:824f3068ef2a

Fixed Saving and Loading.
author KarstenBock@gmx.net
date Thu, 29 Sep 2011 18:09:56 +0200
parents 0411a4bcceee
children 75c0b728ccf3
line wrap: on
line diff
--- a/gamestate.py	Wed Sep 28 15:01:04 2011 +0200
+++ b/gamestate.py	Thu Sep 29 18:09:56 2011 +0200
@@ -22,7 +22,6 @@
         self.quest_engine = QuestEngine(quests_dir)
         self.quest_engine.readQuests()
         self.objects = {}
-        self.objects[None] = {}
         self.object_ids = {}
         self.current_map_name = None
         self.maps = {}
@@ -41,6 +40,8 @@
         @type object: GameObject
         """
         if not self.object_ids.has_key(object_id):
+            if not self.objects.has_key(map_id):
+                self.objects[map_id] = {}
             self.objects[map_id][object_id] = game_object
             self.object_ids[object_id] = map_id
     
@@ -48,15 +49,18 @@
         """Removes an object from the dictionaries
         @param object_id: ID of the object
         @type object_id: str
+        @returns The deleted object
         """
         if self.hasObject(object_id):
             map_id = self.getMapOfObject(object_id)
             if map_id:
                 inst = self.maps[map_id].agent_layer.getInstance(object_id)
                 self.maps[map_id].agent_layer.deleteInstance(inst)
-            self.objects[map_id][object_id].delete()
+            obj = self.objects[map_id][object_id]
             del self.objects[map_id][object_id]
             del self.object_ids[object_id]
+            return obj
+        return None
             
             
     def getObjectsFromMap(self, map_id):
@@ -75,9 +79,11 @@
            @type map: String
            @param map: The map name.
            @returns: None"""
+        deleted_objs = []
         if map_id in self.objects:
             for obj in self.objects[map_id].copy():
-                self.deleteObject(obj)
+                deleted_objs.append(self.deleteObject(obj))
+        return deleted_objs
     
     def hasObject(self, object_id):
         """Check if an object with the given id is present 
@@ -126,11 +132,13 @@
         ret_dict = {}
         ret_dict["CurrentMap"] = self.current_map_name
         ret_dict["Quests"] = self.quest_engine.getStateForSaving()
+        ret_dict["NPCsMet"] = self.npcs_met
         return ret_dict
 
     def restoreFromState(self, state):
         """Restores the state"""
         self.current_map_name = state["CurrentMap"]
+        self.npcs_met = state["NPCsMet"]
         self.quest_engine.readQuests()
         self.quest_engine.restoreFromState(state["Quests"])