projected drone commands
This commit is contained in:
52
gui/fitCommands/calc/fitAddProjectedDrone.py
Normal file
52
gui/fitCommands/calc/fitAddProjectedDrone.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
from eos.saveddata.module import Module
|
||||
from eos.saveddata.drone import Drone
|
||||
from eos.saveddata.fighter import Fighter
|
||||
from .fitRemoveProjectedModule import FitRemoveProjectedModuleCommand
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class FitAddProjectedDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.project
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.index = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.itemID)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID)
|
||||
|
||||
drone = None
|
||||
for d in fit.projectedDrones.find(item):
|
||||
if d is None or d.amountActive == d.amount or d.amount >= 5:
|
||||
drone = d
|
||||
break
|
||||
|
||||
if drone is None:
|
||||
drone = Drone(item)
|
||||
fit.projectedDrones.append(drone)
|
||||
|
||||
self.index = fit.projectedDrones.index(drone)
|
||||
drone.amount += 1
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitRemoveProjectedDrone import FitRemoveProjectedDroneCommand # avoids circular import
|
||||
cmd = FitRemoveProjectedDroneCommand(self.fitID, self.index)
|
||||
cmd.Do()
|
||||
return True
|
||||
51
gui/fitCommands/calc/fitRemoveProjectedDrone.py
Normal file
51
gui/fitCommands/calc/fitRemoveProjectedDrone.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
#from .helpers import ModuleInfoCache
|
||||
from eos.saveddata.module import Module, State
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
from eos.saveddata.module import Module
|
||||
from eos.saveddata.drone import Drone
|
||||
from eos.saveddata.fighter import Fighter
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
# this has the same exact definition that regular projected modules, besides the undo
|
||||
class FitRemoveProjectedDroneCommand(wx.Command):
|
||||
""""
|
||||
from sFit.project
|
||||
"""
|
||||
|
||||
def __init__(self, fitID, position, stack=False):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.removed_item = None
|
||||
self.stack = stack
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing ({0}) onto: {1}", self.fitID, self.position)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
|
||||
drone = fit.projectedDrones[self.position]
|
||||
if self.stack:
|
||||
fit.projectedDrones.remove(drone)
|
||||
else:
|
||||
if drone.amount > 1:
|
||||
drone.amount -= 1
|
||||
else:
|
||||
fit.projectedDrones.remove(drone)
|
||||
|
||||
self.drone_item = drone.itemID
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitAddProjectedDrone import FitAddProjectedDroneCommand
|
||||
cmd = FitAddProjectedDroneCommand(self.fitID, self.drone_item)
|
||||
cmd.Do()
|
||||
return True
|
||||
@@ -15,7 +15,7 @@ pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
# this has the same exact definition that regular rpojected modules, besides the undo
|
||||
class FitRemoveProjectedFighterCommand(FitRemoveProjectedModuleCommand):
|
||||
class FitRemoveProjectedFighterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.project
|
||||
"""
|
||||
|
||||
@@ -8,6 +8,7 @@ from .calc.fitAddProjectedModule import FitAddProjectedModuleCommand
|
||||
from .calc.fitAddProjectedEnv import FitAddProjectedEnvCommand
|
||||
from .calc.fitAddProjectedFit import FitAddProjectedFitCommand
|
||||
from .calc.fitAddProjectedFighter import FitAddProjectedFighterCommand
|
||||
from .calc.fitAddProjectedDrone import FitAddProjectedDroneCommand
|
||||
from logbook import Logger
|
||||
import eos.db
|
||||
pyfalog = Logger(__name__)
|
||||
@@ -31,19 +32,7 @@ class GuiAddProjectedCommand(wx.Command):
|
||||
item = eos.db.getItem(self.id, eager=("attributes", "group.category"))
|
||||
|
||||
if item.category.name == "Drone":
|
||||
# @todo: this may need to be reworked once we visit drone commands
|
||||
pyfalog.warn("DRONE PROJECTION NOT IMPLEMENTED")
|
||||
# drone = None
|
||||
# for d in fit.projectedDrones.find(item):
|
||||
# if d is None or d.amountActive == d.amount or d.amount >= 5:
|
||||
# drone = d
|
||||
# break
|
||||
#
|
||||
# if drone is None:
|
||||
# drone = Drone(item)
|
||||
# fit.projectedDrones.append(drone)
|
||||
#
|
||||
# drone.amount += 1
|
||||
result = self.internal_history.Submit(FitAddProjectedDroneCommand(self.fitID, self.id))
|
||||
elif item.category.name == "Fighter":
|
||||
result = self.internal_history.Submit(FitAddProjectedFighterCommand(self.fitID, self.id))
|
||||
elif item.group.name in Module.SYSTEM_GROUPS:
|
||||
|
||||
@@ -9,8 +9,9 @@ from .calc.fitRemoveProjectedEnv import FitRemoveProjectedEnvCommand
|
||||
from .calc.fitRemoveProjectedFit import FitRemoveProjectedFitCommand
|
||||
from .calc.fitRemoveProjectedFighter import FitRemoveProjectedFighterCommand
|
||||
from logbook import Logger
|
||||
import eos.db
|
||||
from .calc.fitRemoveProjectedDrone import FitRemoveProjectedDroneCommand
|
||||
pyfalog = Logger(__name__)
|
||||
import eos.db
|
||||
|
||||
from eos.saveddata.drone import Drone
|
||||
from eos.saveddata.module import Module
|
||||
@@ -18,6 +19,14 @@ from eos.saveddata.fighter import Fighter
|
||||
|
||||
|
||||
class GuiRemoveProjectedCommand(wx.Command):
|
||||
mapping = {
|
||||
'fit': FitRemoveProjectedFitCommand,
|
||||
'module': FitRemoveProjectedModuleCommand,
|
||||
'fighter': FitRemoveProjectedFighterCommand,
|
||||
'env': FitRemoveProjectedEnvCommand,
|
||||
'drone': FitRemoveProjectedDroneCommand
|
||||
}
|
||||
|
||||
def __init__(self, fitID, thing):
|
||||
wx.Command.__init__(self, True, "Projected Add")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
@@ -49,14 +58,11 @@ class GuiRemoveProjectedCommand(wx.Command):
|
||||
result = False
|
||||
# since we can project various types, we need to switch of the fit command. We can't do this switch easily in
|
||||
# the fit command since each type might have a different kind of undo, easier to split it out
|
||||
if self.type == 'module':
|
||||
result = self.internal_history.Submit(FitRemoveProjectedModuleCommand(self.fitID, self.data))
|
||||
elif self.type == 'env':
|
||||
result = self.internal_history.Submit(FitRemoveProjectedEnvCommand(self.fitID, self.data))
|
||||
elif self.type == 'fit':
|
||||
result = self.internal_history.Submit(FitRemoveProjectedFitCommand(self.fitID, self.data))
|
||||
elif self.type == 'fighter':
|
||||
result = self.internal_history.Submit(FitRemoveProjectedFighterCommand(self.fitID, self.data))
|
||||
|
||||
cls = self.mapping.get(self.type, None)
|
||||
if cls:
|
||||
cmd = cls(self.fitID, self.data)
|
||||
result = self.internal_history.Submit(cmd)
|
||||
|
||||
# if item.category.name == "Drone":
|
||||
# pyfalog.warn("DRONE REMOVE PROJECTION NOT IMPLEMENTED")
|
||||
|
||||
Reference in New Issue
Block a user