本文整理汇总了Python中shared_utils.findFirst函数的典型用法代码示例。如果您正苦于以下问题:Python findFirst函数的具体用法?Python findFirst怎么用?Python findFirst使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了findFirst函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getValue
def _getValue(self):
result = list()
shell = self._tooltip.item
configuration = self._tooltip.context.getParamsConfiguration(shell)
vehicle = configuration.vehicle
params = configuration.params
historicalBattleID = configuration.historicalBattleID
battle = g_eventsCache.getHistoricalBattles().get(historicalBattleID)
vDescr = vehicle.descriptor if vehicle is not None else None
vCompDescr = vehicle.intCD if vehicle is not None else None
if vehicle is not None and battle is not None and battle.canParticipateWith(vCompDescr):
vDescr = battle.getVehicleModifiedDescr(vehicle)
result.append([])
if params:
result = [ItemsParameters.g_instance.getParameters(shell.descriptor, vDescr)]
result.append([])
if vehicle is not None:
gun = VehicleItem(vDescr.gun)
vehicleShell = findFirst(lambda s: s.intCD == shell.intCD, vehicle.shells)
shellCount = vehicleShell.count if vehicleShell else getattr(shell, 'count', 0)
if battle is not None and battle.canParticipateWith(vCompDescr):
_, shellCount = findFirst(lambda x: x[0].intCD == shell.intCD, battle.getShellsLayout(vCompDescr), (None, 0))
result[-1].append({'label': 'ammo',
'current': shellCount,
'total': gun.descriptor['maxAmmo']})
return result
示例2: parseTag
def parseTag(self, pyGlooxTag):
igrID, igrRoomID, gameHost, arenaLabel = (0, 0, '', '')
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='igr-id')))
if tag:
igrID = tag.getCData()
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='igr-room-id')))
if tag:
igrRoomID = tag.getCData()
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='game-host')))
if tag:
gameHost = tag.getCData()
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='arena-label')))
if tag:
arenaLabel = tag.getCData()
return makeClientInfo(igrID, igrRoomID, gameHost, arenaLabel)
示例3: onUnitSettingChanged
def onUnitSettingChanged(self, opCode, value):
if opCode == UNIT_OP.CHANGE_FALLOUT_TYPE:
rosterType = self.unitFunctional.getRosterType()
self.__battleType, _ = findFirst(lambda (k, v): v == rosterType, FALLOUT_QUEUE_TYPE_TO_ROSTER.iteritems(), (QUEUE_TYPE.UNKNOWN, None))
self.__updateVehicles()
self._proxy.onSettingsChanged()
return
示例4: __onItemsChanged
def __onItemsChanged(self, updateReason, invalidItems):
vehiclesDiff = invalidItems.get(GUI_ITEM_TYPE.VEHICLE)
if vehiclesDiff is not None:
falloutVehicle = findFirst(lambda v: v.intCD in vehiclesDiff, getFalloutCtrl().getSelectedVehicles())
if falloutVehicle is not None:
self.__updatePrebattleControls()
return
示例5: cancel
def cancel(self):
item = findFirst(lambda item: item.getStage() == EQUIPMENT_STAGES.PREPARING, self._equipments.itervalues())
if item is not None:
item.deactivate()
return True
else:
return False
示例6: validateVehicles
def validateVehicles(self, vInfos, flags):
from gui.shared.gui_items.Vehicle import Vehicle
if not findFirst(lambda v: not v.isEmpty(), vInfos, False):
return (False, UNIT_RESTRICTION.FALLOUT_VEHICLE_MIN)
else:
for vInfo in vInfos:
vehicle = vInfo.getVehicle()
if vehicle is None:
continue
isReadyToBattle = vehicle.isReadyToPrebattle(checkForRent=not flags.isInPreArena())
if vehicle and not isReadyToBattle:
if vehicle.isBroken:
return (False, UNIT_RESTRICTION.VEHICLE_BROKEN)
if not vehicle.isCrewFull:
return (False, UNIT_RESTRICTION.VEHICLE_CREW_NOT_FULL)
if not flags.isInPreArena() and vehicle.rentalIsOver:
return (False, UNIT_RESTRICTION.VEHICLE_RENT_IS_OVER)
if vehicle.isInBattle:
return (False, UNIT_RESTRICTION.VEHICLE_IS_IN_BATTLE)
isGroupReady, state = vehicle.isGroupReady()
if not isGroupReady:
if state == Vehicle.VEHICLE_STATE.FALLOUT_REQUIRED:
return (False, UNIT_RESTRICTION.FALLOUT_VEHICLE_LEVEL_REQUIRED)
if state == Vehicle.VEHICLE_STATE.FALLOUT_MIN:
return (False, UNIT_RESTRICTION.FALLOUT_VEHICLE_MIN)
if state == Vehicle.VEHICLE_STATE.FALLOUT_MAX:
return (False, UNIT_RESTRICTION.FALLOUT_VEHICLE_MAX)
if state == Vehicle.VEHICLE_STATE.FALLOUT_BROKEN:
return (False, UNIT_RESTRICTION.FALLOUT_VEHICLE_BROKEN)
return (False, UNIT_RESTRICTION.VEHICLE_NOT_VALID)
return (True, UNIT_RESTRICTION.UNDEFINED)
示例7: __updateUsersData
def __updateUsersData(self, userDBIDs):
diff = []
userGetter = storage_getter('users')().getUser
colorGetter = g_settings.getColorScheme('rosters').getColors
for userDBID in userDBIDs:
data = findFirst(lambda d: d['creator'].get('dbID') == userDBID, self.collection)
if data is not None:
clubDBID = data['cfdUnitID']
try:
index = self.mapping[clubDBID]
item = self.collection[index]
except (KeyError, IndexError):
LOG_ERROR('Item not found', clubDBID)
continue
creator = userGetter(userDBID)
creatorVO = makeUserVO(creator, colorGetter)
creatorName = creator.getName()
item.update({'creatorName': creatorName,
'rating': self.getGuiUserRating(userDBID)})
if creator.hasValidName():
item['creator'] = creatorVO
diff.append(index)
if len(diff):
self.updateItems(diff)
return
示例8: isTransportationAvailable
def isTransportationAvailable(self):
forImport = self.getBuildingsAvailableForImport()
def filter(item):
return len(self.getBuildingsAvailableForExport(item)) > 0
return findFirst(filter, forImport) is not None
示例9: itemOnVehicleComparator
def itemOnVehicleComparator(vehicle, item):
vehicleParams = params.VehicleParams(vehicle).getParamsDict()
withItemParams = vehicleParams
mayInstall, reason = vehicle.descriptor.mayInstallComponent(item.intCD)
if item.itemTypeID == ITEM_TYPES.vehicleTurret:
mayInstall, reason = vehicle.descriptor.mayInstallTurret(item.intCD, vehicle.gun.intCD)
if not mayInstall:
properGun = findFirst(lambda gun: vehicle.descriptor.mayInstallComponent(gun['compactDescr'])[0], item.descriptor['guns'])
if properGun is not None:
removedModules = vehicle.descriptor.installTurret(item.intCD, properGun['compactDescr'])
withItemParams = params.VehicleParams(vehicle).getParamsDict()
vehicle.descriptor.installTurret(*removedModules)
else:
LOG_ERROR('not possible to install turret', item, reason)
else:
removedModules = vehicle.descriptor.installTurret(item.intCD, vehicle.gun.intCD)
withItemParams = params.VehicleParams(vehicle).getParamsDict()
vehicle.descriptor.installTurret(*removedModules)
elif not mayInstall and reason == 'not for current vehicle' and item.itemTypeID == ITEM_TYPES.vehicleGun:
turret = g_paramsCache.getPrecachedParameters(item.intCD).getTurretsForVehicle(vehicle.intCD)[0]
removedModules = vehicle.descriptor.installTurret(turret, vehicle.gun.intCD)
vehicleParams = params.VehicleParams(vehicle).getParamsDict()
vehicle.descriptor.installTurret(turret, item.intCD)
withItemParams = params.VehicleParams(vehicle).getParamsDict()
vehicle.descriptor.installTurret(*removedModules)
else:
removedModule = vehicle.descriptor.installComponent(item.intCD)
withItemParams = params.VehicleParams(vehicle).getParamsDict()
vehicle.descriptor.installComponent(removedModule[0])
return VehiclesComparator(withItemParams, vehicleParams)
示例10: updateList
def updateList(self):
directions = []
openedDirectionsCount = len(self.fortCtrl.getFort().getOpenedDirections())
fightsForDirections = self.fortCtrl.getFort().getDirectionsInBattle()
for direction in range(1, g_fortCache.maxDirections + 1):
buildings = self.fortCtrl.getFort().getBuildingsByDirections().get(direction)
isOpened = buildings is not None
inBattle = direction in fightsForDirections
canBeClosed = isOpened and not inBattle and findFirst(lambda b: b is not None, buildings) is None
buildingsData = []
if isOpened:
for building in buildings:
data = None
if building is not None:
uid = self.getBuildingUIDbyID(building.typeID)
data = {'uid': uid,
'progress': self._getProgress(building.typeID, building.level),
'toolTipData': [i18n.makeString('#fortifications:Buildings/buildingName/%s' % uid), self.getCommonBuildTooltipData(building)],
'iconSource': FortViewHelper.getSmallIconSource(uid, building.level)}
buildingsData.append(data)
directions.append({'uid': direction,
'fullName': i18n.makeString('#fortifications:General/direction', value=i18n.makeString('#fortifications:General/directionName%d' % direction)),
'isOpened': isOpened,
'canBeClosed': canBeClosed,
'closeButtonVisible': isOpened and openedDirectionsCount > 1,
'buildings': buildingsData})
self.as_setDirectionsS(directions)
return
示例11: getShellsLayoutPrice
def getShellsLayoutPrice(self):
"""
@return: price that should be paid to fill layout
"""
goldPrice = 0
creditsPrice = 0
if self.shellsLayout is None:
return (creditsPrice, goldPrice)
else:
for shellCompDescr, count, isBoughtForCredits in LayoutIterator(self.shellsLayout):
if not shellCompDescr or not count:
continue
shell = g_itemsCache.items.getItemByCD(int(shellCompDescr))
vehShell = findFirst(lambda s: s.intCD == shellCompDescr, self.vehicle.shells)
vehCount = vehShell.count if vehShell is not None else 0
buyCount = count - shell.inventoryCount - vehCount
if buyCount:
if shell.buyPrice[1] and not isBoughtForCredits:
goldPrice += shell.buyPrice[1] * buyCount
elif shell.buyPrice[1] and isBoughtForCredits:
creditsPrice += shell.buyPrice[1] * buyCount * g_itemsCache.items.shop.exchangeRateForShellsAndEqs
elif shell.buyPrice[0]:
creditsPrice += shell.buyPrice[0] * buyCount
return (creditsPrice, goldPrice)
示例12: canSelectVehicle
def canSelectVehicle(self, vehicle):
if not self.isSelected():
return (False, '')
cfg = self.getConfig()
if findFirst(lambda v: v.level == cfg.vehicleLevelRequired, self.getSelectedVehicles()) is None and vehicle.level != cfg.vehicleLevelRequired:
return (False, i18n.makeString(FALLOUT.TANKCAROUSELSLOT_SELECTIONBUTTONTOOLTIP, requiredLevel=int2roman(cfg.vehicleLevelRequired), level=toRomanRangeString(list(cfg.allowedLevels - {cfg.vehicleLevelRequired}), 1)))
return (True, '')
示例13: setPlayerAssistResult
def setPlayerAssistResult(self, assistType, details):
if not self.__isPEEnabled:
return
else:
eventID = None
series = 1
if assistType == _SET.SPOTTED:
eventID = _EVENT_ID.PLAYER_SPOTTED_ENEMY
series = self.__getSeries(details)
elif assistType in (_SET.RADIO_HIT_ASSIST, _SET.RADIO_KILL_ASSIST, _SET.TRACK_ASSIST):
if assistType == _SET.TRACK_ASSIST:
series = self.__getSeries(details)
eventID = _EVENT_ID.PLAYER_ASSIST_TO_KILL_ENEMY
elif assistType == _SET.BASE_CAPTURE_POINTS:
eventID = _EVENT_ID.PLAYER_CAPTURED_BASE
elif assistType == _SET.BASE_CAPTURE_DROPPED:
eventID = _EVENT_ID.PLAYER_DROPPED_CAPTURE
elif assistType == _SET.TANKING:
eventID = _EVENT_ID.PLAYER_USED_ARMOR
series = findFirst(None, details, default=1)
else:
LOG_CODEPOINT_WARNING(assistType)
if eventID:
self.__pushPlayerEvent(eventID, series)
return
示例14: parseTag
def parseTag(self, pyGlooxTag):
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='status')))
code = self.getDefaultData()
if tag is not None:
found = tag.findAttribute('code')
if found and found.isdigit():
code = int(found)
return code
示例15: parseTag
def parseTag(self, pyGlooxTag):
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='count')))
if tag:
count = int(tag.getCData())
else:
count = 0
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='first')))
if tag:
first = self._converter(tag.getCData())
else:
first = None
tag = findFirst(None, pyGlooxTag.filterXPath(self.getXPath(suffix='last')))
if tag:
last = self._converter(tag.getCData())
else:
last = None
return (count, first, last)