1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 21:45:33 +00:00

Remove NAME and DELE handling from IdCollection

This commit is contained in:
Stanislav Bas 2015-07-13 10:40:11 +03:00
parent 42f9136141
commit 74a055f3cc
7 changed files with 118 additions and 66 deletions

View file

@ -5,16 +5,13 @@
void CSMWorld::Cell::load (ESM::ESMReader &esm) void CSMWorld::Cell::load (ESM::ESMReader &esm)
{ {
mName = mId;
ESM::Cell::load (esm, false); ESM::Cell::load (esm, false);
mId = mName;
if (!(mData.mFlags & Interior)) if (!(mData.mFlags & Interior))
{ {
std::ostringstream stream; std::ostringstream stream;
stream << "#" << mData.mX << " " << mData.mY; stream << "#" << mData.mX << " " << mData.mY;
mId = stream.str(); mId = stream.str();
} }
} }

View file

@ -988,41 +988,41 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages)
case ESM::REC_DIAL: case ESM::REC_DIAL:
{ {
std::string id = mReader->getHNOString ("NAME");
ESM::Dialogue record; ESM::Dialogue record;
record.mId = id;
record.load (*mReader); record.load (*mReader);
if (record.mType==ESM::Dialogue::Journal) if (record.mIsDeleted)
{ {
mJournals.load (record, mBase); // record vector can be shuffled around which would make pointer to record invalid
mDialogue = &mJournals.getRecord (id).get(); mDialogue = 0;
}
else if (record.mType==ESM::Dialogue::Deleted)
{
mDialogue = 0; // record vector can be shuffled around which would make pointer
// to record invalid
if (mJournals.tryDelete (id)) if (mJournals.tryDelete (record.mId))
{ {
/// \todo handle info records /// \todo handle info records
} }
else if (mTopics.tryDelete (id)) else if (mTopics.tryDelete (record.mId))
{ {
/// \todo handle info records /// \todo handle info records
} }
else else
{ {
messages.add (UniversalId::Type_None, messages.add (UniversalId::Type_None,
"Trying to delete dialogue record " + id + " which does not exist", "Trying to delete dialogue record " + record.mId + " which does not exist",
"", CSMDoc::Message::Severity_Warning); "", CSMDoc::Message::Severity_Warning);
} }
} }
else else
{ {
mTopics.load (record, mBase); if (record.mType == ESM::Dialogue::Journal)
mDialogue = &mTopics.getRecord (id).get(); {
mJournals.load (record, mBase);
mDialogue = &mJournals.getRecord (record.mId).get();
}
else
{
mTopics.load (record, mBase);
mDialogue = &mTopics.getRecord (record.mId).get();
}
} }
break; break;

View file

@ -2,6 +2,7 @@
#define CSM_WOLRD_IDCOLLECTION_H #define CSM_WOLRD_IDCOLLECTION_H
#include <components/esm/esmreader.hpp> #include <components/esm/esmreader.hpp>
#include <components/esm/util.hpp>
#include "collection.hpp" #include "collection.hpp"
@ -41,69 +42,43 @@ namespace CSMWorld
template<typename ESXRecordT, typename IdAccessorT> template<typename ESXRecordT, typename IdAccessorT>
int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base) int IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base)
{ {
std::string id = reader.getHNOString ("NAME"); ESXRecordT record;
loadRecord (record, reader);
if (reader.isNextSub ("DELE")) std::string id = IdAccessorT().getId (record);
int index = searchId (id);
if (ESM::isRecordDeleted (record))
{ {
int index = Collection<ESXRecordT, IdAccessorT>::searchId (id);
reader.skipRecord();
if (index==-1) if (index==-1)
{ {
// deleting a record that does not exist // deleting a record that does not exist
// ignore it for now // ignore it for now
/// \todo report the problem to the user /// \todo report the problem to the user
return -1;
} }
else if (base)
if (base)
{ {
Collection<ESXRecordT, IdAccessorT>::removeRows (index, 1); removeRows (index, 1);
} }
else else
{ {
Record<ESXRecordT> record = Collection<ESXRecordT, IdAccessorT>::getRecord (index); Record<ESXRecordT> baseRecord = getRecord (index);
record.mState = RecordBase::State_Deleted; baseRecord.mState = RecordBase::State_Deleted;
this->setRecord (index, record); this->setRecord (index, baseRecord);
} }
return -1; return -1;
} }
else //
{ //if (index != -1)
ESXRecordT record; //{
// ESXRecordT existedRecord = getRecord(index).get();
// IdAccessorT().getId(record) = IdAccessorT().getId(existedRecord);
//}
// Sometimes id (i.e. NAME of the cell) may be different to the id we stored return load (record, base, index);
// earlier. e.g. NAME == "Vivec, Arena" but id == "#-4 11". Sometime NAME is
// missing altogether for scripts or cells.
//
// In such cases the returned index will be -1. We then try updating the
// IdAccessor's id manually (e.g. set mId of the record to "Vivec, Arena")
// and try getting the index once more after loading the record. The mId of the
// record would have changed to "#-4 11" after the load, and searchId() should find
// it (if this is a modify)
int index = this->searchId (id);
if (index==-1)
IdAccessorT().getId (record) = id;
else
{
record = this->getRecord (index).get();
}
loadRecord (record, reader);
if (index==-1)
{
std::string newId = IdAccessorT().getId(record);
int newIndex = this->searchId(newId);
if (newIndex != -1 && id != newId)
index = newIndex;
}
return load (record, base, index);
}
} }
template<typename ESXRecordT, typename IdAccessorT> template<typename ESXRecordT, typename IdAccessorT>

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <components/esm/loadland.hpp> #include <components/esm/loadland.hpp>
#include <components/esm/util.hpp>
namespace CSMWorld namespace CSMWorld
{ {
@ -26,4 +27,13 @@ namespace CSMWorld
}; };
} }
namespace ESM
{
template <>
bool isRecordDeleted<CSMWorld::Land>(const CSMWorld::Land &land)
{
return false;
}
}
#endif #endif

View file

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <components/esm/loadpgrd.hpp> #include <components/esm/loadpgrd.hpp>
#include <components/esm/util.hpp>
namespace CSMWorld namespace CSMWorld
{ {
@ -26,4 +27,13 @@ namespace CSMWorld
}; };
} }
namespace ESM
{
template <>
bool isRecordDeleted<CSMWorld::Pathgrid>(const CSMWorld::Pathgrid &pgrd)
{
return false;
}
}
#endif #endif

View file

@ -36,4 +36,40 @@ namespace ESM
{ {
return false; return false;
} }
template <>
bool isRecordDeleted<Skill>(const Skill &skill)
{
return false;
}
template <>
bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef)
{
return false;
}
template <>
bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd)
{
return false;
}
template <>
bool isRecordDeleted<Land>(const Land &land)
{
return false;
}
template <>
bool isRecordDeleted<DebugProfile>(const DebugProfile &profile)
{
return false;
}
template <>
bool isRecordDeleted<Filter>(const Filter &filter)
{
return false;
}
} }

View file

@ -12,6 +12,12 @@
#include "loadglob.hpp" #include "loadglob.hpp"
#include "loadrace.hpp" #include "loadrace.hpp"
#include "loadgmst.hpp" #include "loadgmst.hpp"
#include "loadskil.hpp"
#include "loadmgef.hpp"
#include "loadland.hpp"
#include "loadpgrd.hpp"
#include "debugprofile.hpp"
#include "filter.hpp"
namespace ESM namespace ESM
{ {
@ -76,6 +82,24 @@ bool isRecordDeleted<Race>(const Race &race);
template <> template <>
bool isRecordDeleted<GameSetting>(const GameSetting &gmst); bool isRecordDeleted<GameSetting>(const GameSetting &gmst);
template <>
bool isRecordDeleted<Skill>(const Skill &skill);
template <>
bool isRecordDeleted<MagicEffect>(const MagicEffect &mgef);
template <>
bool isRecordDeleted<Pathgrid>(const Pathgrid &pgrd);
template <>
bool isRecordDeleted<Land>(const Land &land);
template <>
bool isRecordDeleted<DebugProfile>(const DebugProfile &profile);
template <>
bool isRecordDeleted<Filter>(const Filter &filter);
} }
#endif #endif