Move ID loading into a separate method for Dialogue and DialInfo records

openmw-38
Stanislav Bas 10 years ago
parent 74a055f3cc
commit c8c79dc1ef

@ -1027,19 +1027,19 @@ namespace MWWorld
inline RecordId Store<ESM::Dialogue>::load(ESM::ESMReader &esm) {
// The original letter case of a dialogue ID is saved, because it's printed
ESM::Dialogue dialogue;
dialogue.load(esm);
dialogue.loadId(esm);
std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId);
std::map<std::string, ESM::Dialogue>::iterator found = mStatic.find(idLower);
if (found == mStatic.end())
{
dialogue.loadData(esm);
mStatic.insert(std::make_pair(idLower, dialogue));
}
else
{
// Update only read fields (don't touching the Info list)
found->second.mIsDeleted = dialogue.mIsDeleted;
found->second.mType = dialogue.mType;
found->second.loadData(esm);
dialogue = found->second;
}
return RecordId(dialogue.mId, dialogue.mIsDeleted);

@ -19,9 +19,18 @@ namespace ESM
void Dialogue::load(ESMReader &esm)
{
mIsDeleted = false;
loadId(esm);
loadData(esm);
}
void Dialogue::loadId(ESMReader &esm)
{
mIsDeleted = false;
mId = esm.getHNString("NAME");
}
void Dialogue::loadData(ESMReader &esm)
{
esm.getSubNameIs("DATA");
esm.getSubHeader();
int si = esm.getSubSize();
@ -60,31 +69,28 @@ namespace ESM
void Dialogue::readInfo(ESMReader &esm, bool merge)
{
const std::string& id = esm.getHNOString("INAM");
ESM::DialInfo info;
info.loadId(esm);
if (!merge || mInfo.empty())
{
ESM::DialInfo info;
info.mId = id;
info.load(esm);
mLookup[id] = mInfo.insert(mInfo.end(), info);
info.loadInfo(esm);
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
return;
}
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
lookup = mLookup.find(info.mId);
lookup = mLookup.find(id);
ESM::DialInfo info;
if (lookup != mLookup.end())
{
it = lookup->second;
// Merge with existing record. Only the subrecords that are present in
// the new record will be overwritten.
it->load(esm);
it->loadInfo(esm);
info = *it;
// Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record
@ -93,18 +99,17 @@ namespace ESM
}
else
{
info.mId = id;
info.load(esm);
info.loadInfo(esm);
}
if (info.mNext.empty())
{
mLookup[id] = mInfo.insert(mInfo.end(), info);
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
return;
}
if (info.mPrev.empty())
{
mLookup[id] = mInfo.insert(mInfo.begin(), info);
mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
return;
}
@ -113,7 +118,7 @@ namespace ESM
{
it = lookup->second;
mLookup[id] = mInfo.insert(++it, info);
mLookup[info.mId] = mInfo.insert(++it, info);
return;
}
@ -122,11 +127,11 @@ namespace ESM
{
it = lookup->second;
mLookup[id] = mInfo.insert(it, info);
mLookup[info.mId] = mInfo.insert(it, info);
return;
}
std::cerr << "Failed to insert info " << id << std::endl;
std::cerr << "Failed to insert info " << info.mId << std::endl;
}
void Dialogue::clearDeletedInfos()

@ -51,6 +51,12 @@ struct Dialogue
Dialogue();
void load(ESMReader &esm);
///< Loads all sub-records of Dialogue record
void loadId(ESMReader &esm);
///< Loads NAME sub-record of Dialogue record
void loadData(ESMReader &esm);
///< Loads all sub-records of Dialogue record, except NAME sub-record
void save(ESMWriter &esm) const;
/// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos.

@ -14,10 +14,21 @@ namespace ESM
{}
void DialInfo::load(ESMReader &esm)
{
loadId(esm);
loadInfo(esm);
}
void DialInfo::loadId(ESMReader &esm)
{
mIsDeleted = false;
mId = esm.getHNString("INAM");
}
void DialInfo::loadInfo(ESMReader &esm)
{
mQuestStatus = QS_None;
mFactionLess = false;
mIsDeleted = false;
mPrev = esm.getHNString("PNAM");
mNext = esm.getHNString("NNAM");
@ -141,6 +152,7 @@ namespace ESM
void DialInfo::save(ESMWriter &esm) const
{
esm.writeHNCString("INAM", mId);
esm.writeHNCString("PNAM", mPrev);
esm.writeHNCString("NNAM", mNext);

@ -111,6 +111,12 @@ struct DialInfo
DialInfo();
void load(ESMReader &esm);
///< Loads all sub-records of Info record
void loadId(ESMReader &esm);
///< Loads only Id of Info record (INAM sub-record)
void loadInfo(ESMReader &esm);
///< Loads all sub-records of Info record, except INAM sub-record
void save(ESMWriter &esm) const;
void blank();

Loading…
Cancel
Save