Better load and save interaction.
authorJeremy Thurgood <firxen@gmail.com>
Fri, 16 May 2014 17:42:09 +0000 (19:42 +0200)
committerJeremy Thurgood <firxen@gmail.com>
Fri, 16 May 2014 17:42:09 +0000 (19:42 +0200)
naja/scenes/load_save.py

index 28795041623321dfc8e3490111914c02a0c1fde5..8926e569e6b44992f6076a486549052ec5b64e32 100644 (file)
@@ -13,6 +13,7 @@ from naja.events import SceneChangeEvent, InvalidateTheWorld, LoadGameEvent
 from naja.gamestate import GameState
 from naja.options import options
 from naja.scenes.scene import Scene
+from naja.sound import sound
 from naja.widgets.save_slot import SaveSlotWidget
 from naja.widgets.selector import SelectorWidget
 
@@ -65,6 +66,15 @@ class LoadSaveGameBase(Scene):
             SceneChangeEvent.post(MenuScene)
             return
 
+    def fail(self):
+        sound.play_sound('error.ogg')
+        InvalidateTheWorld.post()
+
+    def succeed(self):
+        from naja.scenes.menu import MenuScene
+        sound.play_sound('chirp.ogg', volume=0.5)
+        SceneChangeEvent.post(MenuScene)
+
     def perform_action(self, slot_num):
         raise NotImplementedError("Nothing to see here.")
 
@@ -81,13 +91,17 @@ class SaveGameScene(LoadSaveGameBase):
                 json.dump(save_data, save_file)
         except Exception as e:
             print "Error saving game in slot %s: %s" % (slot_num, e)
-        self.slots[slot_num].game_data = self.get_game_data(slot_num)
-        InvalidateTheWorld.post()
+            self.fail()
+        else:
+            self.succeed()
 
 
 class LoadGameScene(LoadSaveGameBase):
     def perform_action(self, slot_num):
         game_data = self.get_game_data(slot_num)
-        state = GameState(game_data['data'])
         if game_data is not None:
+            state = GameState(game_data['data'])
             LoadGameEvent.post(state)
+            self.succeed()
+        else:
+            self.fail()