Package horizons :: Package editor :: Module session
[hide private]
[frames] | no frames]

Source Code for Module horizons.editor.session

 1  # ################################################### 
 2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
 3  # team@unknown-horizons.org 
 4  # This file is part of Unknown Horizons. 
 5  # 
 6  # Unknown Horizons is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the 
18  # Free Software Foundation, Inc., 
19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
20  # ################################################### 
21   
22  import random 
23   
24  from horizons.constants import PATHS 
25  from horizons.editor.gui import IngameGui 
26  from horizons.editor.worldeditor import WorldEditor 
27  from horizons.i18n import gettext as T 
28  from horizons.manager import SPManager 
29  from horizons.session import Session 
30  from horizons.timer import Timer 
31   
32   
33 -class EditorSession(Session):
34
35 - def __init__(self, *args, **kwargs):
36 kwargs['ingame_gui_class'] = IngameGui 37 super().__init__(*args, **kwargs) 38 self.world_editor = None
39
40 - def create_manager(self):
41 return SPManager(self)
42
43 - def create_rng(self, seed=None):
44 return random.Random()
45
46 - def create_timer(self):
47 return Timer()
48
49 - def load(self, *args, **kwargs):
50 super().load(*args, **kwargs) 51 self.world_editor = WorldEditor(self.world) 52 self.ingame_gui.setup() 53 # editor "games" start right away 54 self.start()
55
56 - def autosave(self):
57 """Called automatically in an interval""" 58 self.log.debug("Session: autosaving map") 59 success = self.world_editor.save_map(PATHS.USER_MAPS_DIR, 'autosave') 60 if success: 61 self.ingame_gui.message_widget.add('AUTOSAVE')
62
63 - def quicksave(self):
64 """Called when user presses the quicksave hotkey""" 65 self.log.debug("Session: quicksaving map") 66 success = self.world_editor.save_map(PATHS.USER_MAPS_DIR, 'quicksave') 67 if success: 68 self.ingame_gui.message_widget.add('QUICKSAVE') 69 else: 70 headline = T("Failed to quicksave.") 71 descr = T("An error happened during quicksave.") + "\n" + T("Your map has not been saved.") 72 advice = T("If this error happens again, please contact the development team: " 73 "{website}").format(website="http://unknown-horizons.org/support/") 74 self.ingame_gui.open_error_popup(headline, descr, advice)
75
76 - def save(self, savegamename):
77 success = self.world_editor.save_map(PATHS.USER_MAPS_DIR, savegamename) 78 return success
79