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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -42,10 +43,7 @@ namespace MWClass
std::string_view Apparatus::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Apparatus>* ref = ptr.get<ESM::Apparatus>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Apparatus>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -51,10 +52,7 @@ namespace MWClass
std::string_view Armor::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Armor>* ref = ptr.get<ESM::Armor>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Armor>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -48,10 +49,7 @@ namespace MWClass
std::string_view Book::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Book>* ref = ptr.get<ESM::Book>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Book>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -46,10 +47,7 @@ namespace MWClass
std::string_view Clothing::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Clothing>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -217,10 +218,7 @@ namespace MWClass
std::string_view Container::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Container>* ref = ptr.get<ESM::Container>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Container>(ptr);
}
MWWorld::ContainerStore& Container::getContainerStore(const MWWorld::Ptr& ptr) const

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

@ -35,6 +35,7 @@
#include "../mwmechanics/actorutil.hpp"
#include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -101,10 +102,7 @@ namespace MWClass
std::string_view Door::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Door>* ref = ptr.get<ESM::Door>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Door>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -46,10 +47,7 @@ namespace MWClass
std::string_view Ingredient::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Ingredient>* ref = ptr.get<ESM::Ingredient>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Ingredient>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -81,9 +82,7 @@ namespace MWClass
if (ref->mBase->mModel.empty())
return {};
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Light>(ptr);
}
bool Light::isItem(const MWWorld::ConstPtr& ptr) const

@ -21,6 +21,7 @@
#include "../mwrender/renderinginterface.hpp"
#include "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -45,10 +46,7 @@ namespace MWClass
std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Lockpick>* ref = ptr.get<ESM::Lockpick>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Lockpick>(ptr);
}
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 "classmodel.hpp"
#include "nameorid.hpp"
namespace MWClass
{
@ -56,10 +57,7 @@ namespace MWClass
std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = ptr.get<ESM::Miscellaneous>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::Miscellaneous>(ptr);
}
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 "nameorid.hpp"
namespace
{
struct NpcParts
@ -541,10 +543,7 @@ namespace MWClass
return store.find("sWerewolfPopup")->mValue.getString();
}
const MWWorld::LiveCellRef<ESM::NPC>* ref = ptr.get<ESM::NPC>();
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId.getRefIdString();
return getNameOrId<ESM::NPC>(ptr);
}
MWMechanics::CreatureStats& Npc::getCreatureStats(const MWWorld::Ptr& ptr) const

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

Loading…
Cancel
Save