示例#1
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     results = []
     for itemID in self.itemIDs:
         if itemID == self.newItemID:
             continue
         cargo = next((c for c in fit.cargo if c.itemID == itemID), None)
         if cargo is None:
             continue
         amount = cargo.amount
         cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID,
                                            cargoInfo=CargoInfo(
                                                itemID=itemID,
                                                amount=math.inf))
         cmdAdd = CalcAddCargoCommand(fitID=self.fitID,
                                      cargoInfo=CargoInfo(
                                          itemID=self.newItemID,
                                          amount=amount))
         results.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
     success = any(results)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitIDs=(self.fitID, )))
     return success
示例#2
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     for mod in fit.modules:
         if mod.itemID in self.rebaseMap:
             cmd = CalcRebaseItemCommand(fitID=self.fitID,
                                         containerName='modules',
                                         position=fit.modules.index(mod),
                                         itemID=self.rebaseMap[mod.itemID],
                                         commit=False)
             self.internalHistory.submit(cmd)
         if mod.chargeID in self.rebaseMap:
             cmd = CalcChangeModuleChargesCommand(
                 fitID=self.fitID,
                 projected=False,
                 chargeMap={
                     fit.modules.index(mod): self.rebaseMap[mod.chargeID]
                 },
                 commit=False)
             self.internalHistory.submit(cmd)
     for containerName in ('drones', 'fighters', 'implants', 'boosters'):
         container = getattr(fit, containerName)
         for obj in container:
             if obj.itemID in self.rebaseMap:
                 cmd = CalcRebaseItemCommand(
                     fitID=self.fitID,
                     containerName=containerName,
                     position=container.index(obj),
                     itemID=self.rebaseMap[obj.itemID],
                     commit=False)
                 self.internalHistory.submit(cmd)
     # Need to process cargo separately as we want to merge items when needed,
     # e.g. FN iron and CN iron into single stack of CN iron
     for cargo in fit.cargo:
         if cargo.itemID in self.rebaseMap:
             amount = cargo.amount
             cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID,
                                                cargoInfo=CargoInfo(
                                                    itemID=cargo.itemID,
                                                    amount=amount),
                                                commit=False)
             cmdAdd = CalcAddCargoCommand(
                 fitID=self.fitID,
                 cargoInfo=CargoInfo(itemID=self.rebaseMap[cargo.itemID],
                                     amount=amount),
                 commit=False)
             self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     eos.db.commit()
     sFit.recalc(fit)
     sFit.fill(self.fitID)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return len(self.internalHistory) > 0
示例#3
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     cargo = next((c for c in fit.cargo if c.itemID == self.itemID), None)
     if cargo is None:
         return False
     if cargo.itemID == self.newItemID:
         return False
     amount = cargo.amount
     cmdRemove = CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))
     cmdAdd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.newItemID, amount=amount))
     success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
 def Do(self):
     if self.amount > 0:
         cmd = CalcChangeCargoAmountCommand(fitID=self.fitID,
                                            cargoInfo=CargoInfo(
                                                itemID=self.itemID,
                                                amount=self.amount))
     else:
         cmd = CalcRemoveCargoCommand(fitID=self.fitID,
                                      cargoInfo=CargoInfo(
                                          itemID=self.itemID,
                                          amount=math.inf))
     success = self.internalHistory.submit(cmd)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitID=self.fitID))
     return success
示例#5
0
 def Undo(self):
     pyfalog.debug('Undoing removal of cargo {} to fit {}'.format(self.cargoInfo, self.fitID))
     from .add import CalcAddCargoCommand
     cmd = CalcAddCargoCommand(
         fitID=self.fitID,
         cargoInfo=CargoInfo(itemID=self.cargoInfo.itemID, amount=self.savedRemovedAmount),
         commit=self.commit)
     return cmd.Do()
示例#6
0
文件: add.py 项目: bsmr/pyfa-org-Pyfa
 def Do(self):
     cmd = CalcAddCargoCommand(fitID=self.fitID,
                               cargoInfo=CargoInfo(itemID=self.itemID,
                                                   amount=self.amount))
     success = self.internalHistory.submit(cmd)
     Market.getInstance().storeRecentlyUsed(self.itemID)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(),
                  GE.FitChanged(fitIDs=(self.fitID, )))
     return success
示例#7
0
 def Do(self):
     results = []
     for itemID in self.itemIDs:
         cmd = CalcRemoveCargoCommand(
             fitID=self.fitID,
             cargoInfo=CargoInfo(itemID=itemID, amount=math.inf))
         results.append(self.internalHistory.submit(cmd))
     success = any(results)
     eos.db.commit()
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success
示例#8
0
 def Do(self):
     pyfalog.debug('Doing change of cargo {} for fit {}'.format(self.cargoInfo, self.fitID))
     fit = Fit.getInstance().getFit(self.fitID)
     cargo = next((c for c in fit.cargo if c.itemID == self.cargoInfo.itemID), None)
     if cargo is None:
         pyfalog.warning('Cannot find cargo item')
         return False
     self.savedCargoInfo = CargoInfo.fromCargo(cargo)
     if self.cargoInfo.amount == self.savedCargoInfo.amount:
         return False
     cargo.amount = self.cargoInfo.amount
     return True
示例#9
0
 def Do(self):
     sFit = Fit.getInstance()
     fit = sFit.getFit(self.fitID)
     srcCargo = next(
         (c for c in fit.cargo if c.itemID == self.srcCargoItemID), None)
     if srcCargo is None:
         return
     dstMod = fit.modules[self.dstModPosition]
     # Moving/copying charge from cargo to fit
     if srcCargo.item.isCharge and not dstMod.isEmpty:
         newCargoChargeItemID = dstMod.chargeID
         newCargoChargeAmount = dstMod.numCharges
         newModChargeItemID = self.srcCargoItemID
         newModChargeAmount = dstMod.getNumCharges(srcCargo.item)
         if newCargoChargeItemID == newModChargeItemID:
             return False
         commands = []
         if not self.copy:
             commands.append(
                 CalcRemoveCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=newModChargeItemID,
                                            amount=newModChargeAmount),
                                        commit=False))
         if newCargoChargeItemID is not None:
             commands.append(
                 CalcAddCargoCommand(fitID=self.fitID,
                                     cargoInfo=CargoInfo(
                                         itemID=newCargoChargeItemID,
                                         amount=newCargoChargeAmount),
                                     commit=False))
         commands.append(
             CalcChangeModuleChargesCommand(
                 fitID=self.fitID,
                 projected=False,
                 chargeMap={dstMod.modPosition: self.srcCargoItemID},
                 commit=False))
         success = self.internalHistory.submitBatch(*commands)
     # Moving/copying/replacing module
     elif srcCargo.item.isModule:
         dstModItemID = dstMod.itemID
         dstModSlot = dstMod.slot
         if self.srcCargoItemID == dstModItemID:
             return False
         # To keep all old item properties, copy them over from old module
         newModInfo = ModuleInfo.fromModule(dstMod)
         newModInfo.itemID = self.srcCargoItemID
         if dstMod.isEmpty:
             newCargoModItemID = None
             dstModChargeItemID = None
             dstModChargeAmount = None
         else:
             # We cannot put mutated items to cargo, so use unmutated item ID
             newCargoModItemID = ModuleInfo.fromModule(dstMod,
                                                       unmutate=True).itemID
             dstModChargeItemID = dstMod.chargeID
             dstModChargeAmount = dstMod.numCharges
         commands = []
         # Keep cargo only in case we were copying
         if not self.copy:
             commands.append(
                 CalcRemoveCargoCommand(fitID=self.fitID,
                                        cargoInfo=CargoInfo(
                                            itemID=self.srcCargoItemID,
                                            amount=1),
                                        commit=False))
         # Add item to cargo only if we copied/moved to non-empty slot
         if newCargoModItemID is not None:
             commands.append(
                 CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=newCargoModItemID,
                                         amount=1),
                     commit=False))
         cmdReplace = CalcReplaceLocalModuleCommand(
             fitID=self.fitID,
             position=self.dstModPosition,
             newModInfo=newModInfo,
             unloadInvalidCharges=True,
             commit=False)
         commands.append(cmdReplace)
         # Submit batch now because we need to have updated info on fit to keep going
         success = self.internalHistory.submitBatch(*commands)
         newMod = fit.modules[self.dstModPosition]
         # Bail if drag happened to slot to which module cannot be dragged, will undo later
         if newMod.slot != dstModSlot:
             success = False
         if success:
             # If we had to unload charge, add it to cargo
             if cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                 cmdAddCargoCharge = CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                         amount=dstModChargeAmount),
                     commit=False)
                 success = self.internalHistory.submit(cmdAddCargoCharge)
             # If we did not unload charge and there still was a charge, see if amount differs and process it
             elif not cmdReplace.unloadedCharge and dstModChargeItemID is not None:
                 # How many extra charges do we need to take from cargo
                 extraChargeAmount = newMod.numCharges - dstModChargeAmount
                 if extraChargeAmount > 0:
                     cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                             amount=extraChargeAmount),
                         commit=False)
                     # Do not check if operation was successful or not, we're okay if we have no such
                     # charges in cargo
                     self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                 elif extraChargeAmount < 0:
                     cmdAddCargoExtraCharge = CalcAddCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=dstModChargeItemID,
                                             amount=abs(extraChargeAmount)),
                         commit=False)
                     success = self.internalHistory.submit(
                         cmdAddCargoExtraCharge)
         if success:
             # Store info to properly send events later
             self.removedModItemID = dstModItemID
             self.addedModItemID = self.srcCargoItemID
         else:
             self.internalHistory.undoAll()
     else:
         return False
     eos.db.commit()
     sFit.recalc(fit)
     events = []
     if self.removedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='moddel',
                           typeID=self.removedModItemID))
     if self.addedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='modadd',
                           typeID=self.addedModItemID))
     if not events:
         events.append(GE.FitChanged(fitID=self.fitID))
     for event in events:
         wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
     return success
示例#10
0
 def Do(self):
     fit = Fit.getInstance().getFit(self.fitID)
     srcMod = fit.modules[self.srcModPosition]
     if srcMod.isEmpty:
         return False
     srcModItemID = srcMod.itemID
     dstCargo = next(
         (c for c in fit.cargo if c.itemID == self.dstCargoItemID), None)
     success = False
     # Attempt to swap if we're moving our module onto a module in the cargo hold
     if not self.copy and dstCargo is not None and dstCargo.item.isModule:
         if srcModItemID == self.dstCargoItemID:
             return False
         srcModSlot = srcMod.slot
         newModInfo = ModuleInfo.fromModule(srcMod, unmutate=True)
         newModInfo.itemID = self.dstCargoItemID
         srcModChargeItemID = srcMod.chargeID
         srcModChargeAmount = srcMod.numCharges
         commands = []
         commands.append(
             CalcRemoveCargoCommand(fitID=self.fitID,
                                    cargoInfo=CargoInfo(
                                        itemID=self.dstCargoItemID,
                                        amount=1),
                                    commit=False))
         commands.append(
             CalcAddCargoCommand(
                 fitID=self.fitID,
                 # We cannot put mutated items to cargo, so use unmutated item ID
                 cargoInfo=CargoInfo(itemID=ModuleInfo.fromModule(
                     srcMod, unmutate=True).itemID,
                                     amount=1),
                 commit=False))
         cmdReplace = CalcReplaceLocalModuleCommand(
             fitID=self.fitID,
             position=self.srcModPosition,
             newModInfo=newModInfo,
             unloadInvalidCharges=True,
             commit=False)
         commands.append(cmdReplace)
         # Submit batch now because we need to have updated info on fit to keep going
         success = self.internalHistory.submitBatch(*commands)
         newMod = fit.modules[self.srcModPosition]
         # Process charge changes if module is moved to proper slot
         if newMod.slot == srcModSlot:
             # If we had to unload charge, add it to cargo
             if cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                 cmdAddCargoCharge = CalcAddCargoCommand(
                     fitID=self.fitID,
                     cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                         amount=srcModChargeAmount),
                     commit=False)
                 success = self.internalHistory.submit(cmdAddCargoCharge)
             # If we did not unload charge and there still was a charge, see if amount differs and process it
             elif not cmdReplace.unloadedCharge and srcModChargeItemID is not None:
                 # How many extra charges do we need to take from cargo
                 extraChargeAmount = newMod.numCharges - srcModChargeAmount
                 if extraChargeAmount > 0:
                     cmdRemoveCargoExtraCharge = CalcRemoveCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                             amount=extraChargeAmount),
                         commit=False)
                     # Do not check if operation was successful or not, we're okay if we have no such
                     # charges in cargo
                     self.internalHistory.submit(cmdRemoveCargoExtraCharge)
                 elif extraChargeAmount < 0:
                     cmdAddCargoExtraCharge = CalcAddCargoCommand(
                         fitID=self.fitID,
                         cargoInfo=CargoInfo(itemID=srcModChargeItemID,
                                             amount=abs(extraChargeAmount)),
                         commit=False)
                     success = self.internalHistory.submit(
                         cmdAddCargoExtraCharge)
             if success:
                 # Store info to properly send events later
                 self.removedModItemID = srcModItemID
                 self.addedModItemID = self.dstCargoItemID
         # If drag happened to module which cannot be fit into current slot - consider it as failure
         else:
             success = False
         # And in case of any failures, cancel everything to try to do move instead
         if not success:
             self.internalHistory.undoAll()
     # Just dump module and its charges into cargo when copying or moving to cargo
     if not success:
         commands = []
         commands.append(
             CalcAddCargoCommand(fitID=self.fitID,
                                 cargoInfo=CargoInfo(
                                     itemID=ModuleInfo.fromModule(
                                         srcMod, unmutate=True).itemID,
                                     amount=1),
                                 commit=False))
         if srcMod.chargeID is not None:
             commands.append(
                 CalcAddCargoCommand(fitID=self.fitID,
                                     cargoInfo=CargoInfo(
                                         itemID=srcMod.chargeID,
                                         amount=srcMod.numCharges),
                                     commit=False))
         if not self.copy:
             commands.append(
                 CalcRemoveLocalModuleCommand(
                     fitID=self.fitID,
                     positions=[self.srcModPosition],
                     commit=False))
         success = self.internalHistory.submitBatch(*commands)
     eos.db.commit()
     Fit.getInstance().recalc(self.fitID)
     events = []
     if self.removedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='moddel',
                           typeID=self.removedModItemID))
     if self.addedModItemID is not None:
         events.append(
             GE.FitChanged(fitID=self.fitID,
                           action='modadd',
                           typeID=self.addedModItemID))
     if not events:
         events.append(GE.FitChanged(fitID=self.fitID))
     for event in events:
         wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event)
     return success
 def Do(self):
     cmd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))
     success = self.internalHistory.submit(cmd)
     wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
     return success