forked from mirror/openmw-tes3mp
first attempt at an info record collection
parent
45f5a66bcc
commit
ba88c94d58
@ -0,0 +1,72 @@
|
||||
|
||||
#include "infocollection.hpp"
|
||||
|
||||
#include <components/esm/esmreader.hpp>
|
||||
|
||||
void CSMWorld::InfoCollection::load (const ESM::DialInfo& record, bool base)
|
||||
{
|
||||
int index = searchId (record.mId);
|
||||
|
||||
if (index==-1)
|
||||
{
|
||||
// new record
|
||||
Record<ESM::DialInfo> record2;
|
||||
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
||||
(base ? record2.mBase : record2.mModified) = record;
|
||||
|
||||
appendRecord (record2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// old record
|
||||
Record<ESM::DialInfo> record2 = getRecord (index);
|
||||
|
||||
if (base)
|
||||
record2.mBase = record;
|
||||
else
|
||||
record2.setModified (record);
|
||||
|
||||
setRecord (index, record2);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base)
|
||||
{
|
||||
/// \todo put records into proper order
|
||||
/// \todo adjust ID
|
||||
std::string id = reader.getHNOString ("NAME");
|
||||
|
||||
if (reader.isNextSub ("DELE"))
|
||||
{
|
||||
int index = searchId (id);
|
||||
|
||||
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)
|
||||
{
|
||||
removeRows (index, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Record<ESM::DialInfo> record = getRecord (index);
|
||||
record.mState = RecordBase::State_Deleted;
|
||||
setRecord (index, record);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESM::DialInfo record;
|
||||
record.mId = id;
|
||||
record.load (reader);
|
||||
|
||||
load (record, base);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef CSM_WOLRD_INFOCOLLECTION_H
|
||||
#define CSM_WOLRD_INFOCOLLECTION_H
|
||||
|
||||
#include <components/esm/loadinfo.hpp>
|
||||
|
||||
#include "collection.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class InfoCollection : public Collection<ESM::DialInfo, IdAccessor<ESM::DialInfo> >
|
||||
{
|
||||
void load (const ESM::DialInfo& record, bool base);
|
||||
|
||||
public:
|
||||
|
||||
void load (ESM::ESMReader& reader, bool base);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue