当前位置: 首页>>代码示例>>Python>>正文


Python Module.fits方法代码示例

本文整理汇总了Python中eos.saveddata.module.Module.fits方法的典型用法代码示例。如果您正苦于以下问题:Python Module.fits方法的具体用法?Python Module.fits怎么用?Python Module.fits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eos.saveddata.module.Module的用法示例。


在下文中一共展示了Module.fits方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Do

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
    def Do(self):
        sFit = Fit.getInstance()
        fitID = self.fitID
        fit = eos.db.getFit(fitID)

        if self.baseItem is None:
            pyfalog.warning("Unable to build non-mutated module: no base item to build from")
            return False

        try:
            mutaTypeID = self.mutaItem.ID
        except AttributeError:
            mutaplasmid = None
        else:
            mutaplasmid = getDynamicItem(mutaTypeID)
        # Try to build simple item even though no mutaplasmid found
        if mutaplasmid is None:
            try:
                module = Module(self.baseItem)
            except ValueError:
                pyfalog.warning("Unable to build non-mutated module: {}", self.baseItem)
                return False
        # Build mutated module otherwise
        else:
            try:
                module = Module(mutaplasmid.resultingItem, self.baseItem, mutaplasmid)
            except ValueError:
                pyfalog.warning("Unable to build mutated module: {} {}", self.baseItem, self.mutaItem)
                return False
            else:
                for attrID, mutator in module.mutators.items():
                    if attrID in self.attrMap:
                        mutator.value = self.attrMap[attrID]


        # this is essentially the same as the FitAddModule command. possibly look into centralizing this functionality somewhere?
        if module.fits(fit):
            pyfalog.debug("Adding {} as module for fit {}", module, fit)
            module.owner = fit
            numSlots = len(fit.modules)
            fit.modules.append(module)
            if module.isValidState(FittingModuleState.ACTIVE):
                module.state = FittingModuleState.ACTIVE

            # todo: fix these
            # 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, module)

            # fit.fill()
            eos.db.commit()

            self.change = numSlots != len(fit.modules)
            self.new_position = module.modPosition
        else:
            return False

        return True
开发者ID:burnsypet,项目名称:Pyfa,代码行数:61,代码来源:fitImportMutatedModule.py

示例2: importESI

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
def importESI(str_):

    sMkt = Market.getInstance()
    fitobj = Fit()
    refobj = json.loads(str_)
    items = refobj['items']
    # "<" and ">" is replace to "&lt;", "&gt;" by EVE client
    fitobj.name = refobj['name']
    # 2017/03/29: read description
    fitobj.notes = refobj['description']

    try:
        ship = refobj['ship_type_id']
        try:
            fitobj.ship = Ship(sMkt.getItem(ship))
        except ValueError:
            fitobj.ship = Citadel(sMkt.getItem(ship))
    except:
        pyfalog.warning("Caught exception in importESI")
        return None

    items.sort(key=lambda k: k['flag'])

    moduleList = []
    for module in items:
        try:
            item = sMkt.getItem(module['type_id'], eager="group.category")
            if not item.published:
                continue
            if module['flag'] == INV_FLAG_DRONEBAY:
                d = Drone(item)
                d.amount = module['quantity']
                fitobj.drones.append(d)
            elif module['flag'] == INV_FLAG_CARGOBAY:
                c = Cargo(item)
                c.amount = module['quantity']
                fitobj.cargo.append(c)
            elif module['flag'] == INV_FLAG_FIGHTER:
                fighter = Fighter(item)
                fitobj.fighters.append(fighter)
            else:
                try:
                    m = Module(item)
                # When item can't be added to any slot (unknown item or just charge), ignore it
                except ValueError:
                    pyfalog.debug("Item can't be added to any slot (unknown item or just charge)")
                    continue
                # Add subsystems before modules to make sure T3 cruisers have subsystems installed
                if item.category.name == "Subsystem":
                    if m.fits(fitobj):
                        fitobj.modules.append(m)
                else:
                    if m.isValidState(State.ACTIVE):
                        m.state = State.ACTIVE

                    moduleList.append(m)

        except:
            pyfalog.warning("Could not process module.")
            continue

    # Recalc to get slot numbers correct for T3 cruisers
    svcFit.getInstance().recalc(fitobj)

    for module in moduleList:
        if module.fits(fitobj):
            fitobj.modules.append(module)

    return fitobj
开发者ID:bsmr-eve,项目名称:Pyfa,代码行数:71,代码来源:esi.py

示例3: importXml

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
def importXml(text, iportuser):
    from .port import Port
    # type: (str, IPortUser) -> list[eos.saveddata.fit.Fit]
    sMkt = Market.getInstance()
    doc = xml.dom.minidom.parseString(text)
    # NOTE:
    #   When L_MARK is included at this point,
    #   Decided to be localized data
    b_localized = L_MARK in text
    fittings = doc.getElementsByTagName("fittings").item(0)
    fittings = fittings.getElementsByTagName("fitting")
    fit_list = []
    failed = 0

    for fitting in fittings:
        try:
            fitobj = _resolve_ship(fitting, sMkt, b_localized)
        except:
            failed += 1
            continue

        # -- 170327 Ignored description --
        # read description from exported xml. (EVE client, EFT)
        description = fitting.getElementsByTagName("description").item(0).getAttribute("value")
        if description is None:
            description = ""
        elif len(description):
            # convert <br> to "\n" and remove html tags.
            if Port.is_tag_replace():
                description = replace_ltgt(
                    sequential_rep(description, r"<(br|BR)>", "\n", r"<[^<>]+>", "")
                )
        fitobj.notes = description

        hardwares = fitting.getElementsByTagName("hardware")
        moduleList = []
        for hardware in hardwares:
            try:
                item = _resolve_module(hardware, sMkt, b_localized)
                if not item or not item.published:
                    continue

                if item.category.name == "Drone":
                    d = Drone(item)
                    d.amount = int(hardware.getAttribute("qty"))
                    fitobj.drones.append(d)
                elif item.category.name == "Fighter":
                    ft = Fighter(item)
                    ft.amount = int(hardware.getAttribute("qty")) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize
                    fitobj.fighters.append(ft)
                elif hardware.getAttribute("slot").lower() == "cargo":
                    # although the eve client only support charges in cargo, third-party programs
                    # may support items or "refits" in cargo. Support these by blindly adding all
                    # cargo, not just charges
                    c = Cargo(item)
                    c.amount = int(hardware.getAttribute("qty"))
                    fitobj.cargo.append(c)
                else:
                    try:
                        m = Module(item)
                    # When item can't be added to any slot (unknown item or just charge), ignore it
                    except ValueError:
                        pyfalog.warning("item can't be added to any slot (unknown item or just charge), ignore it")
                        continue
                    # Add subsystems before modules to make sure T3 cruisers have subsystems installed
                    if item.category.name == "Subsystem":
                        if m.fits(fitobj):
                            m.owner = fitobj
                            fitobj.modules.append(m)
                    else:
                        if m.isValidState(FittingModuleState.ACTIVE):
                            m.state = activeStateLimit(m.item)

                        moduleList.append(m)

            except KeyboardInterrupt:
                pyfalog.warning("Keyboard Interrupt")
                continue

        # Recalc to get slot numbers correct for T3 cruisers
        sFit = svcFit.getInstance()
        sFit.recalc(fitobj)
        sFit.fill(fitobj)

        for module in moduleList:
            if module.fits(fitobj):
                module.owner = fitobj
                fitobj.modules.append(module)

        fit_list.append(fitobj)
        if iportuser:  # NOTE: Send current processing status
            processing_notify(
                iportuser, IPortUser.PROCESS_IMPORT | IPortUser.ID_UPDATE,
                "Processing %s\n%s" % (fitobj.ship.name, fitobj.name)
            )

    return fit_list
开发者ID:,项目名称:,代码行数:99,代码来源:

示例4: importEftCfg

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
def importEftCfg(shipname, lines, iportuser):
    """Handle import from EFT config store file"""

    # Check if we have such ship in database, bail if we don't
    sMkt = Market.getInstance()
    try:
        sMkt.getItem(shipname)
    except:
        return []  # empty list is expected

    fits = []  # List for fits
    fitIndices = []  # List for starting line numbers for each fit

    for line in lines:
        # Detect fit header
        if line[:1] == "[" and line[-1:] == "]":
            # Line index where current fit starts
            startPos = lines.index(line)
            fitIndices.append(startPos)

    for i, startPos in enumerate(fitIndices):
        # End position is last file line if we're trying to get it for last fit,
        # or start position of next fit minus 1
        endPos = len(lines) if i == len(fitIndices) - 1 else fitIndices[i + 1]

        # Finally, get lines for current fitting
        fitLines = lines[startPos:endPos]

        try:
            # Create fit object
            fitobj = Fit()
            # Strip square brackets and pull out a fit name
            fitobj.name = fitLines[0][1:-1]
            # Assign ship to fitting
            try:
                fitobj.ship = Ship(sMkt.getItem(shipname))
            except ValueError:
                fitobj.ship = Citadel(sMkt.getItem(shipname))

            moduleList = []
            for x in range(1, len(fitLines)):
                line = fitLines[x]
                if not line:
                    continue

                # Parse line into some data we will need
                misc = re.match("(Drones|Implant|Booster)_(Active|Inactive)=(.+)", line)
                cargo = re.match("Cargohold=(.+)", line)
                # 2017/03/27 NOTE: store description from EFT
                description = re.match("Description=(.+)", line)

                if misc:
                    entityType = misc.group(1)
                    entityState = misc.group(2)
                    entityData = misc.group(3)
                    if entityType == "Drones":
                        droneData = re.match("(.+),([0-9]+)", entityData)
                        # Get drone name and attempt to detect drone number
                        droneName = droneData.group(1) if droneData else entityData
                        droneAmount = int(droneData.group(2)) if droneData else 1
                        # Bail if we can't get item or it's not from drone category
                        try:
                            droneItem = sMkt.getItem(droneName, eager="group.category")
                        except:
                            pyfalog.warning("Cannot get item.")
                            continue
                        if droneItem.category.name == "Drone":
                            # Add drone to the fitting
                            d = Drone(droneItem)
                            d.amount = droneAmount
                            if entityState == "Active":
                                d.amountActive = droneAmount
                            elif entityState == "Inactive":
                                d.amountActive = 0
                            fitobj.drones.append(d)
                        elif droneItem.category.name == "Fighter":  # EFT saves fighter as drones
                            ft = Fighter(droneItem)
                            ft.amount = int(droneAmount) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize
                            fitobj.fighters.append(ft)
                        else:
                            continue
                    elif entityType == "Implant":
                        # Bail if we can't get item or it's not from implant category
                        try:
                            implantItem = sMkt.getItem(entityData, eager="group.category")
                        except:
                            pyfalog.warning("Cannot get item.")
                            continue
                        if implantItem.category.name != "Implant":
                            continue
                        # Add implant to the fitting
                        imp = Implant(implantItem)
                        if entityState == "Active":
                            imp.active = True
                        elif entityState == "Inactive":
                            imp.active = False
                        fitobj.implants.append(imp)
                    elif entityType == "Booster":
                        # Bail if we can't get item or it's not from implant category
                        try:
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例5: FitReplaceModuleCommand

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
class FitReplaceModuleCommand(wx.Command):
    """"
    Fitting command that changes an existing module into another.

    from sFit.changeModule
    """
    def __init__(self, fitID, position, itemID):
        wx.Command.__init__(self, True, "Change Module")
        self.fitID = fitID
        self.itemID = itemID
        self.position = position
        self.module = None  # the module version of itemID
        self.old_module = None

    def Do(self):
        fit = eos.db.getFit(self.fitID)

        mod = fit.modules[self.position]
        if not mod.isEmpty:
            self.old_module = ModuleInfoCache(mod.modPosition, mod.item.ID, mod.state, mod.charge, mod.baseItemID,
                                              mod.mutaplasmidID)

        return self.change_module(self.fitID, self.position, self.itemID)

    def Undo(self):
        if self.old_module is None:
            fit = eos.db.getFit(self.fitID)
            fit.modules.toDummy(self.position)
            return True
        self.change_module(self.fitID, self.position, self.old_module.itemID)
        self.module.state = self.old_module.state
        self.module.charge = self.old_module.charge
        return True

    def change_module(self, fitID, position, itemID):
        fit = eos.db.getFit(fitID)

        # We're trying to add a charge to a slot, which won't work. Instead, try to add the charge to the module in that slot.
        # todo: evaluate if this is still a thing
        # actually, this seems like it should be handled higher up...
        #
        # if self.isAmmo(itemID):
        #     module = fit.modules[self.position]
        #     if not module.isEmpty:
        #         self.setAmmo(fitID, itemID, [module])
        #     return True

        pyfalog.debug("Changing position of module from position ({0}) for fit ID: {1}", self.position, fitID)

        item = eos.db.getItem(itemID, eager=("attributes", "group.category"))
        mod = fit.modules[self.position]

        try:
            self.module = Module(item)
        except ValueError:
            pyfalog.warning("Invalid item: {0}", itemID)
            return False

        if self.module.slot != mod.slot:
            return False

        # Dummy it out in case the next bit fails
        fit.modules.toDummy(self.position)

        if self.module.fits(fit):
            self.module.owner = fit
            fit.modules.toModule(self.position, self.module)
            if self.module.isValidState(State.ACTIVE):
                self.module.state = State.ACTIVE

            if self.old_module and self.old_module.charge and self.module.isValidCharge(self.old_module.charge):
                self.module.charge = self.old_module.charge

            # Then, check states of all modules and change where needed. This will recalc if needed
            # self.checkStates(fit, m)

            # fit.fill()
            eos.db.commit()
            return True
        return False
开发者ID:bsmr-eve,项目名称:Pyfa,代码行数:82,代码来源:fitReplaceModule.py

示例6: importDna

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
def importDna(string):
    sMkt = Market.getInstance()

    ids = list(map(int, re.findall(r'\d+', string)))
    for id_ in ids:
        try:
            try:
                try:
                    Ship(sMkt.getItem(sMkt.getItem(id_)))
                except ValueError:
                    Citadel(sMkt.getItem(sMkt.getItem(id_)))
            except ValueError:
                Citadel(sMkt.getItem(id_))
            string = string[string.index(str(id_)):]
            break
        except:
            pyfalog.warning("Exception caught in importDna")
            pass
    string = string[:string.index("::") + 2]
    info = string.split(":")

    f = Fit()
    try:
        try:
            f.ship = Ship(sMkt.getItem(int(info[0])))
        except ValueError:
            f.ship = Citadel(sMkt.getItem(int(info[0])))
        f.name = "{0} - DNA Imported".format(f.ship.item.name)
    except UnicodeEncodeError:
        def logtransform(s_):
            if len(s_) > 10:
                return s_[:10] + "..."
            return s_

        pyfalog.exception("Couldn't import ship data {0}", [logtransform(s) for s in info])
        return None

    moduleList = []
    for itemInfo in info[1:]:
        if itemInfo:
            itemID, amount = itemInfo.split(";")
            item = sMkt.getItem(int(itemID), eager="group.category")

            if item.category.name == "Drone":
                d = Drone(item)
                d.amount = int(amount)
                f.drones.append(d)
            elif item.category.name == "Fighter":
                ft = Fighter(item)
                ft.amount = int(amount) if ft.amount <= ft.fighterSquadronMaxSize else ft.fighterSquadronMaxSize
                if ft.fits(f):
                    f.fighters.append(ft)
            elif item.category.name == "Charge":
                c = Cargo(item)
                c.amount = int(amount)
                f.cargo.append(c)
            else:
                for i in range(int(amount)):
                    try:
                        m = Module(item)
                    except:
                        pyfalog.warning("Exception caught in importDna")
                        continue
                    # Add subsystems before modules to make sure T3 cruisers have subsystems installed
                    if item.category.name == "Subsystem":
                        if m.fits(f):
                            f.modules.append(m)
                    else:
                        m.owner = f
                        if m.isValidState(State.ACTIVE):
                            m.state = State.ACTIVE
                        moduleList.append(m)

    # Recalc to get slot numbers correct for T3 cruisers
    svcFit.getInstance().recalc(f)

    for module in moduleList:
        if module.fits(f):
            module.owner = f
            if module.isValidState(State.ACTIVE):
                module.state = State.ACTIVE
            f.modules.append(module)

    return f
开发者ID:bsmr-eve,项目名称:Pyfa,代码行数:86,代码来源:dna.py

示例7: FitAddModuleCommand

# 需要导入模块: from eos.saveddata.module import Module [as 别名]
# 或者: from eos.saveddata.module.Module import fits [as 别名]
class FitAddModuleCommand(wx.Command):
    """"
    Fitting command that appends a module to a fit using the first available slot. In the case of a Subsystem, it checks
    if there is already a subsystem with the same slot, and runs the replace command instead.

    from sFit.appendModule
    """
    def __init__(self, fitID, itemID, mutaplasmidID=None, baseID=None):
        wx.Command.__init__(self, True)
        self.fitID = fitID
        self.itemID = itemID
        self.mutaplasmidID = mutaplasmidID
        self.baseID = baseID
        self.new_position = None
        self.change = None
        self.replace_cmd = None

    def Do(self):
        sFit = Fit.getInstance()
        fitID = self.fitID
        itemID = self.itemID
        fit = eos.db.getFit(fitID)
        item = eos.db.getItem(itemID, eager=("attributes", "group.category"))

        bItem = eos.db.getItem(self.baseID) if self.baseID else None
        mItem = next((x for x in bItem.mutaplasmids if x.ID == self.mutaplasmidID)) if self.mutaplasmidID else None

        try:
            self.module = Module(item, bItem, mItem)
        except ValueError:
            pyfalog.warning("Invalid module: {}", item)
            return False

        # If subsystem and we need to replace, run the replace command instead and bypass the rest of this command
        if self.module.item.category.name == "Subsystem":
            for mod in fit.modules:
                if mod.getModifiedItemAttr("subSystemSlot") == self.module.getModifiedItemAttr("subSystemSlot"):
                    from .fitReplaceModule import FitReplaceModuleCommand
                    self.replace_cmd = FitReplaceModuleCommand(self.fitID, mod.modPosition, itemID)
                    return self.replace_cmd.Do()

        if self.module.fits(fit):
            pyfalog.debug("Adding {} as module for fit {}", self.module, fit)
            self.module.owner = fit
            numSlots = len(fit.modules)
            fit.modules.append(self.module)
            if self.module.isValidState(State.ACTIVE):
                self.module.state = State.ACTIVE

            # todo: fix these
            # 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, self.module)

            # fit.fill()
            eos.db.commit()

            self.change = numSlots != len(fit.modules)
            self.new_position = self.module.modPosition
        else:
            return False

        return True

    def Undo(self):
        # We added a subsystem module, which actually ran the replace command. Run the undo for that guy instead
        if self.replace_cmd:
            return self.replace_cmd.Undo()

        from .fitRemoveModule import FitRemoveModuleCommand  # Avoid circular import
        if self.new_position:
            cmd = FitRemoveModuleCommand(self.fitID, [self.new_position])
            cmd.Do()
        return True
开发者ID:bsmr-eve,项目名称:Pyfa,代码行数:77,代码来源:fitAddModule.py


注:本文中的eos.saveddata.module.Module.fits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。