Finish off commands for cargo to module action
This commit is contained in:
@@ -14,4 +14,5 @@ from .guiRemoveCommand import GuiRemoveCommandCommand
|
||||
from .guiSetMode import GuiSetModeCommand
|
||||
from .guiToggleCommand import GuiToggleCommandCommand
|
||||
from .guiAddProjected import GuiAddProjectedCommand
|
||||
from .guiRemoveProjected import GuiRemoveProjectedCommand
|
||||
from .guiRemoveProjected import GuiRemoveProjectedCommand
|
||||
from .guiCargoToModule import GuiCargoToModuleCommand
|
||||
54
gui/fitCommands/calc/fitCargoToModule.py
Normal file
54
gui/fitCommands/calc/fitCargoToModule.py
Normal file
@@ -0,0 +1,54 @@
|
||||
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
|
||||
pyfalog = Logger(__name__)
|
||||
from eos.saveddata.booster import Booster
|
||||
|
||||
class FitAddBoosterCommand(wx.Command):
|
||||
""""
|
||||
from sFit.addBooster
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_index = None
|
||||
self.old_item = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.itemID, self.fitID)
|
||||
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
item = eos.db.getItem(self.itemID, eager="attributes")
|
||||
|
||||
if next((x for x in fit.boosters if x.itemID == self.itemID), None):
|
||||
return False # already have item in list of boosters
|
||||
|
||||
try:
|
||||
booster = Booster(item)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", self.itemID)
|
||||
return False
|
||||
|
||||
self.old_item = fit.boosters.makeRoom(booster)
|
||||
fit.boosters.append(booster)
|
||||
self.new_index = fit.boosters.index(booster)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
if self.old_item:
|
||||
# If we had an item in the slot previously, add it back.
|
||||
cmd = FitAddBoosterCommand(self.fitID, self.old_item)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
from .fitRemoveBooster import FitRemoveBoosterCommand # Avoid circular import
|
||||
cmd = FitRemoveBoosterCommand(self.fitID, self.new_index)
|
||||
cmd.Do()
|
||||
return True
|
||||
@@ -1,100 +0,0 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.fitSetCharge import FitSetChargeCommand
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
class GuiCargoToModuleCommand(wx.Command):
|
||||
"""
|
||||
Moves cargo to fitting window. Can either do a copy, move, or swap with current module
|
||||
If we try to copy/move into a spot with a non-empty module, we swap instead.
|
||||
To avoid redundancy in converting Cargo item, this function does the
|
||||
sanity checks as opposed to the GUI View. This is different than how the
|
||||
normal .swapModules() does things, which is mostly a blind swap.
|
||||
"""
|
||||
|
||||
def __init__(self, fitID, moduleIdx, cargoIdx, copy=False):
|
||||
# todo: instead of modules, needs to be positions. Dead objects are a thing
|
||||
wx.Command.__init__(self, True, "Module State Change")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.moduleIdx = moduleIdx
|
||||
self.cargoIdx = cargoIdx
|
||||
self.copy = copy
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
module = fit.modules[self.moduleIdx]
|
||||
cargo = fit.cargo[self.cargoIdx]
|
||||
result = None
|
||||
|
||||
# We're trying to move a charge from cargo to a slot. Use SetCharge command (don't respect move vs copy)
|
||||
if sFit.isAmmo(cargo.item.ID):
|
||||
result = self.internal_history.Submit(FitSetChargeCommand(self.fitID, [module], cargo.item.ID))
|
||||
# else:
|
||||
#
|
||||
# pyfalog.debug("Moving cargo item to module for fit ID: {0}", self.fitID)
|
||||
#
|
||||
# # Gather modules and convert Cargo item to Module, silently return if not a module
|
||||
# try:
|
||||
# cargoP = es_Module(cargo.item)
|
||||
# cargoP.owner = fit
|
||||
# if cargoP.isValidState(State.ACTIVE):
|
||||
# cargoP.state = State.ACTIVE
|
||||
# except:
|
||||
# pyfalog.warning("Invalid item: {0}", cargo.item)
|
||||
# return
|
||||
#
|
||||
# if cargoP.slot != module.slot: # can't swap modules to different racks
|
||||
# return
|
||||
#
|
||||
# # remove module that we are trying to move cargo to
|
||||
# fit.modules.remove(module)
|
||||
#
|
||||
# if not cargoP.fits(fit): # if cargo doesn't fit, rollback and return
|
||||
# fit.modules.insert(moduleIdx, module)
|
||||
# return
|
||||
#
|
||||
# fit.modules.insert(moduleIdx, cargoP)
|
||||
#
|
||||
# if not copyMod: # remove existing cargo if not cloning
|
||||
# if cargo.amount == 1:
|
||||
# fit.cargo.remove(cargo)
|
||||
# else:
|
||||
# cargo.amount -= 1
|
||||
#
|
||||
# if not module.isEmpty: # if module is placeholder, we don't want to convert/add it
|
||||
# moduleItem = module.item if not module.item.isAbyssal else module.baseItem
|
||||
# for x in fit.cargo.find(moduleItem):
|
||||
# x.amount += 1
|
||||
# break
|
||||
# else:
|
||||
# moduleP = es_Cargo(moduleItem)
|
||||
# moduleP.amount = 1
|
||||
# fit.cargo.insert(cargoIdx, moduleP)
|
||||
#
|
||||
# eos.db.commit()
|
||||
# self.recalc(fit)
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# # if self.clone:
|
||||
# # result = self.internal_history.Submit(FitCloneModduleCommand(self.fitID, self.srcPosition, self.dstPosition))
|
||||
# # else:
|
||||
# # result = self.internal_history.Submit(FitSwapModuleCommand(self.fitID, self.srcPosition, self.dstPosition))
|
||||
|
||||
if result:
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return result
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
63
gui/fitCommands/guiCargoToModule.py
Normal file
63
gui/fitCommands/guiCargoToModule.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.fitSetCharge import FitSetChargeCommand
|
||||
from gui.fitCommands.calc.fitReplaceModule import FitReplaceModuleCommand
|
||||
from gui.fitCommands.calc.fitRemoveCargo import FitRemoveCargoCommand
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
class GuiCargoToModuleCommand(wx.Command):
|
||||
"""
|
||||
Moves cargo to fitting window. Can either do a copy, move, or swap with current module
|
||||
If we try to copy/move into a spot with a non-empty module, we swap instead.
|
||||
To avoid redundancy in converting Cargo item, this function does the
|
||||
sanity checks as opposed to the GUI View. This is different than how the
|
||||
normal .swapModules() does things, which is mostly a blind swap.
|
||||
"""
|
||||
|
||||
def __init__(self, fitID, moduleIdx, cargoIdx, copy=False):
|
||||
wx.Command.__init__(self, True, "Module State Change")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.moduleIdx = moduleIdx
|
||||
self.cargoIdx = cargoIdx
|
||||
self.copy = copy
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
module = fit.modules[self.moduleIdx]
|
||||
cargo = fit.cargo[self.cargoIdx]
|
||||
result = None
|
||||
|
||||
# We're trying to move a charge from cargo to a slot. Use SetCharge command (don't respect move vs copy)
|
||||
if sFit.isAmmo(cargo.item.ID):
|
||||
result = self.internal_history.Submit(FitSetChargeCommand(self.fitID, [module], cargo.item.ID))
|
||||
else:
|
||||
|
||||
pyfalog.debug("Moving cargo item to module for fit ID: {0}", self.fitID)
|
||||
|
||||
self.addCmd = FitReplaceModuleCommand(self.fitID, module.modPosition, cargo.itemID)
|
||||
result = self.internal_history.Submit(self.addCmd)
|
||||
if not result:
|
||||
# module failed
|
||||
return False
|
||||
|
||||
if not self.copy:
|
||||
self.removeCmd = FitRemoveCargoCommand(self.fitID, cargo.itemID)
|
||||
result = self.internal_history.Submit(self.removeCmd)
|
||||
|
||||
if result:
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return result
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
Reference in New Issue
Block a user