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

Source Code for Module horizons.command.production

 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 GenericCommand, GenericComponentCommand 
23   
24   
25 -class ToggleActive(GenericComponentCommand):
26 """Sets a production to active/inactive."""
27 - def __init__(self, producer, production=None):
28 super().__init__(producer, "toggle_active") 29 self._production = None if production is None else production.prod_id
30
31 - def __call__(self, issuer):
32 # NOTE: special call method, cause production must be saved as id, not as Production obj 33 obj = self._get_object().get_component_by_name(self.component_name) 34 35 if self._production is not None: 36 production = obj._get_production(self._production) 37 assert production is not None, "{} does not have a production {}".format(obj, self._production) 38 else: 39 production = None 40 41 return getattr(obj, self.method)(production)
42 43 44 GenericComponentCommand.allow_network(ToggleActive) 45 46
47 -class AddProduction(GenericComponentCommand):
48 """Add a production to a producer"""
49 - def __init__(self, producer, production_line_id):
50 super().__init__(producer, "add_production_by_id", production_line_id)
51 52 53 GenericComponentCommand.allow_network(AddProduction) 54 55
56 -class RemoveFromQueue(GenericComponentCommand):
57 """Remove a production line id from a queueproducer's queue"""
58 - def __init__(self, producer, production_line_id):
59 super().__init__(producer, "remove_from_queue", production_line_id)
60 61 62 GenericComponentCommand.allow_network(RemoveFromQueue) 63 64
65 -class CancelCurrentProduction(GenericComponentCommand):
66 """Cancel the current production of a queueproducer. 67 Makes it proceed to the next one."""
68 - def __init__(self, producer):
69 super().__init__(producer, "cancel_current_production")
70 71 72 GenericCommand.allow_network(CancelCurrentProduction) 73