Make conversion to mutaplasmid undoable
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from gui.contextMenu import ContextMenu
|
||||
import gui.mainFrame
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
import gui.globalEvents as GE
|
||||
import gui.mainFrame
|
||||
from gui.fitCommands import GuiMutaConvertCommand
|
||||
from gui.contextMenu import ContextMenu
|
||||
from service.fit import Fit
|
||||
from service.settings import ContextMenuSettings
|
||||
|
||||
@@ -55,13 +57,11 @@ class MutaplasmidCM(ContextMenu):
|
||||
|
||||
def handleMenu(self, event):
|
||||
mutaplasmid, mod = self.eventIDs[event.Id]
|
||||
fit = self.mainFrame.getActiveFit()
|
||||
sFit = Fit.getInstance()
|
||||
|
||||
# todo: dev out function to switch module to an abyssal module. Also, maybe open item stats here automatically
|
||||
# with the attribute tab set?
|
||||
sFit.convertMutaplasmid(fit, mod.modPosition, mutaplasmid)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fit))
|
||||
self.mainFrame.command.Submit(GuiMutaConvertCommand(
|
||||
fitID=self.mainFrame.getActiveFit(),
|
||||
position=mod.modPosition,
|
||||
mutaplasmid=mutaplasmid))
|
||||
|
||||
def activate(self, fullContext, selection, i):
|
||||
sFit = Fit.getInstance()
|
||||
|
||||
@@ -37,3 +37,4 @@ from .guiChangeImplantLocation import GuiChangeImplantLocation
|
||||
from .guiImportMutatedModule import GuiImportMutatedModuleCommand
|
||||
from .guiSetSpoolup import GuiSetSpoolup
|
||||
from .guiRebaseItems import GuiRebaseItemsCommand
|
||||
from .guiMutaConvert import GuiMutaConvertCommand
|
||||
|
||||
@@ -11,7 +11,7 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class FitChangeStatesCommand(wx.Command):
|
||||
"""
|
||||
Fitting command that trys to change the state of modules in [positions]. We use the base module to determine the
|
||||
Fitting command that tries to change the state of modules in [positions]. We use the base module to determine the
|
||||
state that we will try to apply for all modules.
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from logbook import Logger
|
||||
import eos.db
|
||||
from eos.saveddata.module import Module
|
||||
from gui.fitCommands.helpers import ModuleInfoCache, stateLimit
|
||||
from service.fit import Fit
|
||||
from service.market import Market
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -27,7 +29,7 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
self.oldModuleInfo = None
|
||||
|
||||
def Do(self):
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = fit.modules[self.position]
|
||||
if not mod.isEmpty:
|
||||
self.oldModuleInfo = ModuleInfoCache(
|
||||
@@ -45,7 +47,7 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
|
||||
def Undo(self):
|
||||
if self.oldModuleInfo is None:
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
fit.modules.toDummy(self.position)
|
||||
return True
|
||||
self.changeModule(
|
||||
@@ -63,9 +65,10 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
|
||||
pyfalog.debug("Changing module on position ({0}) for fit ID: {1}", self.position, self.fitID)
|
||||
|
||||
item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
|
||||
sMarket = Market.getInstance()
|
||||
item = sMarket.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if baseItemID and mutaplasmidID:
|
||||
baseItem = eos.db.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
baseItem = sMarket.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
mutaplasmid = eos.db.getDynamicItem(mutaplasmidID)
|
||||
else:
|
||||
baseItem = None
|
||||
|
||||
45
gui/fitCommands/guiMutaConvert.py
Normal file
45
gui/fitCommands/guiMutaConvert.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from service.fit import Fit
|
||||
from .calc.fitReplaceModule import FitReplaceModuleCommand
|
||||
|
||||
|
||||
class GuiMutaConvertCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, mutaplasmid):
|
||||
wx.Command.__init__(self, True, "Convert Item to Mutated")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.internal_history = wx.CommandProcessor()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.mutaplasmid = mutaplasmid
|
||||
|
||||
def Do(self):
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
oldMod = fit.modules[self.position]
|
||||
|
||||
success = self.internal_history.Submit(FitReplaceModuleCommand(
|
||||
fitID=self.fitID,
|
||||
position=self.position,
|
||||
newItemID=self.mutaplasmid.resultingItem.ID,
|
||||
newBaseItemID=oldMod.item.ID,
|
||||
newMutaplasmidID=self.mutaplasmid.ID,
|
||||
newMutations={},
|
||||
newState=oldMod.state,
|
||||
newCharge=oldMod.charge))
|
||||
if not success:
|
||||
return False
|
||||
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internal_history.Commands:
|
||||
self.internal_history.Undo()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
@@ -369,37 +369,6 @@ class Fit(FitDeprecated):
|
||||
eos.db.commit()
|
||||
return mutator.value
|
||||
|
||||
def convertMutaplasmid(self, fitID, position, mutaplasmid):
|
||||
# this is mostly the same thing as the self.changeModule method, however it initializes an abyssal module with
|
||||
# the old module as it's base, and then replaces it
|
||||
fit = eos.db.getFit(fitID)
|
||||
base = fit.modules[position]
|
||||
fit.modules.toDummy(position)
|
||||
|
||||
try:
|
||||
m = es_Module(mutaplasmid.resultingItem, base.item, mutaplasmid)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0} AHHHH")
|
||||
return False
|
||||
|
||||
if m.fits(fit):
|
||||
m.owner = fit
|
||||
fit.modules.toModule(position, m)
|
||||
if m.isValidState(FittingModuleState.ACTIVE):
|
||||
m.state = FittingModuleState.ACTIVE
|
||||
|
||||
# As some items may affect state-limiting attributes of the ship, calculate new attributes first
|
||||
self.recalc(fit)
|
||||
# Then, check states of all modules and change where needed. This will recalc if needed
|
||||
self.checkStates(fit, m)
|
||||
|
||||
fit.fill()
|
||||
eos.db.commit()
|
||||
|
||||
return True
|
||||
else:
|
||||
return None
|
||||
|
||||
@deprecated
|
||||
def addDrone(self, fitID, itemID, numDronesToAdd=1, recalc=True):
|
||||
pyfalog.debug("Adding {0} drones ({1}) to fit ID: {2}", numDronesToAdd, itemID, fitID)
|
||||
|
||||
Reference in New Issue
Block a user