def getVehicleComponentsByType(vehicle, itemTypeIdx):
    def packModules(modules):
        if not isinstance(modules, list):
            modules = [modules]
        return ItemsCollection([(module.intCD, module) for module in modules
                                if module is not None])

    if itemTypeIdx == vehicles._CHASSIS:
        return packModules(vehicle.chassis)
    if itemTypeIdx == vehicles._TURRET:
        return packModules(vehicle.turret)
    if itemTypeIdx == vehicles._GUN:
        return packModules(vehicle.gun)
    if itemTypeIdx == vehicles._ENGINE:
        return packModules(vehicle.engine)
    if itemTypeIdx == vehicles._FUEL_TANK:
        return packModules(vehicle.fuelTank)
    if itemTypeIdx == vehicles._RADIO:
        return packModules(vehicle.radio)
    if itemTypeIdx == vehicles._TANKMAN:
        from gui.shared.gui_items.Tankman import TankmenCollection
        return TankmenCollection([(t.invID, t) for _, t in vehicle.crew])
    if itemTypeIdx == vehicles._OPTIONALDEVICE:
        return packModules(vehicle.optDevices.installed)
    if itemTypeIdx == vehicles._SHELL:
        return packModules(vehicle.shells.installed)
    if itemTypeIdx == vehicles._EQUIPMENT:
        return ItemsCollection([
            (eq.intCD, eq) for eq in vehicle.consumables.installed.getItems()
        ])
    return ItemsCollection()
Beispiel #2
0
def getVehicleComponentsByType(vehicle, itemTypeIdx):
    """
    Returns collection of vehicle's installed items.
    
    @param vehicle: target vehicle
    @param itemTypeIdx: items.ITEM_TYPE_NAMES index
    
    @return: ItemsCollection instance
    """
    def packModules(modules):
        """ Helper function to pack item ot items list to the collection """
        if not isinstance(modules, list):
            modules = [modules]
        return ItemsCollection([(module.intCD, module) for module in modules
                                if module is not None])

    if itemTypeIdx == vehicles._CHASSIS:
        return packModules(vehicle.chassis)
    if itemTypeIdx == vehicles._TURRET:
        return packModules(vehicle.turret)
    if itemTypeIdx == vehicles._GUN:
        return packModules(vehicle.gun)
    if itemTypeIdx == vehicles._ENGINE:
        return packModules(vehicle.engine)
    if itemTypeIdx == vehicles._FUEL_TANK:
        return packModules(vehicle.fuelTank)
    if itemTypeIdx == vehicles._RADIO:
        return packModules(vehicle.radio)
    if itemTypeIdx == vehicles._TANKMAN:
        from gui.shared.gui_items.Tankman import TankmenCollection
        return TankmenCollection([(t.invID, t) for slotIdx, t in vehicle.crew])
    if itemTypeIdx == vehicles._OPTIONALDEVICE:
        return packModules(vehicle.optDevices)
    if itemTypeIdx == vehicles._SHELL:
        return packModules(vehicle.shells)
    if itemTypeIdx == vehicles._EQUIPMENT:
        return ItemsCollection([
            (eq.intCD, eq)
            for eq in vehicle.equipment.regularConsumables.getInstalledItems()
        ])
    return ItemsCollection()