From: Jeremy Thurgood Date: Fri, 16 May 2014 17:42:09 +0000 (+0200) Subject: Better load and save interaction. X-Git-Tag: 0.1~207 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=fa35524a58d185e585e779aabf5b14807bc8e5c6;p=naja.git Better load and save interaction. --- diff --git a/naja/scenes/load_save.py b/naja/scenes/load_save.py index 2879504..8926e56 100644 --- a/naja/scenes/load_save.py +++ b/naja/scenes/load_save.py @@ -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()