def start_singleplayer(options): """Starts a singleplayer game.""" _modules.gui.show_loading_screen() LoadingProgress.broadcast(None, "load_objects") global preloading preload_game_join(preloading) # remove cursor while loading horizons.globals.fife.cursor.set(fife_module.CURSOR_NONE) horizons.globals.fife.engine.pump() horizons.globals.fife.set_cursor_image("default") # destruct old session (right now, without waiting for gc) if _modules.session is not None and _modules.session.is_alive: _modules.session.end() if options.is_editor: from horizons.editor.session import EditorSession as session_class else: from horizons.spsession import SPSession as session_class # start new session _modules.session = session_class(horizons.globals.db) from horizons.scenario import InvalidScenarioFileFormat # would create import loop at top from horizons.util.savegameaccessor import MapFileNotFound from horizons.util.savegameupgrader import SavegameTooOld try: _modules.session.load(options) _modules.gui.close_all() except InvalidScenarioFileFormat: raise except (MapFileNotFound, SavegameTooOld, Exception): _modules.gui.close_all() # don't catch errors when we should fail fast (used by tests) if os.environ.get("FAIL_FAST", False): raise print "Failed to load", options.game_identifier traceback.print_exc() if _modules.session is not None and _modules.session.is_alive: try: _modules.session.end() except Exception: print traceback.print_exc() print "Additionally to failing when loading, cleanup afterwards also failed" _modules.gui.show_main() headline = _("Failed to start/load the game") descr = ( _("The game you selected could not be started.") + u" " + _("The savegame might be broken or has been saved with an earlier version.") ) _modules.gui.open_error_popup(headline, descr) _modules.gui.load_game() return _modules.session
def start_singleplayer(options): """Starts a singleplayer game.""" global gui, session, preloader gui.show_loading_screen() LoadingProgress.broadcast(None, 'load_objects') preloader.wait_for_finish() # remove cursor while loading horizons.globals.fife.cursor.set(fife_module.CURSOR_NONE) horizons.globals.fife.engine.pump() horizons.globals.fife.set_cursor_image('default') # destruct old session (right now, without waiting for gc) if session is not None and session.is_alive: session.end() if options.is_editor: from horizons.editor.session import EditorSession as session_class else: from horizons.spsession import SPSession as session_class # start new session session = session_class(horizons.globals.db) from horizons.scenario import InvalidScenarioFileFormat # would create import loop at top from horizons.util.savegameaccessor import MapFileNotFound from horizons.util.savegameupgrader import SavegameTooOld try: session.load(options) gui.close_all() except InvalidScenarioFileFormat: raise except (MapFileNotFound, SavegameTooOld, Exception): gui.close_all() # don't catch errors when we should fail fast (used by tests) if os.environ.get('FAIL_FAST', False): raise print("Failed to load", options.game_identifier) traceback.print_exc() if session is not None and session.is_alive: try: session.end() except Exception: print() traceback.print_exc() print( "Additionally to failing when loading, cleanup afterwards also failed" ) gui.show_main() headline = T("Failed to start/load the game") descr = T("The game you selected could not be started.") + " " + \ T("The savegame might be broken or has been saved with an earlier version.") gui.open_error_popup(headline, descr) gui.load_game() return session