Reworked slot-copying logic so that we can call it explicitly outside the append. Needed for the fitting commands to know what the previous item ID was that it's replacing.

This commit is contained in:
Ryan Holmes
2018-08-05 08:14:12 -04:00
parent 7a1b4b4a1e
commit 326e1e04c2
6 changed files with 31 additions and 5 deletions

View File

@@ -197,14 +197,20 @@ class HandledImplantBoosterList(HandledList):
self.remove(thing)
return
self.makeRoom(thing)
HandledList.append(self, thing)
def makeRoom(self, thing):
# if needed, remove booster that was occupying slot
oldObj = next((m for m in self if m.slot == thing.slot), None)
if oldObj:
pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name, thing.item.name)
pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name,
thing.item.name)
itemID = oldObj.itemID
oldObj.itemID = 0 # hack to remove from DB. See GH issue #324
self.remove(oldObj)
HandledList.append(self, thing)
return itemID
return None
class HandledSsoCharacterList(list):

View File

@@ -148,7 +148,7 @@ class BoosterView(d.Display):
def removeBooster(self, booster):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID, self.origional.index(booster)))
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, self.origional.index(booster)))
def click(self, event):
event.Skip()

View File

@@ -19,7 +19,7 @@ class FitAddBoosterCommand(wx.Command):
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)
@@ -31,11 +31,19 @@ class FitAddBoosterCommand(wx.Command):
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()

View File

@@ -18,6 +18,7 @@ class FitAddImplantCommand(wx.Command):
wx.Command.__init__(self, True, "Cargo add")
self.fitID = fitID
self.itemID = itemID
self.old_item = None
def Do(self):
pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.itemID)
@@ -30,11 +31,18 @@ class FitAddImplantCommand(wx.Command):
pyfalog.warning("Invalid item: {0}", self.itemID)
return False
self.old_item = fit.implants.makeRoom(implant)
fit.implants.append(implant)
self.new_index = fit.implants.index(implant)
return True
def Undo(self):
if self.old_item:
# If we had an item in the slot previously, add it back.
cmd = FitAddImplantCommand(self.fitID, self.old_item)
cmd.Do()
return True
from .fitRemoveImplant import FitRemoveImplantCommand # Avoid circular import
cmd = FitRemoveImplantCommand(self.fitID, self.new_index)
cmd.Do()

View File

@@ -17,6 +17,7 @@ class GuiAddBoosterCommand(wx.Command):
def Do(self):
if self.internal_history.Submit(self.cmd):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
return False
@@ -24,6 +25,7 @@ class GuiAddBoosterCommand(wx.Command):
def Undo(self):
for x in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -17,6 +17,7 @@ class GuiRemoveBoosterCommand(wx.Command):
def Do(self):
if self.internal_history.Submit(self.cmd):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
return False
@@ -24,6 +25,7 @@ class GuiRemoveBoosterCommand(wx.Command):
def Undo(self):
for x in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True