mirror of https://github.com/OpenMW/openmw.git
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!4217pull/3236/head
commit
3ebeaaa3bb
@ -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
|
Loading…
Reference in New Issue