Merge branch 'saymyname' into 'master'

Don't use getRefIdString to get a fallback object name for non-string ids

Closes #8043

See merge request OpenMW/openmw!4217
pull/3236/head
psi29a 6 months ago
commit 3ebeaaa3bb

@ -18,6 +18,7 @@
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -42,10 +43,7 @@ namespace MWClass
std::string_view Apparatus::getName(const MWWorld::ConstPtr& ptr) const std::string_view Apparatus::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Apparatus>* ref = ptr.get<ESM::Apparatus>(); return getNameOrId<ESM::Apparatus>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Apparatus::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Apparatus::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -27,6 +27,7 @@
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -51,10 +52,7 @@ namespace MWClass
std::string_view Armor::getName(const MWWorld::ConstPtr& ptr) const std::string_view Armor::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Armor>* ref = ptr.get<ESM::Armor>(); return getNameOrId<ESM::Armor>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Armor::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Armor::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -24,6 +24,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -48,10 +49,7 @@ namespace MWClass
std::string_view Book::getName(const MWWorld::ConstPtr& ptr) const std::string_view Book::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Book>* ref = ptr.get<ESM::Book>(); return getNameOrId<ESM::Book>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Book::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Book::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -22,6 +22,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -46,10 +47,7 @@ namespace MWClass
std::string_view Clothing::getName(const MWWorld::ConstPtr& ptr) const std::string_view Clothing::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>(); return getNameOrId<ESM::Clothing>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Clothing::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Clothing::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -34,6 +34,7 @@
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -217,10 +218,7 @@ namespace MWClass
std::string_view Container::getName(const MWWorld::ConstPtr& ptr) const std::string_view Container::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Container>* ref = ptr.get<ESM::Container>(); return getNameOrId<ESM::Container>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
MWWorld::ContainerStore& Container::getContainerStore(const MWWorld::Ptr& ptr) const MWWorld::ContainerStore& Container::getContainerStore(const MWWorld::Ptr& ptr) const

@ -48,6 +48,7 @@
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace namespace
{ {
@ -209,10 +210,7 @@ namespace MWClass
std::string_view Creature::getName(const MWWorld::ConstPtr& ptr) const std::string_view Creature::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>(); return getNameOrId<ESM::Creature>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
MWMechanics::CreatureStats& Creature::getCreatureStats(const MWWorld::Ptr& ptr) const MWMechanics::CreatureStats& Creature::getCreatureStats(const MWWorld::Ptr& ptr) const

@ -35,6 +35,7 @@
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -101,10 +102,7 @@ namespace MWClass
std::string_view Door::getName(const MWWorld::ConstPtr& ptr) const std::string_view Door::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Door>* ref = ptr.get<ESM::Door>(); return getNameOrId<ESM::Door>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Door::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Door::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -22,6 +22,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -46,10 +47,7 @@ namespace MWClass
std::string_view Ingredient::getName(const MWWorld::ConstPtr& ptr) const std::string_view Ingredient::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Ingredient>* ref = ptr.get<ESM::Ingredient>(); return getNameOrId<ESM::Ingredient>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Ingredient::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Ingredient::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -27,6 +27,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -81,9 +82,7 @@ namespace MWClass
if (ref->mBase->mModel.empty()) if (ref->mBase->mModel.empty())
return {}; return {};
return getNameOrId<ESM::Light>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
bool Light::isItem(const MWWorld::ConstPtr& ptr) const bool Light::isItem(const MWWorld::ConstPtr& ptr) const

@ -21,6 +21,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -45,10 +46,7 @@ namespace MWClass
std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>(); return getNameOrId<ESM::Lockpick>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Lockpick::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Lockpick::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -25,6 +25,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -56,10 +57,7 @@ namespace MWClass
std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>(); return getNameOrId<ESM::Miscellaneous>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Miscellaneous::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Miscellaneous::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -0,0 +1,25 @@
#ifndef OPENMW_MWCLASS_NAMEORID_H
#define OPENMW_MWCLASS_NAMEORID_H
#include <components/esm/refid.hpp>
#include "../mwworld/livecellref.hpp"
#include "../mwworld/ptr.hpp"
#include <string_view>
namespace MWClass
{
template <class Class>
std::string_view getNameOrId(const MWWorld::ConstPtr& ptr)
{
const MWWorld::LiveCellRef<Class>* ref = ptr.get<Class>();
if (!ref->mBase->mName.empty())
return ref->mBase->mName;
if (const auto* id = ref->mBase->mId.template getIf<ESM::StringRefId>())
return id->getValue();
return {};
}
}
#endif

@ -61,6 +61,8 @@
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "nameorid.hpp"
namespace namespace
{ {
struct NpcParts struct NpcParts
@ -541,10 +543,7 @@ namespace MWClass
return store.find("sWerewolfPopup")->mValue.getString(); return store.find("sWerewolfPopup")->mValue.getString();
} }
const MWWorld::LiveCellRef<ESM::NPC>* ref = ptr.get<ESM::NPC>(); return getNameOrId<ESM::NPC>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
MWMechanics::CreatureStats& Npc::getCreatureStats(const MWWorld::Ptr& ptr) const MWMechanics::CreatureStats& Npc::getCreatureStats(const MWWorld::Ptr& ptr) const

@ -22,6 +22,7 @@
#include "../mwmechanics/spellutil.hpp" #include "../mwmechanics/spellutil.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -46,10 +47,7 @@ namespace MWClass
std::string_view Potion::getName(const MWWorld::ConstPtr& ptr) const std::string_view Potion::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Potion>* ref = ptr.get<ESM::Potion>(); return getNameOrId<ESM::Potion>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Potion::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Potion::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -21,6 +21,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -45,10 +46,7 @@ namespace MWClass
std::string_view Probe::getName(const MWWorld::ConstPtr& ptr) const std::string_view Probe::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Probe>* ref = ptr.get<ESM::Probe>(); return getNameOrId<ESM::Probe>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Probe::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Probe::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const
{ {

@ -19,6 +19,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -43,10 +44,7 @@ namespace MWClass
std::string_view Repair::getName(const MWWorld::ConstPtr& ptr) const std::string_view Repair::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Repair>* ref = ptr.get<ESM::Repair>(); return getNameOrId<ESM::Repair>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Repair::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Repair::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

@ -26,6 +26,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass namespace MWClass
{ {
@ -50,10 +51,7 @@ namespace MWClass
std::string_view Weapon::getName(const MWWorld::ConstPtr& ptr) const std::string_view Weapon::getName(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Weapon>* ref = ptr.get<ESM::Weapon>(); return getNameOrId<ESM::Weapon>(ptr);
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
} }
std::unique_ptr<MWWorld::Action> Weapon::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const std::unique_ptr<MWWorld::Action> Weapon::activate(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor) const

Loading…
Cancel
Save