diff gamescenecontroller.py @ 101:824f3068ef2a

Fixed Saving and Loading.
author KarstenBock@gmx.net
date Thu, 29 Sep 2011 18:09:56 +0200
parents 485d866a847f
children c9afad46091b
line wrap: on
line diff
--- a/gamescenecontroller.py	Wed Sep 28 15:01:04 2011 +0200
+++ b/gamescenecontroller.py	Thu Sep 29 18:09:56 2011 +0200
@@ -336,14 +336,19 @@
                 pc_agent = self.model.agents\
                     [self.model.ALL_AGENTS_KEY]["PlayerCharacter"]
                 pc_agent["Map"] = self.model.target_map_name 
-                pc_agent["Position"] = self.model.target_position
+                pc_agent["Position"] = (self.model.target_position or 
+                                        pc_agent["Position"])
                 player_agent = self.model.active_map.\
                                     agent_layer.getInstance("PlayerCharacter")
-                self.model.game_state.deleteObject("PlayerCharacter")
-                self.model.game_state.deleteObjectsFromMap(
+                self.model.game_state.deleteObject("PlayerCharacter").delete()
+                deleted = self.model.game_state.deleteObjectsFromMap(
                     self.model.game_state.current_map_name
                 )
-                self.model.game_state.deleteObjectsFromMap(None)
+                deleted.extend(
+                    self.model.game_state.deleteObjectsFromMap(None)
+                )
+                for obj in deleted:
+                    obj.delete()
             
             self.model.loadMap(self.model.target_map_name)
             
@@ -481,24 +486,32 @@
         return actions
     
     def saveGame(self, *args, **kwargs):
-        """Saves the game state, delegates call to engine.Engine
+        """Saves the game state, delegates call to gamemodel.GameModel
            @return: None"""
         self.model.pause(False)
         self.pause(False)
         self.view.hud.enabled = True
+        self.model.updateObjectDB(self)
         self.model.save(*args, **kwargs)
 
     def loadGame(self, *args, **kwargs):
-        """Loads the game state, delegates call to engine.Engine
+        """Loads the game state, delegates call to gamemodel.GameModel
            @return: None"""
         # Remove all currently loaded maps so we can start fresh
         self.model.pause(False)
         self.pause(False)
         self.view.hud.enabled = True
         self.model.deleteMaps()
+        for entity in self.entities.copy():
+            entity.delete()
         self.view.hud.inventory = None
 
         self.model.load(*args, **kwargs)
+        # Load the current map
+        if self.model.game_state.current_map_name:
+            self.model.loadMap(self.model.game_state.current_map_name)   
+        self.model.placeAgents(self)
+        self.model.placePC(self)
         self.view.hud.initializeInventory()          
 
     def quitGame(self):