1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 03:45:35 +00:00

Merge branch 'hidden_marker' into 'master'

Use single implementation to check whether marker is hidden

See merge request OpenMW/openmw!2096
This commit is contained in:
psi29a 2022-07-06 07:30:56 +00:00
commit 9ed4d17f8a
7 changed files with 29 additions and 25 deletions

View file

@ -62,7 +62,7 @@ namespace MWLua
auto visitor = [&](const MWWorld::Ptr& ptr)
{
worldView->getObjectRegistry()->registerPtr(ptr);
if (ptr.getLuaType() == ptr.getType())
if (getLiveCellRefType(ptr.mRef) == ptr.getType())
res->push_back(getId(ptr));
return true;
};

View file

@ -335,7 +335,7 @@ namespace MWLua
if (!localScripts)
{
LuaUtil::ScriptIdsWithInitializationData autoStartConf =
mConfiguration.getLocalConf(ptr.getLuaType(), ptr.getCellRef().getRefId(), getId(ptr));
mConfiguration.getLocalConf(getLiveCellRefType(ptr.mRef), ptr.getCellRef().getRefId(), getId(ptr));
if (!autoStartConf.empty())
{
localScripts = createLocalScripts(ptr, std::move(autoStartConf));
@ -411,7 +411,7 @@ namespace MWLua
{
assert(mInitialized);
std::shared_ptr<LocalScripts> scripts;
uint32_t type = ptr.getLuaType();
const uint32_t type = getLiveCellRefType(ptr.mRef);
if (type == ESM::REC_STAT)
throw std::runtime_error("Lua scripts on static objects are not allowed");
else if (type == ESM::REC_INTERNAL_PLAYER)

View file

@ -2,6 +2,8 @@
#include "types/types.hpp"
#include <components/misc/resourcehelpers.hpp>
namespace MWLua
{
@ -12,8 +14,7 @@ namespace MWLua
bool isMarker(const MWWorld::Ptr& ptr)
{
std::string_view id = ptr.getCellRef().getRefId();
return id == "prisonmarker" || id == "divinemarker" || id == "templemarker" || id == "northmarker";
return Misc::ResourceHelpers::isHiddenMarker(ptr.getCellRef().getRefId());
}
std::string ptrToString(const MWWorld::Ptr& ptr)

View file

@ -165,7 +165,7 @@ namespace MWLua
objectT["type"] = sol::readonly_property([types=getTypeToPackageTable(context.mLua->sol())](const ObjectT& o) mutable
{
return types[o.ptr().getLuaType()];
return types[getLiveCellRefType(o.ptr().mRef)];
});
objectT["count"] = sol::readonly_property([](const ObjectT& o) { return o.ptr().getRefData().getCount(); });

View file

@ -1,6 +1,7 @@
#include "types.hpp"
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
namespace MWLua
{
@ -60,6 +61,18 @@ namespace MWLua
}
unsigned int getLiveCellRefType(const MWWorld::LiveCellRefBase* ref)
{
if (ref == nullptr)
throw std::runtime_error("Can't get type name from an empty object.");
const std::string_view id = ref->mRef.getRefId();
if (id == "player")
return ESM::REC_INTERNAL_PLAYER;
if (Misc::ResourceHelpers::isHiddenMarker(id))
return ESM::REC_INTERNAL_MARKER;
return ref->getType();
}
std::string_view getLuaObjectTypeName(ESM::RecNameInts type, std::string_view fallback)
{
auto it = luaObjectTypeInfo.find(type);
@ -71,7 +84,7 @@ namespace MWLua
std::string_view getLuaObjectTypeName(const MWWorld::Ptr& ptr)
{
return getLuaObjectTypeName(static_cast<ESM::RecNameInts>(ptr.getLuaType()), /*fallback=*/ptr.getTypeDescription());
return getLuaObjectTypeName(static_cast<ESM::RecNameInts>(getLiveCellRefType(ptr.mRef)), /*fallback=*/ptr.getTypeDescription());
}
const MWWorld::Ptr& verifyType(ESM::RecNameInts recordType, const MWWorld::Ptr& ptr)
@ -125,7 +138,7 @@ namespace MWLua
}
t["objectIsInstance"] = [types=recTypes](const Object& o)
{
unsigned int type = o.ptr().getLuaType();
unsigned int type = getLiveCellRefType(o.ptr().mRef);
for (ESM::RecNameInts t : types)
if (t == type)
return true;

View file

@ -10,6 +10,13 @@
namespace MWLua
{
// `getLiveCellRefType()` is not exactly what we usually mean by "type" because some refids have special meaning.
// This function handles these special refids (and by this adds some performance overhead).
// We use this "fixed" type in Lua because we don't want to expose the weirdness of Morrowind internals to our API.
// TODO: Implement https://gitlab.com/OpenMW/openmw/-/issues/6617 and make `MWWorld::PtrBase::getType` work the
// same as `getLiveCellRefType`.
unsigned int getLiveCellRefType(const MWWorld::LiveCellRefBase* ref);
std::string_view getLuaObjectTypeName(ESM::RecNameInts type, std::string_view fallback = "Unknown");
std::string_view getLuaObjectTypeName(const MWWorld::Ptr& ptr);
const MWWorld::Ptr& verifyType(ESM::RecNameInts type, const MWWorld::Ptr& ptr);

View file

@ -46,23 +46,6 @@ namespace MWWorld
throw std::runtime_error("Can't get type name from an empty object.");
}
// `getType()` is not exactly what we usually mean by "type" because some refids have special meaning.
// This function handles these special refids (and by this adds some performance overhead).
// We use this "fixed" type in Lua because we don't want to expose the weirdness of Morrowind internals to our API.
// TODO: Implement https://gitlab.com/OpenMW/openmw/-/issues/6617 and make `getType` work the same as `getLuaType`.
unsigned int getLuaType() const
{
if(mRef == nullptr)
throw std::runtime_error("Can't get type name from an empty object.");
std::string_view id = mRef->mRef.getRefId();
if (id == "player")
return ESM::REC_INTERNAL_PLAYER;
else if (id == "prisonmarker" || id == "divinemarker" || id == "templemarker" || id == "northmarker")
return ESM::REC_INTERNAL_MARKER;
else
return mRef->getType();
}
std::string_view getTypeDescription() const
{
return mRef ? mRef->getTypeDescription() : "nullptr";