Пример #1
0
    def getImageId(self, stuff):
        if isinstance(stuff, BaseWrapper):
            stuff = stuff.item

        if isinstance(stuff, Drone):
            return -1
        elif isinstance(stuff, Fit):
            return self.shipImage
        elif isinstance(stuff, Rack):
            return -1
        elif isinstance(stuff, Implant):
            if stuff.character:  # if it has a character as it's parent
                return self.fittingView.imageList.GetImageIndex(
                    "character_small", "gui")
            else:
                return self.shipImage
        elif isinstance(stuff, Module):
            if stuff.isEmpty:
                return self.fittingView.imageList.GetImageIndex(
                    "slot_%s_small" % FittingSlot(stuff.slot).name.lower(),
                    "gui")
            else:
                return self.loadIconFile(stuff.item.iconID or "")
        elif isinstance(stuff, TargetProfile):
            return self.fittingView.imageList.GetImageIndex(
                "target_small", "gui")

        item = getattr(stuff, "item", stuff)
        return self.loadIconFile(item.iconID)
Пример #2
0
def exportModules(modules, options, mutaData=None):
    if mutaData is None:
        mutaData = MutationExportData()
    modsBySlotType = {}
    for module in modules:
        modsBySlotType.setdefault(module.slot, []).append(module)
    modSection = []
    for slotType in SLOT_ORDER:
        rackLines = []
        rackModules = modsBySlotType.get(slotType, ())
        for module in rackModules:
            if module.item:
                # if module was mutated, use base item name for export
                if module.isMutated:
                    modName = module.baseItem.typeName
                else:
                    modName = module.item.typeName
                if module.isMutated and options[PortEftOptions.MUTATIONS]:
                    mutaData.mutants[mutaData.reference] = module
                    mutationSuffix = ' [{}]'.format(mutaData.reference)
                    mutaData.reference += 1
                else:
                    mutationSuffix = ''
                modOfflineSuffix = ' {}'.format(OFFLINE_SUFFIX) if module.state == FittingModuleState.OFFLINE else ''
                if module.charge and options[PortEftOptions.LOADED_CHARGES]:
                    rackLines.append('{}, {}{}{}'.format(
                        modName, module.charge.typeName, modOfflineSuffix, mutationSuffix))
                else:
                    rackLines.append('{}{}{}'.format(modName, modOfflineSuffix, mutationSuffix))
            else:
                rackLines.append('[Empty {} slot]'.format(
                    FittingSlot(slotType).name.capitalize() if slotType is not None else ''))
        if rackLines:
            modSection.append('\n'.join(rackLines))
    return '\n\n'.join(modSection)
Пример #3
0
def exportEft(fit, options, callback):
    # EFT formatted export is split in several sections, each section is
    # separated from another using 2 blank lines. Sections might have several
    # sub-sections, which are separated by 1 blank line
    sections = []

    header = '[{}, {}]'.format(fit.ship.item.typeName, fit.name)

    # Section 1: modules, rigs, subsystems, services
    modsBySlotType = {}
    for module in fit.modules:
        modsBySlotType.setdefault(module.slot, []).append(module)
    modSection = []

    mutants = {}  # Format: {reference number: module}
    mutantReference = 1
    for slotType in SLOT_ORDER:
        rackLines = []
        modules = modsBySlotType.get(slotType, ())
        for module in modules:
            if module.item:
                # if module was mutated, use base item name for export
                if module.isMutated:
                    modName = module.baseItem.typeName
                else:
                    modName = module.item.typeName
                if module.isMutated and options[PortEftOptions.MUTATIONS]:
                    mutants[mutantReference] = module
                    mutationSuffix = ' [{}]'.format(mutantReference)
                    mutantReference += 1
                else:
                    mutationSuffix = ''
                modOfflineSuffix = ' {}'.format(
                    OFFLINE_SUFFIX
                ) if module.state == FittingModuleState.OFFLINE else ''
                if module.charge and options[PortEftOptions.LOADED_CHARGES]:
                    rackLines.append('{}, {}{}{}'.format(
                        modName, module.charge.typeName, modOfflineSuffix,
                        mutationSuffix))
                else:
                    rackLines.append('{}{}{}'.format(modName, modOfflineSuffix,
                                                     mutationSuffix))
            else:
                rackLines.append('[Empty {} slot]'.format(
                    FittingSlot(slotType).name.capitalize(
                    ) if slotType is not None else ''))
        if rackLines:
            modSection.append('\n'.join(rackLines))
    if modSection:
        sections.append('\n\n'.join(modSection))

    # Section 2: drones, fighters
    minionSection = []
    droneExport = exportDrones(fit.drones)
    if droneExport:
        minionSection.append(droneExport)
    fighterExport = exportFighters(fit.fighters)
    if fighterExport:
        minionSection.append(fighterExport)
    if minionSection:
        sections.append('\n\n'.join(minionSection))

    # Section 3: implants, boosters
    charSection = []
    if options[PortEftOptions.IMPLANTS]:
        implantExport = exportImplants(fit.implants)
        if implantExport:
            charSection.append(implantExport)
    if options[PortEftOptions.BOOSTERS]:
        boosterExport = exportBoosters(fit.boosters)
        if boosterExport:
            charSection.append(boosterExport)
    if charSection:
        sections.append('\n\n'.join(charSection))

    # Section 4: cargo
    if options[PortEftOptions.CARGO]:
        cargoExport = exportCargo(fit.cargo)
        if cargoExport:
            sections.append(cargoExport)

    # Section 5: mutated modules' details
    mutationLines = []
    if mutants and options[PortEftOptions.MUTATIONS]:
        for mutantReference in sorted(mutants):
            mutant = mutants[mutantReference]
            mutationLines.append(
                renderMutant(mutant,
                             firstPrefix='[{}] '.format(mutantReference),
                             prefix='  '))
    if mutationLines:
        sections.append('\n'.join(mutationLines))

    text = '{}\n\n{}'.format(header, '\n\n\n'.join(sections))

    if callback:
        callback(text)
    else:
        return text
Пример #4
0
    def getText(self, stuff):
        if isinstance(stuff, BaseWrapper):
            stuff = stuff.item

        if isinstance(stuff, Drone):
            return "%dx %s" % (stuff.amount, stuff.item.name)
        elif isinstance(stuff, Fighter):
            return "%d/%d %s" % \
                   (stuff.amount, stuff.getModifiedItemAttr("fighterSquadronMaxSize"), stuff.item.name)
        elif isinstance(stuff, Cargo):
            if stuff.item.group.name in ("Cargo Container",
                                         "Secure Cargo Container",
                                         "Audit Log Secure Container",
                                         "Freight Container"):
                capacity = stuff.item.getAttribute('capacity')
                if capacity:
                    return "{:d}x {} ({} m\u00B3)".format(
                        stuff.amount, stuff.item.name,
                        formatAmount(capacity, 3, 0, 6))
            return "{:d}x {}".format(stuff.amount, stuff.item.name)
        elif isinstance(stuff, Fit):
            if self.projectedView:
                # we need a little more information for the projected view
                fitID = self.mainFrame.getActiveFit()
                info = stuff.getProjectionInfo(fitID)

                if info:
                    return "%dx %s (%s)" % (stuff.getProjectionInfo(
                        fitID).amount, stuff.name, stuff.ship.item.name)

                pyfalog.warning(
                    "Projected View trying to display things that aren't there. stuff: {}, info: {}",
                    repr(stuff), info)
                return "<unknown>"
            else:
                return "%s (%s)" % (stuff.name, stuff.ship.item.name)
        elif isinstance(stuff, FitLite):
            return "{} ({})".format(stuff.name, stuff.shipName)
        elif isinstance(stuff, Rack):
            if FitSvc.getInstance().serviceFittingOptions["rackLabels"]:
                if stuff.slot == FittingSlot.MODE:
                    return '─ Tactical Mode ─'
                else:
                    return '─ {} {} Slot{}─'.format(
                        stuff.num,
                        FittingSlot(stuff.slot).name.capitalize(),
                        '' if stuff.num == 1 else 's')
            else:
                return ""
        elif isinstance(stuff, Module):
            if self.projectedView:
                # check for projected abyssal name
                name_check = stuff.item.name[0:-2]
                type = AddEnvironmentEffect.abyssal_mapping.get(
                    name_check, None)
                if type:
                    sMkt = Market.getInstance()
                    type = sMkt.getItem(type)
                    return "{} {}".format(type.name, stuff.item.name[-1:])

            if stuff.isEmpty:
                return "%s Slot" % FittingSlot(stuff.slot).name.capitalize()
            else:
                return stuff.item.name
        elif isinstance(stuff, Implant):
            return stuff.item.name
        elif isinstance(stuff, TargetProfile):
            return stuff.shortName
        else:
            item = getattr(stuff, "item", stuff)

            if FitSvc.getInstance(
            ).serviceFittingOptions["showMarketShortcuts"]:
                marketShortcut = getattr(item, "marketShortcut", None)

                if marketShortcut:
                    # use unicode subscript to display shortcut value
                    shortcut = chr(marketShortcut + 8320) + " "
                    del item.marketShortcut
                    return shortcut + item.name

            return item.name
Пример #5
0
def exportXml(fits, iportuser, callback):
    doc = xml.dom.minidom.Document()
    fittings = doc.createElement("fittings")
    # fit count
    fit_count = len(fits)
    fittings.setAttribute("count", "%s" % fit_count)
    doc.appendChild(fittings)

    for i, fit in enumerate(fits):
        try:
            fitting = doc.createElement("fitting")
            fitting.setAttribute("name", fit.name)
            fittings.appendChild(fitting)
            description = doc.createElement("description")
            # -- 170327 Ignored description --
            try:
                notes = fit.notes  # unicode

                if notes:
                    notes = notes[:397] + '...' if len(notes) > 400 else notes

                description.setAttribute(
                    "value",
                    re.sub("(\r|\n|\r\n)+", "<br>", notes)
                    if notes is not None else "")
            except Exception as e:
                pyfalog.warning("read description is failed, msg=%s\n" %
                                e.args)

            fitting.appendChild(description)
            shipType = doc.createElement("shipType")
            shipType.setAttribute("value", fit.ship.name)
            fitting.appendChild(shipType)

            charges = {}
            slotNum = {}
            for module in fit.modules:
                if module.isEmpty:
                    continue

                slot = module.slot

                if slot == FittingSlot.SUBSYSTEM:
                    # Order of subsystem matters based on this attr. See GH issue #130
                    slotId = module.getModifiedItemAttr("subSystemSlot") - 125
                else:
                    if slot not in slotNum:
                        slotNum[slot] = 0

                    slotId = slotNum[slot]
                    slotNum[slot] += 1

                hardware = doc.createElement("hardware")
                hardware.setAttribute("type", module.item.name)
                slotName = FittingSlot(slot).name.lower()
                slotName = slotName if slotName != "high" else "hi"
                hardware.setAttribute("slot",
                                      "%s slot %d" % (slotName, slotId))
                fitting.appendChild(hardware)

                if module.charge:
                    if module.charge.name not in charges:
                        charges[module.charge.name] = 0
                    # `or 1` because some charges (ie scripts) are without qty
                    charges[module.charge.name] += module.numCharges or 1

            for drone in fit.drones:
                hardware = doc.createElement("hardware")
                hardware.setAttribute("qty", "%d" % drone.amount)
                hardware.setAttribute("slot", "drone bay")
                hardware.setAttribute("type", drone.item.name)
                fitting.appendChild(hardware)

            for fighter in fit.fighters:
                hardware = doc.createElement("hardware")
                hardware.setAttribute("qty", "%d" % fighter.amountActive)
                hardware.setAttribute("slot", "fighter bay")
                hardware.setAttribute("type", fighter.item.name)
                fitting.appendChild(hardware)

            for cargo in fit.cargo:
                if cargo.item.name not in charges:
                    charges[cargo.item.name] = 0
                charges[cargo.item.name] += cargo.amount

            for name, qty in list(charges.items()):
                hardware = doc.createElement("hardware")
                hardware.setAttribute("qty", "%d" % qty)
                hardware.setAttribute("slot", "cargo")
                hardware.setAttribute("type", name)
                fitting.appendChild(hardware)
        except Exception as e:
            pyfalog.error("Failed on fitID: %d, message: %s" % e.message)
            continue
        finally:
            if iportuser:
                processing_notify(
                    iportuser, IPortUser.PROCESS_EXPORT | IPortUser.ID_UPDATE,
                    (i, "convert to xml (%s/%s) %s" %
                     (i + 1, fit_count, fit.ship.name)))
    text = doc.toprettyxml()

    if callback:
        callback(text)
    else:
        return text
Пример #6
0
def exportEft(fit, options, callback):
    # EFT formatted export is split in several sections, each section is
    # separated from another using 2 blank lines. Sections might have several
    # sub-sections, which are separated by 1 blank line
    sections = []

    header = '[{}, {}]'.format(fit.ship.item.name, fit.name)

    # Section 1: modules, rigs, subsystems, services
    modsBySlotType = {}
    for module in fit.modules:
        modsBySlotType.setdefault(module.slot, []).append(module)
    modSection = []

    mutants = {}  # Format: {reference number: module}
    mutantReference = 1
    for slotType in SLOT_ORDER:
        rackLines = []
        modules = modsBySlotType.get(slotType, ())
        for module in modules:
            if module.item:
                # if module was mutated, use base item name for export
                if module.isMutated:
                    modName = module.baseItem.name
                else:
                    modName = module.item.name
                if module.isMutated and options[PortEftOptions.MUTATIONS]:
                    mutants[mutantReference] = module
                    mutationSuffix = ' [{}]'.format(mutantReference)
                    mutantReference += 1
                else:
                    mutationSuffix = ''
                modOfflineSuffix = ' {}'.format(
                    OFFLINE_SUFFIX
                ) if module.state == FittingModuleState.OFFLINE else ''
                if module.charge and options[PortEftOptions.LOADED_CHARGES]:
                    rackLines.append('{}, {}{}{}'.format(
                        modName, module.charge.name, modOfflineSuffix,
                        mutationSuffix))
                else:
                    rackLines.append('{}{}{}'.format(modName, modOfflineSuffix,
                                                     mutationSuffix))
            else:
                rackLines.append('[Empty {} slot]'.format(
                    FittingSlot(slotType).name.capitalize(
                    ) if slotType is not None else ''))
        if rackLines:
            modSection.append('\n'.join(rackLines))
    if modSection:
        sections.append('\n\n'.join(modSection))

    # Section 2: drones, fighters
    minionSection = []
    droneLines = []
    for drone in sorted(fit.drones, key=lambda d: d.item.name):
        droneLines.append('{} x{}'.format(drone.item.name, drone.amount))
    if droneLines:
        minionSection.append('\n'.join(droneLines))
    fighterLines = []
    for fighter in sorted(fit.fighters, key=lambda f: f.item.name):
        fighterLines.append('{} x{}'.format(fighter.item.name,
                                            fighter.amountActive))
    if fighterLines:
        minionSection.append('\n'.join(fighterLines))
    if minionSection:
        sections.append('\n\n'.join(minionSection))

    # Section 3: implants, boosters
    if options[PortEftOptions.IMPLANTS]:
        charSection = []
        implantLines = []
        for implant in sorted(fit.implants, key=lambda i: i.slot or 0):
            implantLines.append(implant.item.name)
        if implantLines:
            charSection.append('\n'.join(implantLines))
        boosterLines = []
        for booster in sorted(fit.boosters, key=lambda b: b.slot or 0):
            boosterLines.append(booster.item.name)
        if boosterLines:
            charSection.append('\n'.join(boosterLines))
        if charSection:
            sections.append('\n\n'.join(charSection))

    # Section 4: cargo
    cargoLines = []
    for cargo in sorted(
            fit.cargo,
            key=lambda c:
        (c.item.group.category.name, c.item.group.name, c.item.name)):
        cargoLines.append('{} x{}'.format(cargo.item.name, cargo.amount))
    if cargoLines:
        sections.append('\n'.join(cargoLines))

    # Section 5: mutated modules' details
    mutationLines = []
    if mutants and options[PortEftOptions.MUTATIONS]:
        for mutantReference in sorted(mutants):
            mutant = mutants[mutantReference]
            mutationLines.append(
                renderMutant(mutant,
                             firstPrefix='[{}] '.format(mutantReference),
                             prefix='  '))
    if mutationLines:
        sections.append('\n'.join(mutationLines))

    text = '{}\n\n{}'.format(header, '\n\n\n'.join(sections))

    if callback:
        callback(text)
    else:
        return text