def Do(self): pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) mainMod = fit.modules[self.mainPosition] if mainMod.isEmpty: return False positions = [pos for pos in self.positions if not fit.modules[pos].isEmpty] if self.mainPosition not in positions: positions.append(self.mainPosition) self.savedStates = {pos: fit.modules[pos].state for pos in positions} changed = False mainProposedState = Module.getProposedState(mainMod, self.click) pyfalog.debug('Attempting to change modules to {}'.format(mainProposedState)) if mainProposedState != mainMod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format(mainMod, mainProposedState, self.fitID)) mainMod.state = mainProposedState changed = True for position in [pos for pos in positions if pos != self.mainPosition]: mod = fit.modules[position] proposedState = Module.getProposedState(mod, self.click, mainProposedState) if proposedState != mod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format(mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, mainMod) return True
def Do(self): pyfalog.debug('Doing change of local module states at position {}/{} to click {} on fit {}'.format(self.mainPosition, self.positions, self.click, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) mainMod = fit.modules[self.mainPosition] if mainMod.isEmpty: return False positions = [pos for pos in self.positions if not fit.modules[pos].isEmpty] self.savedStates = {pos: fit.modules[pos].state for pos in positions} changed = False mainProposedState = Module.getProposedState(mainMod, self.click) pyfalog.debug('Attempting to change modules to {}'.format(mainProposedState)) if mainProposedState != mainMod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format(mainMod, mainProposedState, self.fitID)) mainMod.state = mainProposedState changed = True for position in [pos for pos in positions if pos != self.mainPosition]: mod = fit.modules[position] proposedState = Module.getProposedState(mod, self.click, mainProposedState) if proposedState != mod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format(mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False # Need to flush because checkStates sometimes relies on module->fit # relationship via .owner attribute, which is handled by SQLAlchemy eos.db.flush() sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, mainMod) eos.db.commit() return True
def Do(self): pyfalog.debug( 'Doing change of projected module state at positions {} to state {} on fit {}' .format(self.positions, self.proposedState, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) self.savedStates = { pos: fit.projectedModules[pos].state for pos in self.positions } changed = False for position in self.positions: mod = fit.projectedModules[position] proposedState = Module.getProposedState(mod, None, self.proposedState) if proposedState != mod.state: pyfalog.debug( 'Toggle projected {} state: {} for fit ID: {}'.format( mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, None) return True
def Do(self): pyfalog.debug( 'Doing change of projected module state at positions {} to state {} on fit {}' .format(self.positions, self.proposedState, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) self.savedStates = { pos: fit.projectedModules[pos].state for pos in self.positions } changed = False for position in self.positions: mod = fit.projectedModules[position] proposedState = Module.getProposedState(mod, None, self.proposedState) if proposedState != mod.state: pyfalog.debug( 'Toggle projected {} state: {} for fit ID: {}'.format( mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False # Need to flush because checkStates sometimes relies on module->fit # relationship via .owner attribute, which is handled by SQLAlchemy eos.db.flush() sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, None) if self.commit: eos.db.commit() return True
def __init__(self, fitID, mainItem, items, click): wx.Command.__init__(self, True, 'Change Projected Item States') self.internalHistory = InternalCommandHistory() self.fitID = fitID self.pModPositions = [] self.pDroneItemIDs = [] self.pFighterPositions = [] self.pFitIDs = [] fit = Fit.getInstance().getFit(fitID) for item in items: if isinstance(item, EosModule): if item in fit.projectedModules: self.pModPositions.append(fit.projectedModules.index(item)) elif isinstance(item, EosDrone): self.pDroneItemIDs.append(item.itemID) elif isinstance(item, EosFighter): if item in fit.projectedFighters: self.pFighterPositions.append(fit.projectedFighters.index(item)) elif isinstance(item, EosFit): self.pFitIDs.append(item.ID) self.proposedState = None if click == 'right' and isinstance(mainItem, EosModule): self.proposedState = 'overheat' elif click == 'left': if isinstance(mainItem, EosModule): modProposedState = EosModule.getProposedState(mainItem, click) self.proposedState = 'inactive' if modProposedState == FittingModuleState.OFFLINE else 'active' elif isinstance(mainItem, EosDrone): self.proposedState = 'active' if mainItem.amountActive == 0 else 'inactive' elif isinstance(mainItem, EosFighter): self.proposedState = 'inactive' if mainItem.active else 'active' elif isinstance(mainItem, EosFit): projectionInfo = mainItem.getProjectionInfo(self.fitID) if projectionInfo is not None: self.proposedState = 'inactive' if projectionInfo.active else 'active'
def Do(self): fit = eos.db.getFit(self.fitID) sFit = Fit.getInstance() baseMod = fit.modules[self.baseModPos] # make sure positions only include non-empty positions self.positions = [ x for x in self.positions if not fit.modules[x].isEmpty ] for x in self.positions: self.old_states[x] = fit.modules[x].state proposedState = Module.getProposedState(baseMod, self.click) pyfalog.debug("Attempting to change modules to {}", proposedState) if proposedState != baseMod.state: pyfalog.debug("Toggle {} state: {} for fit ID: {}", baseMod, proposedState, self.fitID) self.changed = True baseMod.state = proposedState for i in [x for x in self.positions if x != self.baseModPos ]: # dont consider base module position mod = fit.modules[i] p = Module.getProposedState(mod, self.click, proposedState) mod.state = p if p != mod.state: pyfalog.debug("Toggle {} state: {} for fit ID: {}", mod, p, self.fitID) self.changed = True # if we haven't change the state (eg, overheat -> overheat), simply fail the command if self.changed: eos.db.commit() # 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 sFit.checkStates(fit, baseMod) # self.checkStates(fit, base) return True return False
def Do(self): pyfalog.debug( 'Doing change of local module states at position {}/{} to click {} on fit {}' .format(self.mainPosition, self.positions, self.click, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) mainMod = fit.modules[self.mainPosition] if mainMod.isEmpty: return False positions = [ pos for pos in self.positions if not fit.modules[pos].isEmpty ] if self.mainPosition not in positions: positions.append(self.mainPosition) self.savedStates = {pos: fit.modules[pos].state for pos in positions} changed = False mainProposedState = Module.getProposedState(mainMod, self.click) pyfalog.debug( 'Attempting to change modules to {}'.format(mainProposedState)) if mainProposedState != mainMod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format( mainMod, mainProposedState, self.fitID)) mainMod.state = mainProposedState changed = True for position in [pos for pos in positions if pos != self.mainPosition]: mod = fit.modules[position] proposedState = Module.getProposedState(mod, self.click, mainProposedState) if proposedState != mod.state: pyfalog.debug('Toggle {} state: {} for fit ID: {}'.format( mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, mainMod) eos.db.commit() return True
def toggleModulesState(self, fitID, base, modules, click): pyfalog.debug("Toggle module state for fit ID: {0}", fitID) changed = False proposedState = es_Module.getProposedState(base, click) if proposedState != base.state: changed = True base.state = proposedState for mod in modules: if mod != base: p = es_Module.getProposedState(mod, click, proposedState) mod.state = p if p != mod.state: changed = True if changed: eos.db.commit() fit = eos.db.getFit(fitID) # 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, base)
def Do(self): pyfalog.debug('Doing change of projected module state at positions {} to state {} on fit {}'.format( self.positions, self.proposedState, self.fitID)) sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) self.savedStates = {pos: fit.projectedModules[pos].state for pos in self.positions} changed = False for position in self.positions: mod = fit.projectedModules[position] proposedState = Module.getProposedState(mod, None, self.proposedState) if proposedState != mod.state: pyfalog.debug('Toggle projected {} state: {} for fit ID: {}'.format(mod, proposedState, self.fitID)) mod.state = proposedState changed = True if not changed: return False sFit.recalc(fit) self.savedStateCheckChanges = sFit.checkStates(fit, None) return True
def toggleProjected(self, fitID, thing, click): pyfalog.debug("Toggling projected on fit ({0}) for: {1}", fitID, thing) fit = eos.db.getFit(fitID) if isinstance(thing, es_Drone): if thing.amountActive == 0 and thing.canBeApplied(fit): thing.amountActive = thing.amount else: thing.amountActive = 0 elif isinstance(thing, es_Fighter): thing.active = not thing.active elif isinstance(thing, es_Module): thing.state = es_Module.getProposedState(thing, click) if not thing.canHaveState(thing.state, fit): thing.state = State.OFFLINE elif isinstance(thing, FitType): projectionInfo = thing.getProjectionInfo(fitID) if projectionInfo: projectionInfo.active = not projectionInfo.active eos.db.commit() self.recalc(fit)