def Do(self): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) try: mod = fit.modules[self.position] except IndexError: return False if mod.isEmpty: return False if not mod.isMutated: return False cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=self.position, newModInfo=ModuleInfo( itemID=mod.baseItemID, chargeID=mod.chargeID, state=mod.state, spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) success = self.internalHistory.submit(cmd) if cmd.needsGuiRecalc: eos.db.flush() sFit.recalc(self.fitID) sFit.fill(self.fitID) eos.db.commit() wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID, ))) return success
def Do(self): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) mod = fit.modules[self.position] if mod.isEmpty: return False if mod.isMutated: return False cmd = CalcReplaceLocalModuleCommand( fitID=self.fitID, position=self.position, newModInfo=ModuleInfo(itemID=self.itemID, baseItemID=mod.item.ID, mutaplasmidID=self.mutaplasmidID, mutations={}, chargeID=mod.chargeID, state=mod.state, spoolType=mod.spoolType, spoolAmount=mod.spoolAmount)) success = self.internalHistory.submit(cmd) sFit.recalc(self.fitID) sFit.fill(self.fitID) wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return success
def Do(self): results = [] needRecalc = None for position in self.positions: cmd = CalcReplaceLocalModuleCommand( fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID)) results.append(self.internalHistory.submit(cmd)) # Last command decides if we need it or not needRecalc = cmd.needsGuiRecalc success = any(results) Market.getInstance().storeRecentlyUsed(self.itemID) sFit = Fit.getInstance() if needRecalc: eos.db.flush() sFit.recalc(self.fitID) self.savedRemovedDummies = sFit.fill(self.fitID) eos.db.commit() wx.PostEvent( gui.mainFrame.MainFrame.getInstance(), GE.FitChanged( fitIDs=(self.fitID, ), action='modadd', typeID=self.itemID) if success else GE.FitChanged(fitIDs=(self.fitID, ))) return success
def Do(self): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) oldModMap = self._getPositionMap(fit) results = [] self.replacedItemIDs = set() lastSuccessfulCmd = None for position in self.positions: module = fit.modules[position] if module.isEmpty: continue if module.itemID == self.newItemID: continue info = ModuleInfo.fromModule(module) info.itemID = self.newItemID cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=info, unloadInvalidCharges=True) result = self.internalHistory.submit(cmd) results.append(result) if result: self.replacedItemIDs.add(module.itemID) lastSuccessfulCmd = cmd success = any(results) if lastSuccessfulCmd is not None and lastSuccessfulCmd.needsGuiRecalc: eos.db.flush() sFit.recalc(self.fitID) self.savedRemovedDummies = sFit.fill(self.fitID) eos.db.commit() newModMap = self._getPositionMap(fit) events = [] if success and self.replacedItemIDs: events.append( GE.FitChanged(fitIDs=(self.fitID, ), action='moddel', typeID=self.replacedItemIDs)) if success: events.append( GE.FitChanged(fitIDs=(self.fitID, ), action='modadd', typeID=self.newItemID)) if not events: events.append(GE.FitChanged(fitIDs=(self.fitID, ))) if success: for position in self.positions: oldMod = oldModMap.get(position) newMod = newModMap.get(position) if oldMod is not newMod: events.append(GE.ItemChangedInplace(old=oldMod, new=newMod)) for event in events: wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event) return success
def Do(self): results = [] for position in self.positions: cmd = CalcReplaceLocalModuleCommand( fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID), commit=False) results.append(self.internalHistory.submit(cmd)) success = any(results) eos.db.commit() Fit.getInstance().recalc(self.fitID) wx.PostEvent( gui.mainFrame.MainFrame.getInstance(), GE.FitChanged( fitID=self.fitID, action='modadd', typeID=self.itemID) if success else GE.FitChanged(fitID=self.fitID)) return success
def Do(self): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) commands = [] self.replacedItemIDs = set() for position in self.positions: module = fit.modules[position] if module.isEmpty: continue if module.itemID == self.newItemID: continue self.replacedItemIDs.add(module.itemID) info = ModuleInfo.fromModule(module) info.itemID = self.newItemID cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=info, unloadInvalidCharges=True) commands.append(cmd) if not commands: return False success = self.internalHistory.submitBatch(*commands) if commands[-1].needsGuiRecalc: eos.db.flush() sFit.recalc(self.fitID) self.savedRemovedDummies = sFit.fill(self.fitID) eos.db.commit() events = [] if success and self.replacedItemIDs: events.append( GE.FitChanged(fitIDs=(self.fitID, ), action='moddel', typeID=self.replacedItemIDs)) if success: events.append( GE.FitChanged(fitIDs=(self.fitID, ), action='modadd', typeID=self.newItemID)) if not events: events.append(GE.FitChanged(fitIDs=(self.fitID, ))) for event in events: wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event) return success
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
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