Removed projected modules now keep their state for undoing
This commit is contained in:
@@ -280,38 +280,59 @@ class HandledSsoCharacterList(list):
|
||||
|
||||
|
||||
class HandledProjectedModList(HandledList):
|
||||
|
||||
def append(self, proj):
|
||||
if proj.isInvalid:
|
||||
# we must include it before we remove it. doing it this way ensures
|
||||
# rows and relationships in database are removed as well
|
||||
HandledList.append(self, proj)
|
||||
self.remove(proj)
|
||||
return
|
||||
return False
|
||||
|
||||
proj.projected = True
|
||||
|
||||
if proj.isExclusiveSystemEffect:
|
||||
self.makeRoom(proj)
|
||||
|
||||
HandledList.append(self, proj)
|
||||
|
||||
# Remove non-projectable modules
|
||||
if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect:
|
||||
self.remove(proj)
|
||||
return False
|
||||
return True
|
||||
|
||||
def insert(self, idx, proj):
|
||||
if proj.isInvalid:
|
||||
# we must include it before we remove it. doing it this way ensures
|
||||
# rows and relationships in database are removed as well
|
||||
HandledList.insert(self, idx, proj)
|
||||
self.remove(proj)
|
||||
return False
|
||||
|
||||
proj.projected = True
|
||||
|
||||
HandledList.insert(self, idx, proj)
|
||||
|
||||
# Remove non-projectable modules
|
||||
if not proj.item.isType("projected") and not proj.isExclusiveSystemEffect:
|
||||
self.remove(proj)
|
||||
return False
|
||||
return True
|
||||
|
||||
@property
|
||||
def currentSystemEffect(self):
|
||||
return next((m for m in self if m.isExclusiveSystemEffect), None)
|
||||
|
||||
def makeRoom(self, proj):
|
||||
# remove other system effects - only 1 per fit plz
|
||||
oldEffect = self.currentSystemEffect
|
||||
if proj.isExclusiveSystemEffect:
|
||||
# remove other system effects - only 1 per fit plz
|
||||
mod = self.currentSystemEffect
|
||||
|
||||
if oldEffect:
|
||||
pyfalog.info("System effect occupied with {0}, replacing with {1}", oldEffect.item.name, proj.item.name)
|
||||
self.remove(oldEffect)
|
||||
return oldEffect.itemID
|
||||
return None
|
||||
if mod:
|
||||
pyfalog.info("System effect occupied with {0}, removing it to make space for {1}".format(mod.item.name, proj.item.name))
|
||||
mutations = {m.attrID: m.value for m in mod.mutators.values()}
|
||||
position = self.index(mod)
|
||||
self.remove(mod)
|
||||
return mod.itemID, mod.baseItemID, mod.mutaplasmidID, mutations, mod.state, mod.chargeID, position
|
||||
return None, None, None, None, None, None, None
|
||||
|
||||
|
||||
class HandledProjectedDroneList(HandledDroneCargoList):
|
||||
|
||||
@@ -56,7 +56,7 @@ class FitAddModuleCommand(wx.Command):
|
||||
newMutaplasmidID=None,
|
||||
newMutations=None,
|
||||
newState=None,
|
||||
newCharge=None)
|
||||
newChargeID=None)
|
||||
return self.replace_cmd.Do()
|
||||
|
||||
if self.module.fits(fit):
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
from eos.saveddata.module import Module
|
||||
|
||||
import eos.db
|
||||
from eos.const import FittingModuleState
|
||||
from eos.saveddata.module import Module
|
||||
from gui.fitCommands.helpers import ModuleInfoCache
|
||||
from service.fit import Fit
|
||||
from service.market import Market
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
@@ -10,35 +16,79 @@ class FitAddProjectedModuleCommand(wx.Command):
|
||||
""""
|
||||
from sFit.project
|
||||
"""
|
||||
def __init__(self, fitID, itemID):
|
||||
def __init__(self, fitID, newItemID, newBaseItemID, newMutaplasmidID, newMutations, newState, newChargeID, newPosition):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_index = None
|
||||
self.newItemID = newItemID
|
||||
self.newBaseItemID = newBaseItemID
|
||||
self.newMutaplasmidID = newMutaplasmidID
|
||||
self.newMutations = newMutations
|
||||
self.newState = newState
|
||||
self.newChargeID = newChargeID
|
||||
self.newPosition = newPosition
|
||||
self.oldModuleInfo = 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, eager=("attributes", "group.category"))
|
||||
|
||||
try:
|
||||
module = Module(item)
|
||||
if not module.item.isType("projected"):
|
||||
return False
|
||||
except ValueError:
|
||||
pyfalog.debug("Projecting fit ({0}) onto: {1}", self.fitID, self.newItemID)
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = self.makeModule(self.newItemID, self.newBaseItemID, self.newMutaplasmidID, self.newMutations, self.newState, self.newChargeID)
|
||||
if mod is None:
|
||||
return False
|
||||
|
||||
module.state = FittingModuleState.ACTIVE
|
||||
if not module.canHaveState(module.state, fit):
|
||||
module.state = FittingModuleState.OFFLINE
|
||||
fit.projectedModules.append(module)
|
||||
if not mod.canHaveState(mod.state, fit):
|
||||
mod.state = FittingModuleState.OFFLINE
|
||||
|
||||
oldItemID, oldBaseItemID, oldMutaplasmidID, oldMutations, oldState, oldChargeID, oldPosition = fit.projectedModules.makeRoom(mod)
|
||||
if oldItemID is not None:
|
||||
self.oldModuleInfo = ModuleInfoCache(oldPosition, oldItemID, oldState, oldChargeID, oldBaseItemID, oldMutaplasmidID, oldMutations)
|
||||
|
||||
if self.newPosition is not None:
|
||||
fit.projectedModules.append(self.newPosition, mod)
|
||||
else:
|
||||
fit.projectedModules.append(mod)
|
||||
self.newPosition = fit.projectedModules.index(mod)
|
||||
|
||||
eos.db.commit()
|
||||
self.new_index = fit.projectedModules.index(module)
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitRemoveProjectedModule import FitRemoveProjectedModuleCommand # avoids circular import
|
||||
cmd = FitRemoveProjectedModuleCommand(self.fitID, self.new_index)
|
||||
cmd = FitRemoveProjectedModuleCommand(self.fitID, self.newPosition)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
def makeModule(self, itemID, baseItemID, mutaplasmidID, mutations, state, chargeID):
|
||||
mkt = Market.getInstance()
|
||||
|
||||
item = mkt.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if baseItemID and mutaplasmidID:
|
||||
baseItem = mkt.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
mutaplasmid = eos.db.getDynamicItem(mutaplasmidID)
|
||||
else:
|
||||
baseItem = None
|
||||
mutaplasmid = None
|
||||
try:
|
||||
mod = Module(item, baseItem, mutaplasmid)
|
||||
except ValueError:
|
||||
pyfalog.warning("Invalid item: {0}", itemID)
|
||||
return None
|
||||
|
||||
for attrID, mutator in mod.mutators.items():
|
||||
if attrID in mutations:
|
||||
mutator.value = mutations[attrID]
|
||||
|
||||
if state is not None:
|
||||
if not mod.isValidState(state):
|
||||
return None
|
||||
mod.state = state
|
||||
else:
|
||||
desiredState = FittingModuleState.ACTIVE
|
||||
if mod.isValidState(desiredState):
|
||||
mod.state = desiredState
|
||||
|
||||
if chargeID is not None:
|
||||
charge = mkt.getItem(chargeID)
|
||||
if charge is not None:
|
||||
mod.charge = charge
|
||||
|
||||
return mod
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import wx
|
||||
|
||||
from gui.fitCommands.helpers import ModuleInfoCache
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from gui.fitCommands.helpers import ModuleInfoCache
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
@@ -33,7 +35,7 @@ class FitRemoveModuleCommand(wx.Command):
|
||||
mod.modPosition,
|
||||
mod.item.ID,
|
||||
mod.state,
|
||||
mod.charge,
|
||||
mod.chargeID,
|
||||
mod.baseItemID,
|
||||
mod.mutaplasmidID,
|
||||
{m.attrID: m.value for m in mod.mutators.values()}))
|
||||
@@ -60,6 +62,6 @@ class FitRemoveModuleCommand(wx.Command):
|
||||
newMutaplasmidID=modInfo.mutaplasmidID,
|
||||
newMutations=modInfo.mutations,
|
||||
newState=modInfo.state,
|
||||
newCharge=modInfo.charge)
|
||||
newChargeID=modInfo.chargeID)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import wx
|
||||
import eos.db
|
||||
from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from service.fit import Fit
|
||||
from gui.fitCommands.helpers import ModuleInfoCache
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
@@ -12,12 +17,21 @@ class FitRemoveProjectedModuleCommand(wx.Command):
|
||||
wx.Command.__init__(self, True)
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.removed_item = None
|
||||
self.savedModInfo = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug("Removing ({0}) onto: {1}", self.fitID, self.position)
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
self.removed_item = fit.projectedModules[self.position].itemID
|
||||
pyfalog.debug("Removing ({}) onto: {}".format(self.fitID, self.position))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
mod = fit.projectedModules[self.position]
|
||||
self.savedModInfo = ModuleInfoCache(
|
||||
modPosition=self.position,
|
||||
itemID=mod.itemID,
|
||||
state=mod.state,
|
||||
chargeID=mod.chargeID,
|
||||
baseID=None,
|
||||
mutaplasmidID=None,
|
||||
mutations={})
|
||||
|
||||
del fit.projectedModules[self.position]
|
||||
|
||||
eos.db.commit()
|
||||
@@ -25,6 +39,14 @@ class FitRemoveProjectedModuleCommand(wx.Command):
|
||||
|
||||
def Undo(self):
|
||||
from gui.fitCommands.calc.fitAddProjectedModule import FitAddProjectedModuleCommand
|
||||
cmd = FitAddProjectedModuleCommand(self.fitID, self.removed_item)
|
||||
cmd = FitAddProjectedModuleCommand(
|
||||
fitID=self.fitID,
|
||||
newItemID=self.savedModInfo.itemID,
|
||||
newBaseItemID=self.savedModInfo.baseID,
|
||||
newMutaplasmidID=self.savedModInfo.mutaplasmidID,
|
||||
newMutations=self.savedModInfo.mutations,
|
||||
newState=self.savedModInfo.state,
|
||||
newChargeID=self.savedModInfo.chargeID,
|
||||
newPosition=self.savedModInfo.modPosition)
|
||||
cmd.Do()
|
||||
return True
|
||||
|
||||
@@ -16,7 +16,7 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
|
||||
from sFit.changeModule
|
||||
"""
|
||||
def __init__(self, fitID, position, newItemID, newBaseItemID, newMutaplasmidID, newMutations, newState, newCharge):
|
||||
def __init__(self, fitID, position, newItemID, newBaseItemID, newMutaplasmidID, newMutations, newState, newChargeID):
|
||||
wx.Command.__init__(self, True, "Change Module")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
@@ -25,7 +25,7 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
self.newMutaplasmidID = newMutaplasmidID
|
||||
self.newMutations = newMutations
|
||||
self.newState = newState
|
||||
self.newCharge = newCharge
|
||||
self.newChargeID = newChargeID
|
||||
self.oldModuleInfo = None
|
||||
|
||||
def Do(self):
|
||||
@@ -36,39 +36,38 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
mod.modPosition,
|
||||
mod.item.ID,
|
||||
mod.state,
|
||||
mod.charge,
|
||||
mod.chargeID,
|
||||
mod.baseItemID,
|
||||
mod.mutaplasmidID,
|
||||
{m.attrID: m.value for m in mod.mutators.values()})
|
||||
|
||||
newState = self.newState if self.newState is not None else getattr(self.oldModuleInfo, 'state', None)
|
||||
newCharge = self.newCharge if self.newCharge is not None else getattr(self.oldModuleInfo, 'charge', None)
|
||||
return self.changeModule(self.newItemID, self.newBaseItemID, self.newMutaplasmidID, self.newMutations, newState, newCharge)
|
||||
newChargeID = self.newChargeID if self.newChargeID is not None else getattr(self.oldModuleInfo, 'chargeID', None)
|
||||
return self.changeModule(self.newItemID, self.newBaseItemID, self.newMutaplasmidID, self.newMutations, newState, newChargeID)
|
||||
|
||||
def Undo(self):
|
||||
if self.oldModuleInfo is None:
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
fit.modules.toDummy(self.position)
|
||||
return True
|
||||
self.changeModule(
|
||||
return self.changeModule(
|
||||
self.oldModuleInfo.itemID,
|
||||
self.oldModuleInfo.baseID,
|
||||
self.oldModuleInfo.mutaplasmidID,
|
||||
self.oldModuleInfo.mutations,
|
||||
self.oldModuleInfo.state,
|
||||
self.oldModuleInfo.charge)
|
||||
return True
|
||||
self.oldModuleInfo.chargeID)
|
||||
|
||||
def changeModule(self, itemID, baseItemID, mutaplasmidID, mutations, state, charge):
|
||||
fit = eos.db.getFit(self.fitID)
|
||||
def changeModule(self, itemID, baseItemID, mutaplasmidID, mutations, state, chargeID):
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
oldMod = fit.modules[self.position]
|
||||
|
||||
pyfalog.debug("Changing module on position ({0}) for fit ID: {1}", self.position, self.fitID)
|
||||
|
||||
sMarket = Market.getInstance()
|
||||
item = sMarket.getItem(itemID, eager=("attributes", "group.category"))
|
||||
mkt = Market.getInstance()
|
||||
item = mkt.getItem(itemID, eager=("attributes", "group.category"))
|
||||
if baseItemID and mutaplasmidID:
|
||||
baseItem = sMarket.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
baseItem = mkt.getItem(baseItemID, eager=("attributes", "group.category"))
|
||||
mutaplasmid = eos.db.getDynamicItem(mutaplasmidID)
|
||||
else:
|
||||
baseItem = None
|
||||
@@ -96,12 +95,20 @@ class FitReplaceModuleCommand(wx.Command):
|
||||
|
||||
newMod.owner = fit
|
||||
fit.modules.toModule(self.position, newMod)
|
||||
desiredState = stateLimit(newMod.item) if state is None else state
|
||||
if newMod.isValidState(desiredState):
|
||||
newMod.state = desiredState
|
||||
|
||||
if charge is not None:
|
||||
newMod.charge = charge
|
||||
if state is not None:
|
||||
if not newMod.isValidState(state):
|
||||
return False
|
||||
newMod.state = state
|
||||
else:
|
||||
desiredState = stateLimit(newMod.item) if state is None else state
|
||||
if newMod.isValidState(desiredState):
|
||||
newMod.state = desiredState
|
||||
|
||||
if chargeID is not None:
|
||||
charge = mkt.getItem(chargeID)
|
||||
if charge is not None:
|
||||
newMod.charge = charge
|
||||
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
@@ -50,7 +50,7 @@ class GuiModuleAddCommand(wx.Command):
|
||||
newMutaplasmidID=None,
|
||||
newMutations=None,
|
||||
newState=None,
|
||||
newCharge=None))
|
||||
newChargeID=None))
|
||||
if not success:
|
||||
pyfalog.debug(" Failed")
|
||||
# something went wrong with trying to fit the module into specific location, attempt to append it
|
||||
|
||||
@@ -38,7 +38,7 @@ class GuiAddProjectedCommand(wx.Command):
|
||||
elif item.group.name in Module.SYSTEM_GROUPS:
|
||||
result = self.internal_history.Submit(FitAddProjectedEnvCommand(self.fitID, self.id))
|
||||
else:
|
||||
result = self.internal_history.Submit(FitAddProjectedModuleCommand(self.fitID, self.id))
|
||||
result = self.internal_history.Submit(FitAddProjectedModuleCommand(self.fitID, self.id, None, None, None, None, None, None))
|
||||
elif self.type == 'fit':
|
||||
result = self.internal_history.Submit(FitAddProjectedFitCommand(self.fitID, self.id))
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class GuiCargoToModuleCommand(wx.Command):
|
||||
newMutaplasmidID=None,
|
||||
newMutations=None,
|
||||
newState=None,
|
||||
newCharge=None)
|
||||
newChargeID=None)
|
||||
|
||||
result = self.internal_history.Submit(self.addCmd)
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ class GuiMetaSwapCommand(wx.Command):
|
||||
|
||||
if context == 'fittingModule':
|
||||
for x in selection:
|
||||
self.data.append(((FitReplaceModuleCommand, fitID, fit.modules.index(x), itemID),),)
|
||||
position = fit.modules.index(x)
|
||||
state = x.state
|
||||
chargeID = x.chargeID
|
||||
self.data.append(((FitReplaceModuleCommand, fitID, position, itemID, None, None, None, state, chargeID),),)
|
||||
elif context == 'implantItem':
|
||||
for x in selection:
|
||||
idx = fit.implants.index(x)
|
||||
|
||||
@@ -13,6 +13,7 @@ pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiModuleToCargoCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, moduleIdx, cargoIdx, copy=False):
|
||||
wx.Command.__init__(self, True, "Module to Cargo")
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
@@ -33,7 +33,7 @@ class GuiMutaConvertCommand(wx.Command):
|
||||
newMutaplasmidID=self.mutaplasmid.ID,
|
||||
newMutations={},
|
||||
newState=oldMod.state,
|
||||
newCharge=oldMod.charge))
|
||||
newChargeID=oldMod.chargeID))
|
||||
if not success:
|
||||
return False
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class GuiMutaRevertCommand(wx.Command):
|
||||
newMutaplasmidID=None,
|
||||
newMutations=None,
|
||||
newState=oldMod.state,
|
||||
newCharge=oldMod.charge))
|
||||
newChargeID=oldMod.chargeID))
|
||||
if not success:
|
||||
return False
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class GuiModuleRemoveCommand(wx.Command):
|
||||
mod.modPosition,
|
||||
mod.item.ID,
|
||||
mod.state,
|
||||
mod.charge,
|
||||
mod.chargeID,
|
||||
mod.baseItemID,
|
||||
mod.mutaplasmidID,
|
||||
{m.attrID: m.value for m in mod.mutators.values()}) for mod in modules if not mod.isEmpty]
|
||||
|
||||
@@ -3,7 +3,7 @@ from collections import namedtuple
|
||||
from eos.const import FittingModuleState
|
||||
|
||||
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'charge', 'baseID', 'mutaplasmidID', 'mutations'])
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'chargeID', 'baseID', 'mutaplasmidID', 'mutations'])
|
||||
|
||||
|
||||
def stateLimit(item):
|
||||
|
||||
Reference in New Issue
Block a user