mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:23:51 +00:00
Move ID loading into a separate method for Dialogue and DialInfo records
This commit is contained in:
parent
74a055f3cc
commit
c8c79dc1ef
5 changed files with 51 additions and 22 deletions
|
@ -1027,19 +1027,19 @@ namespace MWWorld
|
||||||
inline RecordId Store<ESM::Dialogue>::load(ESM::ESMReader &esm) {
|
inline RecordId Store<ESM::Dialogue>::load(ESM::ESMReader &esm) {
|
||||||
// The original letter case of a dialogue ID is saved, because it's printed
|
// The original letter case of a dialogue ID is saved, because it's printed
|
||||||
ESM::Dialogue dialogue;
|
ESM::Dialogue dialogue;
|
||||||
dialogue.load(esm);
|
dialogue.loadId(esm);
|
||||||
|
|
||||||
std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId);
|
std::string idLower = Misc::StringUtils::lowerCase(dialogue.mId);
|
||||||
std::map<std::string, ESM::Dialogue>::iterator found = mStatic.find(idLower);
|
std::map<std::string, ESM::Dialogue>::iterator found = mStatic.find(idLower);
|
||||||
if (found == mStatic.end())
|
if (found == mStatic.end())
|
||||||
{
|
{
|
||||||
|
dialogue.loadData(esm);
|
||||||
mStatic.insert(std::make_pair(idLower, dialogue));
|
mStatic.insert(std::make_pair(idLower, dialogue));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Update only read fields (don't touching the Info list)
|
found->second.loadData(esm);
|
||||||
found->second.mIsDeleted = dialogue.mIsDeleted;
|
dialogue = found->second;
|
||||||
found->second.mType = dialogue.mType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RecordId(dialogue.mId, dialogue.mIsDeleted);
|
return RecordId(dialogue.mId, dialogue.mIsDeleted);
|
||||||
|
|
|
@ -19,9 +19,18 @@ namespace ESM
|
||||||
|
|
||||||
void Dialogue::load(ESMReader &esm)
|
void Dialogue::load(ESMReader &esm)
|
||||||
{
|
{
|
||||||
mIsDeleted = false;
|
loadId(esm);
|
||||||
|
loadData(esm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dialogue::loadId(ESMReader &esm)
|
||||||
|
{
|
||||||
|
mIsDeleted = false;
|
||||||
mId = esm.getHNString("NAME");
|
mId = esm.getHNString("NAME");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dialogue::loadData(ESMReader &esm)
|
||||||
|
{
|
||||||
esm.getSubNameIs("DATA");
|
esm.getSubNameIs("DATA");
|
||||||
esm.getSubHeader();
|
esm.getSubHeader();
|
||||||
int si = esm.getSubSize();
|
int si = esm.getSubSize();
|
||||||
|
@ -60,31 +69,28 @@ namespace ESM
|
||||||
|
|
||||||
void Dialogue::readInfo(ESMReader &esm, bool merge)
|
void Dialogue::readInfo(ESMReader &esm, bool merge)
|
||||||
{
|
{
|
||||||
const std::string& id = esm.getHNOString("INAM");
|
ESM::DialInfo info;
|
||||||
|
info.loadId(esm);
|
||||||
|
|
||||||
if (!merge || mInfo.empty())
|
if (!merge || mInfo.empty())
|
||||||
{
|
{
|
||||||
ESM::DialInfo info;
|
info.loadInfo(esm);
|
||||||
info.mId = id;
|
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
|
||||||
info.load(esm);
|
|
||||||
mLookup[id] = mInfo.insert(mInfo.end(), info);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
|
ESM::Dialogue::InfoContainer::iterator it = mInfo.end();
|
||||||
|
|
||||||
std::map<std::string, ESM::Dialogue::InfoContainer::iterator>::iterator lookup;
|
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())
|
if (lookup != mLookup.end())
|
||||||
{
|
{
|
||||||
it = lookup->second;
|
it = lookup->second;
|
||||||
|
|
||||||
// Merge with existing record. Only the subrecords that are present in
|
// Merge with existing record. Only the subrecords that are present in
|
||||||
// the new record will be overwritten.
|
// the new record will be overwritten.
|
||||||
it->load(esm);
|
it->loadInfo(esm);
|
||||||
info = *it;
|
info = *it;
|
||||||
|
|
||||||
// Since the record merging may have changed the next/prev linked list connection, we need to re-insert the record
|
// 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
|
else
|
||||||
{
|
{
|
||||||
info.mId = id;
|
info.loadInfo(esm);
|
||||||
info.load(esm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.mNext.empty())
|
if (info.mNext.empty())
|
||||||
{
|
{
|
||||||
mLookup[id] = mInfo.insert(mInfo.end(), info);
|
mLookup[info.mId] = mInfo.insert(mInfo.end(), info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (info.mPrev.empty())
|
if (info.mPrev.empty())
|
||||||
{
|
{
|
||||||
mLookup[id] = mInfo.insert(mInfo.begin(), info);
|
mLookup[info.mId] = mInfo.insert(mInfo.begin(), info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +118,7 @@ namespace ESM
|
||||||
{
|
{
|
||||||
it = lookup->second;
|
it = lookup->second;
|
||||||
|
|
||||||
mLookup[id] = mInfo.insert(++it, info);
|
mLookup[info.mId] = mInfo.insert(++it, info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +127,11 @@ namespace ESM
|
||||||
{
|
{
|
||||||
it = lookup->second;
|
it = lookup->second;
|
||||||
|
|
||||||
mLookup[id] = mInfo.insert(it, info);
|
mLookup[info.mId] = mInfo.insert(it, info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "Failed to insert info " << id << std::endl;
|
std::cerr << "Failed to insert info " << info.mId << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialogue::clearDeletedInfos()
|
void Dialogue::clearDeletedInfos()
|
||||||
|
|
|
@ -51,6 +51,12 @@ struct Dialogue
|
||||||
Dialogue();
|
Dialogue();
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
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;
|
void save(ESMWriter &esm) const;
|
||||||
|
|
||||||
/// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos.
|
/// Remove all INFOs that are deleted or marked as QS_Deleted from mInfos.
|
||||||
|
|
|
@ -14,10 +14,21 @@ namespace ESM
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void DialInfo::load(ESMReader &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;
|
mQuestStatus = QS_None;
|
||||||
mFactionLess = false;
|
mFactionLess = false;
|
||||||
mIsDeleted = false;
|
|
||||||
|
|
||||||
mPrev = esm.getHNString("PNAM");
|
mPrev = esm.getHNString("PNAM");
|
||||||
mNext = esm.getHNString("NNAM");
|
mNext = esm.getHNString("NNAM");
|
||||||
|
@ -141,6 +152,7 @@ namespace ESM
|
||||||
|
|
||||||
void DialInfo::save(ESMWriter &esm) const
|
void DialInfo::save(ESMWriter &esm) const
|
||||||
{
|
{
|
||||||
|
esm.writeHNCString("INAM", mId);
|
||||||
esm.writeHNCString("PNAM", mPrev);
|
esm.writeHNCString("PNAM", mPrev);
|
||||||
esm.writeHNCString("NNAM", mNext);
|
esm.writeHNCString("NNAM", mNext);
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,12 @@ struct DialInfo
|
||||||
DialInfo();
|
DialInfo();
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
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 save(ESMWriter &esm) const;
|
||||||
|
|
||||||
void blank();
|
void blank();
|
||||||
|
|
Loading…
Reference in a new issue