1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-06 15:40:54 +00:00

Suggested fixes

This commit is contained in:
SkyHasACat 2025-08-03 11:44:45 -07:00
parent d40a78e8ac
commit d7a411cc72
3 changed files with 10 additions and 14 deletions

View file

@ -41,8 +41,7 @@ namespace
else
npc.blank();
if (npc.mId == ESM::RefId::deserializeText("Player"))
npc.mId = ESM::RefId::deserializeText("blank");
npc.mId = {};
// Basic fields
if (rec["name"] != sol::nil)

View file

@ -191,7 +191,11 @@ namespace MWLua
},
[lua = context.mLua](const ESM::NPC& npc) -> const ESM::NPC* {
checkGameInitialized(lua);
return MWBase::Environment::get().getESMStore()->insert(npc);
if (npc.mId.empty())
return MWBase::Environment::get().getESMStore()->insert(npc);
ESM::NPC copy = npc;
copy.mId = {};
return MWBase::Environment::get().getESMStore()->insert(copy);
},
[lua = context.mLua](const ESM::Weapon& weapon) -> const ESM::Weapon* {
checkGameInitialized(lua);

View file

@ -276,22 +276,15 @@ namespace MWWorld
return it != map.end();
}
template <class StaticMap>
inline bool shouldInsert(const ESM::RefId& id, const StaticMap& map)
{
if (!id.template is<ESM::GeneratedRefId>())
{
auto it = map.find(id);
return it != map.end();
}
return true;
}
template <class T, class Id>
T* TypedDynamicStore<T, Id>::insert(const T& item, bool overrideOnly)
{
if constexpr (std::is_same_v<decltype(item.mId), ESM::RefId>)
overrideOnly = overrideOnly && !item.mId.template is<ESM::GeneratedRefId>();
if (overrideOnly)
{
if (!shouldInsert(item.mId, mStatic))
auto it = mStatic.find(item.mId);
if (it == mStatic.end())
return nullptr;
}
std::pair<typename Dynamic::iterator, bool> result = mDynamic.insert_or_assign(item.mId, item);