forked from teamnwah/openmw-tes3coop
Remove DELE and NAME handling from RefIdCollection and RefIdData
This commit is contained in:
parent
c266315a35
commit
42f9136141
3 changed files with 87 additions and 77 deletions
|
@ -767,61 +767,7 @@ const CSMWorld::RecordBase& CSMWorld::RefIdCollection::getRecord (int index) con
|
||||||
|
|
||||||
void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type)
|
void CSMWorld::RefIdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type)
|
||||||
{
|
{
|
||||||
std::string id = reader.getHNOString ("NAME");
|
mData.load(reader, base, type);
|
||||||
|
|
||||||
int index = searchId (id);
|
|
||||||
|
|
||||||
if (reader.isNextSub ("DELE"))
|
|
||||||
{
|
|
||||||
reader.skipRecord();
|
|
||||||
|
|
||||||
if (index==-1)
|
|
||||||
{
|
|
||||||
// deleting a record that does not exist
|
|
||||||
|
|
||||||
// ignore it for now
|
|
||||||
|
|
||||||
/// \todo report the problem to the user
|
|
||||||
}
|
|
||||||
else if (base)
|
|
||||||
{
|
|
||||||
mData.erase (index, 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mData.getRecord (mData.globalToLocalIndex (index)).mState = RecordBase::State_Deleted;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (index==-1)
|
|
||||||
{
|
|
||||||
// new record
|
|
||||||
int index = mData.getAppendIndex (type);
|
|
||||||
mData.appendRecord (type, id, base);
|
|
||||||
|
|
||||||
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index);
|
|
||||||
|
|
||||||
mData.load (localIndex, reader, base);
|
|
||||||
|
|
||||||
mData.getRecord (localIndex).mState =
|
|
||||||
base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// old record
|
|
||||||
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index);
|
|
||||||
|
|
||||||
if (!base)
|
|
||||||
if (mData.getRecord (localIndex).mState==RecordBase::State_Erased)
|
|
||||||
throw std::logic_error ("attempt to access a deleted record");
|
|
||||||
|
|
||||||
mData.load (localIndex, reader, base);
|
|
||||||
|
|
||||||
if (!base)
|
|
||||||
mData.getRecord (localIndex).mState = RecordBase::State_Modified;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSMWorld::RefIdCollection::getAppendIndex (const std::string& id, UniversalId::Type type) const
|
int CSMWorld::RefIdCollection::getAppendIndex (const std::string& id, UniversalId::Type type) const
|
||||||
|
|
|
@ -161,15 +161,15 @@ int CSMWorld::RefIdData::getAppendIndex (UniversalId::Type type) const
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::RefIdData::load (const LocalIndex& index, ESM::ESMReader& reader, bool base)
|
void CSMWorld::RefIdData::load (ESM::ESMReader& reader, bool base, CSMWorld::UniversalId::Type type)
|
||||||
{
|
{
|
||||||
std::map<UniversalId::Type, RefIdDataContainerBase *>::iterator iter =
|
std::map<UniversalId::Type, RefIdDataContainerBase *>::iterator found =
|
||||||
mRecordContainers.find (index.second);
|
mRecordContainers.find (type);
|
||||||
|
|
||||||
if (iter==mRecordContainers.end())
|
if (found == mRecordContainers.end())
|
||||||
throw std::logic_error ("invalid local index type");
|
throw std::logic_error ("Invalid type for an Object (Reference ID)");
|
||||||
|
|
||||||
iter->second->load (index.first, reader, base);
|
found->second->load(reader, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::RefIdData::erase (const LocalIndex& index, int count)
|
void CSMWorld::RefIdData::erase (const LocalIndex& index, int count)
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual void insertRecord (RecordBase& record) = 0;
|
virtual void insertRecord (RecordBase& record) = 0;
|
||||||
|
|
||||||
virtual void load (int index, ESM::ESMReader& reader, bool base) = 0;
|
virtual void load (ESM::ESMReader& reader, bool base) = 0;
|
||||||
|
|
||||||
virtual void erase (int index, int count) = 0;
|
virtual void erase (int index, int count) = 0;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual void insertRecord (RecordBase& record);
|
virtual void insertRecord (RecordBase& record);
|
||||||
|
|
||||||
virtual void load (int index, ESM::ESMReader& reader, bool base);
|
virtual void load (ESM::ESMReader& reader, bool base);
|
||||||
|
|
||||||
virtual void erase (int index, int count);
|
virtual void erase (int index, int count);
|
||||||
|
|
||||||
|
@ -122,9 +122,67 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
void RefIdDataContainer<RecordT>::load (int index, ESM::ESMReader& reader, bool base)
|
void RefIdDataContainer<RecordT>::load (ESM::ESMReader& reader, bool base)
|
||||||
{
|
{
|
||||||
(base ? mContainer.at (index).mBase : mContainer.at (index).mModified).load (reader);
|
RecordT record;
|
||||||
|
record.load(reader);
|
||||||
|
|
||||||
|
typename std::vector<Record<RecordT> >::iterator found = mContainer.begin();
|
||||||
|
for (; found != mContainer.end(); ++found)
|
||||||
|
{
|
||||||
|
if (found->get().mId == record.mId)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (record.mIsDeleted)
|
||||||
|
{
|
||||||
|
if (found == mContainer.end())
|
||||||
|
{
|
||||||
|
// deleting a record that does not exist
|
||||||
|
// ignore it for now
|
||||||
|
/// \todo report the problem to the user
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (base)
|
||||||
|
{
|
||||||
|
mContainer.erase(found);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
found->mState = RecordBase::State_Deleted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (found == mContainer.end())
|
||||||
|
{
|
||||||
|
appendRecord(record.mId, base);
|
||||||
|
if (base)
|
||||||
|
{
|
||||||
|
mContainer.back().mBase = record;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mContainer.back().mModified = record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!base)
|
||||||
|
{
|
||||||
|
if (found->mState == RecordBase::State_Erased)
|
||||||
|
{
|
||||||
|
throw std::logic_error("Attempt to access a deleted record");
|
||||||
|
}
|
||||||
|
|
||||||
|
found->mState = RecordBase::State_Modified;
|
||||||
|
found->mModified = record;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
|
@ -145,20 +203,26 @@ namespace CSMWorld
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
void RefIdDataContainer<RecordT>::save (int index, ESM::ESMWriter& writer) const
|
void RefIdDataContainer<RecordT>::save (int index, ESM::ESMWriter& writer) const
|
||||||
{
|
{
|
||||||
CSMWorld::RecordBase::State state = mContainer.at (index).mState;
|
Record<RecordT> record = mContainer.at(index);
|
||||||
|
RecordT esmRecord;
|
||||||
|
|
||||||
if (state==CSMWorld::RecordBase::State_Modified ||
|
switch (record.mState)
|
||||||
state==CSMWorld::RecordBase::State_ModifiedOnly)
|
|
||||||
{
|
{
|
||||||
writer.startRecord (mContainer.at (index).mModified.sRecordId);
|
case RecordBase::State_Modified:
|
||||||
writer.writeHNCString ("NAME", getId (index));
|
case RecordBase::State_ModifiedOnly:
|
||||||
mContainer.at (index).mModified.save (writer);
|
esmRecord = record.mModified;
|
||||||
writer.endRecord (mContainer.at (index).mModified.sRecordId);
|
break;
|
||||||
}
|
case RecordBase::State_Deleted:
|
||||||
else if (state==CSMWorld::RecordBase::State_Deleted)
|
esmRecord = record.mBase;
|
||||||
{
|
esmRecord.mIsDeleted = true;
|
||||||
/// \todo write record with delete flag
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.startRecord(esmRecord.sRecordId);
|
||||||
|
esmRecord.save(writer);
|
||||||
|
writer.endRecord(esmRecord.sRecordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,7 +284,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
int getAppendIndex (UniversalId::Type type) const;
|
int getAppendIndex (UniversalId::Type type) const;
|
||||||
|
|
||||||
void load (const LocalIndex& index, ESM::ESMReader& reader, bool base);
|
void load (ESM::ESMReader& reader, bool base, UniversalId::Type type);
|
||||||
|
|
||||||
int getSize() const;
|
int getSize() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue