mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'enchanting_inventory_view' into 'master'
Use more string_view and const string& See merge request OpenMW/openmw!2327
This commit is contained in:
commit
e4c1748ee8
@ -75,7 +75,7 @@ namespace MWClass
|
||||
return "Item Apparatus Down";
|
||||
}
|
||||
|
||||
std::string Apparatus::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Apparatus::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Apparatus> *ref = ptr.get<ESM::Apparatus>();
|
||||
|
||||
|
@ -42,7 +42,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
|
||||
|
@ -181,7 +181,7 @@ namespace MWClass
|
||||
return "Item Armor Heavy Down";
|
||||
}
|
||||
|
||||
std::string Armor::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Armor::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
|
||||
|
||||
@ -247,14 +247,14 @@ namespace MWClass
|
||||
return info;
|
||||
}
|
||||
|
||||
std::string Armor::getEnchantment (const MWWorld::ConstPtr& ptr) const
|
||||
std::string_view Armor::getEnchantment(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
|
||||
|
||||
return ref->mBase->mEnchant;
|
||||
}
|
||||
|
||||
std::string Armor::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
const std::string& Armor::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
|
||||
|
||||
|
@ -56,13 +56,13 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override;
|
||||
std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||
|
||||
std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||
|
||||
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;
|
||||
|
@ -92,7 +92,7 @@ namespace MWClass
|
||||
return "Item Book Down";
|
||||
}
|
||||
|
||||
std::string Book::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Book::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
|
||||
|
||||
@ -126,14 +126,14 @@ namespace MWClass
|
||||
return info;
|
||||
}
|
||||
|
||||
std::string Book::getEnchantment (const MWWorld::ConstPtr& ptr) const
|
||||
std::string_view Book::getEnchantment(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
|
||||
|
||||
return ref->mBase->mEnchant;
|
||||
}
|
||||
|
||||
std::string Book::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
const std::string& Book::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
|
||||
|
||||
|
@ -40,13 +40,13 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override;
|
||||
std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||
|
||||
std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||
|
||||
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
|
||||
|
@ -139,7 +139,7 @@ namespace MWClass
|
||||
return "Item Clothes Down";
|
||||
}
|
||||
|
||||
std::string Clothing::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Clothing::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
|
||||
|
||||
@ -175,14 +175,14 @@ namespace MWClass
|
||||
return info;
|
||||
}
|
||||
|
||||
std::string Clothing::getEnchantment (const MWWorld::ConstPtr& ptr) const
|
||||
std::string_view Clothing::getEnchantment(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
|
||||
|
||||
return ref->mBase->mEnchant;
|
||||
}
|
||||
|
||||
std::string Clothing::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
const std::string& Clothing::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
|
||||
|
||||
|
@ -48,13 +48,13 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override;
|
||||
std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||
|
||||
std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||
|
||||
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;
|
||||
|
@ -87,7 +87,7 @@ namespace MWClass
|
||||
return "Item Ingredient Down";
|
||||
}
|
||||
|
||||
std::string Ingredient::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Ingredient::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>();
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
|
||||
|
@ -133,7 +133,7 @@ namespace MWClass
|
||||
}
|
||||
|
||||
|
||||
std::string Light::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Light::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
|
||||
|
@ -86,7 +86,7 @@ namespace MWClass
|
||||
return "Item Lockpick Down";
|
||||
}
|
||||
|
||||
std::string Lockpick::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Lockpick::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Lockpick> *ref = ptr.get<ESM::Lockpick>();
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;
|
||||
|
@ -118,7 +118,7 @@ namespace MWClass
|
||||
return "Item Misc Down";
|
||||
}
|
||||
|
||||
std::string Miscellaneous::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Miscellaneous::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
|
||||
|
@ -79,7 +79,7 @@ namespace MWClass
|
||||
return "Item Potion Down";
|
||||
}
|
||||
|
||||
std::string Potion::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Potion::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Potion> *ref = ptr.get<ESM::Potion>();
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
|
||||
|
@ -86,7 +86,7 @@ namespace MWClass
|
||||
return "Item Probe Down";
|
||||
}
|
||||
|
||||
std::string Probe::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Probe::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Probe> *ref = ptr.get<ESM::Probe>();
|
||||
|
||||
|
@ -44,7 +44,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;
|
||||
|
@ -76,7 +76,7 @@ namespace MWClass
|
||||
return "Item Repair Down";
|
||||
}
|
||||
|
||||
std::string Repair::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Repair::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>();
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getModel(const MWWorld::ConstPtr &ptr) const override;
|
||||
|
@ -135,7 +135,7 @@ namespace MWClass
|
||||
return MWMechanics::getWeaponType(type)->mSoundIdDown;
|
||||
}
|
||||
|
||||
std::string Weapon::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Weapon::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
|
||||
|
||||
@ -250,14 +250,14 @@ namespace MWClass
|
||||
return info;
|
||||
}
|
||||
|
||||
std::string Weapon::getEnchantment (const MWWorld::ConstPtr& ptr) const
|
||||
std::string_view Weapon::getEnchantment(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
|
||||
|
||||
return ref->mBase->mEnchant;
|
||||
}
|
||||
|
||||
std::string Weapon::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
const std::string& Weapon::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
{
|
||||
const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
|
||||
|
||||
|
@ -54,13 +54,13 @@ namespace MWClass
|
||||
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return the put down sound Id
|
||||
|
||||
std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const override;
|
||||
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
std::string getEnchantment (const MWWorld::ConstPtr& ptr) const override;
|
||||
std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const override;
|
||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||
|
||||
std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override;
|
||||
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||
|
||||
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;
|
||||
|
@ -184,7 +184,7 @@ namespace MWGui
|
||||
line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr));
|
||||
break;
|
||||
case DisplayMode_EnchantmentCharge:
|
||||
std::string enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr);
|
||||
std::string_view enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr);
|
||||
if (enchId.empty())
|
||||
break;
|
||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId);
|
||||
|
@ -16,7 +16,7 @@ namespace MWGui
|
||||
, mCount(count)
|
||||
, mBase(base)
|
||||
{
|
||||
if (base.getClass().getEnchantment(base) != "")
|
||||
if (!base.getClass().getEnchantment(base).empty())
|
||||
mFlags |= Flag_Enchanted;
|
||||
|
||||
if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(base))
|
||||
|
@ -112,11 +112,11 @@ namespace MWGui
|
||||
|
||||
void ItemWidget::setIcon(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
std::string invIcon = ptr.getClass().getInventoryIcon(ptr);
|
||||
if (invIcon.empty())
|
||||
invIcon = "default icon.tga";
|
||||
std::string_view icon = ptr.getClass().getInventoryIcon(ptr);
|
||||
if (icon.empty())
|
||||
icon = "default icon.tga";
|
||||
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
invIcon = Misc::ResourceHelpers::correctIconPath(invIcon, vfs);
|
||||
std::string invIcon = Misc::ResourceHelpers::correctIconPath(icon, vfs);
|
||||
if (!vfs->exists(invIcon))
|
||||
{
|
||||
Log(Debug::Error) << "Failed to open image: '" << invIcon << "' not found, falling back to 'default-icon.tga'";
|
||||
|
@ -281,7 +281,7 @@ namespace MWGui
|
||||
if (!(item.mFlags & ItemStack::Flag_Enchanted))
|
||||
return false;
|
||||
|
||||
std::string enchId = base.getClass().getEnchantment(base);
|
||||
std::string_view enchId = base.getClass().getEnchantment(base);
|
||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId);
|
||||
if (!ench)
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ namespace MWGui
|
||||
for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it)
|
||||
{
|
||||
MWWorld::Ptr item = *it;
|
||||
const std::string enchantId = item.getClass().getEnchantment(item);
|
||||
const std::string_view enchantId = item.getClass().getEnchantment(item);
|
||||
if (enchantId.empty())
|
||||
continue;
|
||||
const ESM::Enchantment* enchant = esmStore.get<ESM::Enchantment>().search(enchantId);
|
||||
|
@ -209,7 +209,7 @@ namespace MWMechanics
|
||||
auto slot = store.getSlot(slotIndex);
|
||||
if(slot == store.end())
|
||||
continue;
|
||||
const auto& enchantmentId = slot->getClass().getEnchantment(*slot);
|
||||
const std::string_view enchantmentId = slot->getClass().getEnchantment(*slot);
|
||||
if(enchantmentId.empty())
|
||||
continue;
|
||||
const ESM::Enchantment* enchantment = world->getStore().get<ESM::Enchantment>().find(enchantmentId);
|
||||
|
@ -344,7 +344,7 @@ namespace MWMechanics
|
||||
}
|
||||
else if (!selectedEnchItem.isEmpty())
|
||||
{
|
||||
std::string enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem);
|
||||
std::string_view enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem);
|
||||
if (!enchId.empty())
|
||||
{
|
||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchId);
|
||||
|
@ -39,7 +39,7 @@ namespace MWMechanics
|
||||
|
||||
bool applyOnStrikeEnchantment(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, const MWWorld::Ptr& object, const osg::Vec3f& hitPosition, const bool fromProjectile)
|
||||
{
|
||||
std::string enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : "";
|
||||
std::string_view enchantmentName = !object.isEmpty() ? object.getClass().getEnchantment(object) : "";
|
||||
if (!enchantmentName.empty())
|
||||
{
|
||||
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(
|
||||
|
@ -98,7 +98,7 @@ namespace MWMechanics
|
||||
enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
||||
|
||||
// Apply the enchantment
|
||||
std::string newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
||||
const std::string& newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
||||
|
||||
// Add the new item to player inventory and remove the old one
|
||||
store.remove(mOldItemPtr, count, player);
|
||||
|
@ -54,7 +54,7 @@ bool rechargeItem(const MWWorld::Ptr &item, const MWWorld::Ptr &gem)
|
||||
int roll = Misc::Rng::roll0to99(prng);
|
||||
if (roll < x)
|
||||
{
|
||||
std::string soul = gem.getCellRef().getSoul();
|
||||
const std::string& soul = gem.getCellRef().getSoul();
|
||||
const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul);
|
||||
|
||||
float restored = creature->mData.mSoul * (roll / x);
|
||||
|
@ -210,7 +210,7 @@ namespace MWMechanics
|
||||
|
||||
bool CastSpell::cast(const MWWorld::Ptr &item, int slot, bool launchProjectile)
|
||||
{
|
||||
std::string enchantmentName = item.getClass().getEnchantment(item);
|
||||
std::string_view enchantmentName = item.getClass().getEnchantment(item);
|
||||
if (enchantmentName.empty())
|
||||
throw std::runtime_error("can't cast an item without an enchantment");
|
||||
|
||||
|
@ -1195,10 +1195,10 @@ namespace MWWorld
|
||||
|
||||
void MWWorld::CellStore::checkItem(const Ptr& ptr)
|
||||
{
|
||||
if (ptr.getClass().getEnchantment(ptr).empty())
|
||||
std::string_view enchantmentId = ptr.getClass().getEnchantment(ptr);
|
||||
if (enchantmentId.empty())
|
||||
return;
|
||||
|
||||
std::string enchantmentId = ptr.getClass().getEnchantment(ptr);
|
||||
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId);
|
||||
if (!enchantment)
|
||||
{
|
||||
|
@ -271,7 +271,7 @@ namespace MWWorld
|
||||
throw std::runtime_error("class does not support soundgen look up");
|
||||
}
|
||||
|
||||
std::string Class::getInventoryIcon (const MWWorld::ConstPtr& ptr) const
|
||||
const std::string& Class::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
|
||||
{
|
||||
throw std::runtime_error ("class does not have any inventory icon");
|
||||
}
|
||||
@ -294,7 +294,7 @@ namespace MWWorld
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Class::getEnchantment (const ConstPtr& ptr) const
|
||||
std::string_view Class::getEnchantment(const ConstPtr& ptr) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@ -320,7 +320,7 @@ namespace MWWorld
|
||||
models.push_back(model);
|
||||
}
|
||||
|
||||
std::string Class::applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
const std::string& Class::applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const
|
||||
{
|
||||
throw std::runtime_error ("class can't be enchanted");
|
||||
}
|
||||
@ -505,7 +505,7 @@ namespace MWWorld
|
||||
osg::Vec4f Class::getEnchantmentColor(const MWWorld::ConstPtr& item) const
|
||||
{
|
||||
osg::Vec4f result(1,1,1,1);
|
||||
std::string enchantmentName = item.getClass().getEnchantment(item);
|
||||
std::string_view enchantmentName = item.getClass().getEnchantment(item);
|
||||
if (enchantmentName.empty())
|
||||
return result;
|
||||
|
||||
|
@ -252,10 +252,10 @@ namespace MWWorld
|
||||
virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
|
||||
///< @return combined armor rating of this actor
|
||||
|
||||
virtual std::string getInventoryIcon (const MWWorld::ConstPtr& ptr) const;
|
||||
virtual const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const;
|
||||
///< Return name of inventory icon.
|
||||
|
||||
virtual std::string getEnchantment (const MWWorld::ConstPtr& ptr) const;
|
||||
virtual std::string_view getEnchantment(const MWWorld::ConstPtr& ptr) const;
|
||||
///< @return the enchantment ID if the object is enchanted, otherwise an empty string
|
||||
/// (default implementation: return empty string)
|
||||
|
||||
@ -278,7 +278,7 @@ namespace MWWorld
|
||||
virtual void getModelsToPreload(const MWWorld::Ptr& ptr, std::vector<std::string>& models) const;
|
||||
///< Get a list of models to preload that this object may use (directly or indirectly). default implementation: list getModel().
|
||||
|
||||
virtual std::string applyEnchantment(const MWWorld::ConstPtr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
virtual const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
|
||||
///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
|
||||
|
||||
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const;
|
||||
|
@ -444,7 +444,7 @@ void MWWorld::ContainerStore::updateRechargingItems()
|
||||
mRechargingItems.clear();
|
||||
for (ContainerStoreIterator it = begin(); it != end(); ++it)
|
||||
{
|
||||
const std::string& enchantmentId = it->getClass().getEnchantment(*it);
|
||||
std::string_view enchantmentId = it->getClass().getEnchantment(*it);
|
||||
if (!enchantmentId.empty())
|
||||
{
|
||||
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId);
|
||||
|
@ -1868,7 +1868,7 @@ namespace MWWorld
|
||||
const MWWorld::Ptr& selectedEnchantItem = MWBase::Environment::get().getWindowManager()->getSelectedEnchantItem();
|
||||
if (!selectedEnchantItem.isEmpty())
|
||||
{
|
||||
std::string enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem);
|
||||
std::string_view enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem);
|
||||
if (!enchantId.empty())
|
||||
{
|
||||
const ESM::Enchantment* ench = mStore.get<ESM::Enchantment>().search(enchantId);
|
||||
@ -1879,7 +1879,7 @@ namespace MWWorld
|
||||
const MWWorld::Ptr& selectedWeapon = MWBase::Environment::get().getWindowManager()->getSelectedWeapon();
|
||||
if (!selectedWeapon.isEmpty())
|
||||
{
|
||||
std::string enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon);
|
||||
std::string_view enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon);
|
||||
if (!enchantId.empty())
|
||||
{
|
||||
const ESM::Enchantment* ench = mStore.get<ESM::Enchantment>().search(enchantId);
|
||||
|
@ -48,26 +48,22 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
|
||||
return changeExtension(path, ".dds");
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs)
|
||||
{
|
||||
/* Bethesda at some point converted all their BSA
|
||||
* textures from tga to dds for increased load speed, but all
|
||||
* texture file name references were kept as .tga.
|
||||
*/
|
||||
|
||||
std::string prefix1 = topLevelDirectory + '\\';
|
||||
std::string prefix2 = topLevelDirectory + '/';
|
||||
|
||||
std::string correctedPath = resPath;
|
||||
Misc::StringUtils::lowerCaseInPlace(correctedPath);
|
||||
std::string correctedPath = Misc::StringUtils::lowerCase(resPath);
|
||||
|
||||
// Apparently, leading separators are allowed
|
||||
while (correctedPath.size() && (correctedPath[0] == '/' || correctedPath[0] == '\\'))
|
||||
correctedPath.erase(0, 1);
|
||||
|
||||
if(correctedPath.compare(0, prefix1.size(), prefix1.data()) != 0 &&
|
||||
correctedPath.compare(0, prefix2.size(), prefix2.data()) != 0)
|
||||
correctedPath = prefix1 + correctedPath;
|
||||
if(!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size() ||
|
||||
(correctedPath[topLevelDirectory.size()] != '/' && correctedPath[topLevelDirectory.size()] != '\\'))
|
||||
correctedPath = std::string{topLevelDirectory} + '\\' + correctedPath;
|
||||
|
||||
std::string origExt = correctedPath;
|
||||
|
||||
@ -82,13 +78,17 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
|
||||
return origExt;
|
||||
|
||||
// fall back to a resource in the top level directory if it exists
|
||||
std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath);
|
||||
std::string fallback{topLevelDirectory};
|
||||
fallback += '\\';
|
||||
fallback += getBasename(correctedPath);
|
||||
if (vfs->exists(fallback))
|
||||
return fallback;
|
||||
|
||||
if (changedToDds)
|
||||
{
|
||||
fallback = topLevelDirectory + "\\" + getBasename(origExt);
|
||||
fallback = topLevelDirectory;
|
||||
fallback += '\\';
|
||||
fallback += getBasename(origExt);
|
||||
if (vfs->exists(fallback))
|
||||
return fallback;
|
||||
}
|
||||
@ -96,27 +96,22 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
|
||||
return correctedPath;
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctTexturePath(const std::string &resPath, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs)
|
||||
{
|
||||
static const std::string dir = "textures";
|
||||
return correctResourcePath(dir, resPath, vfs);
|
||||
return correctResourcePath("textures", resPath, vfs);
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctIconPath(const std::string &resPath, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs)
|
||||
{
|
||||
static const std::string dir = "icons";
|
||||
return correctResourcePath(dir, resPath, vfs);
|
||||
return correctResourcePath("icons", resPath, vfs);
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs)
|
||||
{
|
||||
static const std::string dir = "bookart";
|
||||
std::string image = correctResourcePath(dir, resPath, vfs);
|
||||
|
||||
return image;
|
||||
return correctResourcePath("bookart", resPath, vfs);
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs)
|
||||
{
|
||||
std::string image = correctBookartPath(resPath, vfs);
|
||||
|
||||
@ -152,14 +147,16 @@ std::string Misc::ResourceHelpers::correctMeshPath(const std::string &resPath, c
|
||||
return "meshes\\" + resPath;
|
||||
}
|
||||
|
||||
std::string Misc::ResourceHelpers::correctSoundPath(const std::string& resPath, const VFS::Manager* vfs)
|
||||
std::string Misc::ResourceHelpers::correctSoundPath(std::string_view resPath, const VFS::Manager* vfs)
|
||||
{
|
||||
std::string sound = resPath;
|
||||
// Workaround: Bethesda at some point converted some of the files to mp3, but the references were kept as .wav.
|
||||
if (!vfs->exists(sound))
|
||||
if (!vfs->exists(resPath))
|
||||
{
|
||||
std::string sound{resPath};
|
||||
changeExtension(sound, ".mp3");
|
||||
|
||||
return vfs->normalizeFilename(sound);
|
||||
return vfs->normalizeFilename(sound);
|
||||
}
|
||||
return vfs->normalizeFilename(resPath);
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,16 @@ namespace Misc
|
||||
namespace ResourceHelpers
|
||||
{
|
||||
bool changeExtensionToDds(std::string &path);
|
||||
std::string correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs);
|
||||
std::string correctTexturePath(const std::string &resPath, const VFS::Manager* vfs);
|
||||
std::string correctIconPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||
std::string correctBookartPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||
std::string correctBookartPath(const std::string &resPath, int width, int height, const VFS::Manager* vfs);
|
||||
std::string correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs);
|
||||
std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs);
|
||||
std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs);
|
||||
std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs);
|
||||
std::string correctBookartPath(std::string_view resPath, int width, int height, const VFS::Manager* vfs);
|
||||
/// Use "xfoo.nif" instead of "foo.nif" if available
|
||||
std::string correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||
std::string correctMeshPath(const std::string &resPath, const VFS::Manager* vfs);
|
||||
|
||||
std::string correctSoundPath(const std::string& resPath, const VFS::Manager* vfs);
|
||||
std::string correctSoundPath(std::string_view resPath, const VFS::Manager* vfs);
|
||||
|
||||
/// marker objects that have a hardcoded function in the game logic, should be hidden from the player
|
||||
bool isHiddenMarker(std::string_view id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user