1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-26 02:38:04 +00:00

Use more string_view and const string&

This commit is contained in:
Evil Eye 2022-08-22 16:55:53 +02:00
parent bf0865d03d
commit 150d1840d6
42 changed files with 97 additions and 100 deletions

View File

@ -75,7 +75,7 @@ namespace MWClass
return "Item Apparatus Down"; 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>(); const MWWorld::LiveCellRef<ESM::Apparatus> *ref = ptr.get<ESM::Apparatus>();

View File

@ -42,7 +42,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override; std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;

View File

@ -181,7 +181,7 @@ namespace MWClass
return "Item Armor Heavy Down"; 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>(); const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
@ -247,14 +247,14 @@ namespace MWClass
return info; 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>(); const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
return ref->mBase->mEnchant; 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>(); const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();

View File

@ -56,13 +56,13 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< 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 ///< @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. ///< 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; std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;

View File

@ -92,7 +92,7 @@ namespace MWClass
return "Item Book Down"; 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>(); const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
@ -126,14 +126,14 @@ namespace MWClass
return info; 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>(); const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
return ref->mBase->mEnchant; 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>(); const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();

View File

@ -40,13 +40,13 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< 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 ///< @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. ///< 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; std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;

View File

@ -139,7 +139,7 @@ namespace MWClass
return "Item Clothes Down"; 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>(); const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
@ -175,14 +175,14 @@ namespace MWClass
return info; 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>(); const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
return ref->mBase->mEnchant; 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>(); const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();

View File

@ -48,13 +48,13 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< 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 ///< @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. ///< 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; std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;

View File

@ -87,7 +87,7 @@ namespace MWClass
return "Item Ingredient Down"; 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>(); const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>();

View File

@ -43,7 +43,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::string getModel(const MWWorld::ConstPtr &ptr) const override; std::string getModel(const MWWorld::ConstPtr &ptr) const override;

View File

@ -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>(); const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();

View File

@ -54,7 +54,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override; std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;

View File

@ -86,7 +86,7 @@ namespace MWClass
return "Item Lockpick Down"; 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>(); const MWWorld::LiveCellRef<ESM::Lockpick> *ref = ptr.get<ESM::Lockpick>();

View File

@ -44,7 +44,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;

View File

@ -118,7 +118,7 @@ namespace MWClass
return "Item Misc Down"; 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>(); const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();

View File

@ -40,7 +40,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::string getModel(const MWWorld::ConstPtr &ptr) const override; std::string getModel(const MWWorld::ConstPtr &ptr) const override;

View File

@ -79,7 +79,7 @@ namespace MWClass
return "Item Potion Down"; 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>(); const MWWorld::LiveCellRef<ESM::Potion> *ref = ptr.get<ESM::Potion>();

View File

@ -43,7 +43,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::string getModel(const MWWorld::ConstPtr &ptr) const override; std::string getModel(const MWWorld::ConstPtr &ptr) const override;

View File

@ -86,7 +86,7 @@ namespace MWClass
return "Item Probe Down"; 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>(); const MWWorld::LiveCellRef<ESM::Probe> *ref = ptr.get<ESM::Probe>();

View File

@ -44,7 +44,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;

View File

@ -76,7 +76,7 @@ namespace MWClass
return "Item Repair Down"; 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>(); const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>();

View File

@ -40,7 +40,7 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< Return name of inventory icon.
std::string getModel(const MWWorld::ConstPtr &ptr) const override; std::string getModel(const MWWorld::ConstPtr &ptr) const override;

View File

@ -135,7 +135,7 @@ namespace MWClass
return MWMechanics::getWeaponType(type)->mSoundIdDown; 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>(); const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
@ -250,14 +250,14 @@ namespace MWClass
return info; 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>(); const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
return ref->mBase->mEnchant; 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>(); const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();

View File

@ -54,13 +54,13 @@ namespace MWClass
std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override; std::string_view getDownSoundId(const MWWorld::ConstPtr& ptr) const override;
///< Return the put down sound Id ///< 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. ///< 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 ///< @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. ///< 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; std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override;

View File

@ -184,7 +184,7 @@ namespace MWGui
line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr)); line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr));
break; break;
case DisplayMode_EnchantmentCharge: 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()) if (enchId.empty())
break; break;
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId); const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId);

View File

@ -16,7 +16,7 @@ namespace MWGui
, mCount(count) , mCount(count)
, mBase(base) , mBase(base)
{ {
if (base.getClass().getEnchantment(base) != "") if (!base.getClass().getEnchantment(base).empty())
mFlags |= Flag_Enchanted; mFlags |= Flag_Enchanted;
if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(base)) if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(base))

View File

@ -112,11 +112,11 @@ namespace MWGui
void ItemWidget::setIcon(const MWWorld::Ptr &ptr) void ItemWidget::setIcon(const MWWorld::Ptr &ptr)
{ {
std::string invIcon = ptr.getClass().getInventoryIcon(ptr); std::string_view icon = ptr.getClass().getInventoryIcon(ptr);
if (invIcon.empty()) if (icon.empty())
invIcon = "default icon.tga"; icon = "default icon.tga";
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); 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)) if (!vfs->exists(invIcon))
{ {
Log(Debug::Error) << "Failed to open image: '" << invIcon << "' not found, falling back to 'default-icon.tga'"; Log(Debug::Error) << "Failed to open image: '" << invIcon << "' not found, falling back to 'default-icon.tga'";

View File

@ -281,7 +281,7 @@ namespace MWGui
if (!(item.mFlags & ItemStack::Flag_Enchanted)) if (!(item.mFlags & ItemStack::Flag_Enchanted))
return false; 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); const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId);
if (!ench) if (!ench)
{ {

View File

@ -127,7 +127,7 @@ namespace MWGui
for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it)
{ {
MWWorld::Ptr item = *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()) if (enchantId.empty())
continue; continue;
const ESM::Enchantment* enchant = esmStore.get<ESM::Enchantment>().search(enchantId); const ESM::Enchantment* enchant = esmStore.get<ESM::Enchantment>().search(enchantId);

View File

@ -209,7 +209,7 @@ namespace MWMechanics
auto slot = store.getSlot(slotIndex); auto slot = store.getSlot(slotIndex);
if(slot == store.end()) if(slot == store.end())
continue; continue;
const auto& enchantmentId = slot->getClass().getEnchantment(*slot); const std::string_view enchantmentId = slot->getClass().getEnchantment(*slot);
if(enchantmentId.empty()) if(enchantmentId.empty())
continue; continue;
const ESM::Enchantment* enchantment = world->getStore().get<ESM::Enchantment>().find(enchantmentId); const ESM::Enchantment* enchantment = world->getStore().get<ESM::Enchantment>().find(enchantmentId);

View File

@ -344,7 +344,7 @@ namespace MWMechanics
} }
else if (!selectedEnchItem.isEmpty()) else if (!selectedEnchItem.isEmpty())
{ {
std::string enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem); std::string_view enchId = selectedEnchItem.getClass().getEnchantment(selectedEnchItem);
if (!enchId.empty()) if (!enchId.empty())
{ {
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchId); const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchId);

View File

@ -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) 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()) if (!enchantmentName.empty())
{ {
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find( const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(

View File

@ -98,7 +98,7 @@ namespace MWMechanics
enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment); enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
// Apply the 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 // Add the new item to player inventory and remove the old one
store.remove(mOldItemPtr, count, player); store.remove(mOldItemPtr, count, player);

View File

@ -54,7 +54,7 @@ bool rechargeItem(const MWWorld::Ptr &item, const MWWorld::Ptr &gem)
int roll = Misc::Rng::roll0to99(prng); int roll = Misc::Rng::roll0to99(prng);
if (roll < x) 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); const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul);
float restored = creature->mData.mSoul * (roll / x); float restored = creature->mData.mSoul * (roll / x);

View File

@ -210,7 +210,7 @@ namespace MWMechanics
bool CastSpell::cast(const MWWorld::Ptr &item, int slot, bool launchProjectile) 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()) if (enchantmentName.empty())
throw std::runtime_error("can't cast an item without an enchantment"); throw std::runtime_error("can't cast an item without an enchantment");

View File

@ -1195,10 +1195,10 @@ namespace MWWorld
void MWWorld::CellStore::checkItem(const Ptr& ptr) 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; return;
std::string enchantmentId = ptr.getClass().getEnchantment(ptr);
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId);
if (!enchantment) if (!enchantment)
{ {

View File

@ -271,7 +271,7 @@ namespace MWWorld
throw std::runtime_error("class does not support soundgen look up"); 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"); throw std::runtime_error ("class does not have any inventory icon");
} }
@ -294,7 +294,7 @@ namespace MWWorld
return true; return true;
} }
std::string Class::getEnchantment (const ConstPtr& ptr) const std::string_view Class::getEnchantment(const ConstPtr& ptr) const
{ {
return {}; return {};
} }
@ -320,7 +320,7 @@ namespace MWWorld
models.push_back(model); 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"); 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 Class::getEnchantmentColor(const MWWorld::ConstPtr& item) const
{ {
osg::Vec4f result(1,1,1,1); 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()) if (enchantmentName.empty())
return result; return result;

View File

@ -252,10 +252,10 @@ namespace MWWorld
virtual float getArmorRating (const MWWorld::Ptr& ptr) const; virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
///< @return combined armor rating of this actor ///< @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. ///< 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 ///< @return the enchantment ID if the object is enchanted, otherwise an empty string
/// (default implementation: return 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; 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(). ///< 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. ///< 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; virtual std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const;

View File

@ -444,7 +444,7 @@ void MWWorld::ContainerStore::updateRechargingItems()
mRechargingItems.clear(); mRechargingItems.clear();
for (ContainerStoreIterator it = begin(); it != end(); ++it) 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()) if (!enchantmentId.empty())
{ {
const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId); const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchantmentId);

View File

@ -1868,7 +1868,7 @@ namespace MWWorld
const MWWorld::Ptr& selectedEnchantItem = MWBase::Environment::get().getWindowManager()->getSelectedEnchantItem(); const MWWorld::Ptr& selectedEnchantItem = MWBase::Environment::get().getWindowManager()->getSelectedEnchantItem();
if (!selectedEnchantItem.isEmpty()) if (!selectedEnchantItem.isEmpty())
{ {
std::string enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem); std::string_view enchantId = selectedEnchantItem.getClass().getEnchantment(selectedEnchantItem);
if (!enchantId.empty()) if (!enchantId.empty())
{ {
const ESM::Enchantment* ench = mStore.get<ESM::Enchantment>().search(enchantId); 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(); const MWWorld::Ptr& selectedWeapon = MWBase::Environment::get().getWindowManager()->getSelectedWeapon();
if (!selectedWeapon.isEmpty()) if (!selectedWeapon.isEmpty())
{ {
std::string enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon); std::string_view enchantId = selectedWeapon.getClass().getEnchantment(selectedWeapon);
if (!enchantId.empty()) if (!enchantId.empty())
{ {
const ESM::Enchantment* ench = mStore.get<ESM::Enchantment>().search(enchantId); const ESM::Enchantment* ench = mStore.get<ESM::Enchantment>().search(enchantId);

View File

@ -48,26 +48,22 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string &path)
return changeExtension(path, ".dds"); 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 /* Bethesda at some point converted all their BSA
* textures from tga to dds for increased load speed, but all * textures from tga to dds for increased load speed, but all
* texture file name references were kept as .tga. * texture file name references were kept as .tga.
*/ */
std::string prefix1 = topLevelDirectory + '\\'; std::string correctedPath = Misc::StringUtils::lowerCase(resPath);
std::string prefix2 = topLevelDirectory + '/';
std::string correctedPath = resPath;
Misc::StringUtils::lowerCaseInPlace(correctedPath);
// Apparently, leading separators are allowed // Apparently, leading separators are allowed
while (correctedPath.size() && (correctedPath[0] == '/' || correctedPath[0] == '\\')) while (correctedPath.size() && (correctedPath[0] == '/' || correctedPath[0] == '\\'))
correctedPath.erase(0, 1); correctedPath.erase(0, 1);
if(correctedPath.compare(0, prefix1.size(), prefix1.data()) != 0 && if(!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size() ||
correctedPath.compare(0, prefix2.size(), prefix2.data()) != 0) (correctedPath[topLevelDirectory.size()] != '/' && correctedPath[topLevelDirectory.size()] != '\\'))
correctedPath = prefix1 + correctedPath; correctedPath = std::string{topLevelDirectory} + '\\' + correctedPath;
std::string origExt = correctedPath; std::string origExt = correctedPath;
@ -82,13 +78,17 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
return origExt; return origExt;
// fall back to a resource in the top level directory if it exists // 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)) if (vfs->exists(fallback))
return fallback; return fallback;
if (changedToDds) if (changedToDds)
{ {
fallback = topLevelDirectory + "\\" + getBasename(origExt); fallback = topLevelDirectory;
fallback += '\\';
fallback += getBasename(origExt);
if (vfs->exists(fallback)) if (vfs->exists(fallback))
return fallback; return fallback;
} }
@ -96,27 +96,22 @@ std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLev
return correctedPath; 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("textures", resPath, vfs);
return correctResourcePath(dir, 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("icons", resPath, vfs);
return correctResourcePath(dir, 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"; return correctResourcePath("bookart", resPath, vfs);
std::string image = correctResourcePath(dir, resPath, vfs);
return image;
} }
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); std::string image = correctBookartPath(resPath, vfs);
@ -152,14 +147,16 @@ std::string Misc::ResourceHelpers::correctMeshPath(const std::string &resPath, c
return "meshes\\" + resPath; 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. // 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"); changeExtension(sound, ".mp3");
return vfs->normalizeFilename(sound);
return vfs->normalizeFilename(sound); }
return vfs->normalizeFilename(resPath);
} }

View File

@ -17,16 +17,16 @@ namespace Misc
namespace ResourceHelpers namespace ResourceHelpers
{ {
bool changeExtensionToDds(std::string &path); bool changeExtensionToDds(std::string &path);
std::string correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs); std::string correctResourcePath(std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs);
std::string correctTexturePath(const std::string &resPath, const VFS::Manager* vfs); std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs);
std::string correctIconPath(const std::string &resPath, const VFS::Manager* vfs); std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs);
std::string correctBookartPath(const std::string &resPath, const VFS::Manager* vfs); std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs);
std::string correctBookartPath(const std::string &resPath, int width, int height, 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 /// Use "xfoo.nif" instead of "foo.nif" if available
std::string correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs); std::string correctActorModelPath(const std::string &resPath, const VFS::Manager* vfs);
std::string correctMeshPath(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 /// marker objects that have a hardcoded function in the game logic, should be hidden from the player
bool isHiddenMarker(std::string_view id); bool isHiddenMarker(std::string_view id);