Package horizons :: Package command :: Module game
[hide private]
[frames] | no frames]

Source Code for Module horizons.command.game

  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  from horizons.command import Command 
 23  from horizons.i18n import gettext as T 
 24  from horizons.savegamemanager import SavegameManager 
 25   
 26   
27 -class SaveCommand(Command):
28 """Used to init a save, which will happen at all network machines. 29 Only reasonable in multiplayer games."""
30 - def __init__(self, name):
31 self.name = name
32
33 - def __call__(self, issuer):
34 session = issuer.session 35 try: 36 path = SavegameManager.create_multiplayersave_filename(self.name) 37 except RuntimeError as e: 38 headline = T("Invalid filename") 39 msg = T("Received an invalid filename for a save command.") 40 session.ingame_gui.open_error_popup(headline, msg, str(e)) 41 return 42 43 self.log.debug("SaveCommand: save to %s", path) 44 45 success = session._do_save(path) 46 if success: 47 # TODO: distinguish auto/quick/normal 48 session.ingame_gui.message_widget.add('SAVED_GAME') 49 else: 50 session.ingame_gui.open_popup(T('Error'), T('Failed to save.'))
51 52 53 Command.allow_network(SaveCommand) 54 55
56 -class SpeedUpCommand(Command):
57 """Used to change the game speed""" 58
59 - def __call__(self, issuer):
60 session = issuer.session 61 session.speed_up()
62 63 64 Command.allow_network(SpeedUpCommand) 65 66
67 -class SpeedDownCommand(Command):
68 """Used to change the game speed""" 69
70 - def __call__(self, issuer):
71 session = issuer.session 72 session.speed_down()
73 74 75 Command.allow_network(SpeedDownCommand) 76 77
78 -class TogglePauseCommand(Command):
79 """Used to change the game speed""" 80
81 - def __call__(self, issuer):
84 85 86 Command.allow_network(TogglePauseCommand) 87 88
89 -class _SpeedCommand(Command):
90
91 - def __init__(self, suggestion=False):
92 self.suggestion = suggestion
93 94
95 -class UnPauseCommand(_SpeedCommand):
96 """Used to change the game speed""" 97
98 - def __call__(self, issuer):
99 session = issuer.session 100 session.speed_unpause(self.suggestion)
101 102 103 Command.allow_network(UnPauseCommand) 104 105
106 -class PauseCommand(_SpeedCommand):
107 """Used to change the game speed""" 108
109 - def __call__(self, issuer):
110 session = issuer.session 111 session.speed_pause(self.suggestion)
112 113 114 Command.allow_network(PauseCommand) 115