Example #1
0
const Item *Inventory::findItemBySprite(std::string spritePath,
                                        const GenderT gender,
                                        const BeingTypeId race) const
{
    spritePath = removeSpriteIndex(spritePath);

    const std::string spritePathShort = extractNameFromSprite(spritePath);
    int partialIndex = -1;

    for (unsigned i = 0; i < mSize; i++)
    {
        const Item *const item = mItems[i];
        if (item != nullptr)
        {
            std::string path = item->getInfo().getSprite(gender, race);
            if (!path.empty())
            {
                path = removeSpriteIndex(path);
                if (spritePath == path)
                    return item;

                path = extractNameFromSprite(path);
                if (spritePathShort == path)
                    partialIndex = i;
            }
        }
    }
    if (partialIndex != -1)
        return mItems[partialIndex];

    return nullptr;
}
Example #2
0
Item *Inventory::findItemBySprite(std::string spritePath,
                                  Gender gender, int race)
{
    spritePath = removeSpriteIndex(spritePath);
//    logger->log1("Inventory::FindItemBySprite sprite: " + spritePath);

    std::string spritePathShort = extractNameFromSprite(spritePath);
//    logger->log1("Inventory::FindItemBySprite spriteShort: " + spritePathShort);
    int partialIndex = -1;

    for (unsigned i = 0; i < mSize; i++)
    {
        if (mItems[i])
        {
            std::string path = mItems[i]->getInfo().getSprite(gender, race);
            if (!path.empty())
            {
                path = removeSpriteIndex(path);

//                logger->log("Inventory::FindItemBySprite normal: " + path);

                if (spritePath == path)
                    return mItems[i];

                path = extractNameFromSprite(path);
//                logger->log("Inventory::FindItemBySprite short: " + path);
                if (spritePathShort == path)
                    partialIndex = i;
            }
        }
    }
    if (partialIndex != -1)
        return mItems[partialIndex];

    return nullptr;
}