1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:53:53 +00:00

Merge branch 'esmstore-fixes' into 'master'

Some ESMStore fixes

See merge request OpenMW/openmw!2279
This commit is contained in:
psi29a 2022-08-17 14:10:54 +00:00
commit 5b9acd0bb9

View file

@ -249,17 +249,14 @@ namespace MWWorld
template <class T> template <class T>
const T *insertStatic(const T &x) const T *insertStatic(const T &x)
{ {
const std::string id = "$dynamic" + std::to_string(mDynamicCount++);
Store<T> &store = const_cast<Store<T> &>(get<T>()); Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(id) != nullptr) if (store.search(x.mId) != nullptr)
{ {
const std::string msg = "Try to override existing record '" + id + "'"; const std::string msg = "Try to override existing record '" + x.mId + "'";
throw std::runtime_error(msg); throw std::runtime_error(msg);
} }
T record = x;
T *ptr = store.insertStatic(record); T *ptr = store.insertStatic(x);
for (iterator it = mStores.begin(); it != mStores.end(); ++it) { for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
if (it->second == &store) { if (it->second == &store) {
mIds[ptr->mId] = it->first; mIds[ptr->mId] = it->first;
@ -299,13 +296,13 @@ namespace MWWorld
template <> template <>
inline const ESM::NPC *ESMStore::insert<ESM::NPC>(const ESM::NPC &npc) inline const ESM::NPC *ESMStore::insert<ESM::NPC>(const ESM::NPC &npc)
{ {
const std::string id = "$dynamic" + std::to_string(mDynamicCount++);
if (Misc::StringUtils::ciEqual(npc.mId, "player")) if (Misc::StringUtils::ciEqual(npc.mId, "player"))
{ {
return mNpcs.insert(npc); return mNpcs.insert(npc);
} }
else if (mNpcs.search(id) != nullptr)
const std::string id = "$dynamic" + std::to_string(mDynamicCount++);
if (mNpcs.search(id) != nullptr)
{ {
const std::string msg = "Try to override existing record '" + id + "'"; const std::string msg = "Try to override existing record '" + id + "'";
throw std::runtime_error(msg); throw std::runtime_error(msg);