From 69f28ee4bebdb636b3623c7342f1c72d98532858 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 31 Oct 2013 12:16:45 +0100 Subject: [PATCH] split info records between journal and topic info tables --- apps/opencs/model/world/data.cpp | 24 ++++++++++++++++++++-- apps/opencs/model/world/infocollection.cpp | 2 +- apps/opencs/model/world/infocollection.hpp | 7 ++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 2947b2b8f..0962c3856 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -456,6 +456,8 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) reader.open (path.string()); + const ESM::Dialogue *dialogue = 0; + // Note: We do not need to send update signals here, because at this point the model is not connected // to any view. while (reader.hasMoreRecs()) @@ -516,10 +518,15 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) if (record.mType==ESM::Dialogue::Journal) { + int index = mJournals.getAppendIndex (id); mJournals.load (record, base); + dialogue = &mJournals.getRecord (index).get(); } else if (record.mType==ESM::Dialogue::Deleted) { + dialogue = 0; // record vector can be shuffled around which would make pointer + // to record invalid + if (mJournals.tryDelete (id)) { /// \todo handle info records @@ -535,7 +542,9 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) } else { + int index = mTopics.getAppendIndex (id); mTopics.load (record, base); + dialogue = &mTopics.getRecord (index).get(); } break; @@ -543,14 +552,25 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) case ESM::REC_INFO: { - /// \todo associate info record with last loaded dialogue record - mJournalInfos.load (reader, base); + if (!dialogue) + { + /// \todo INFO record without matching DIAL record -> report to user + reader.skipRecord(); + break; + } + + if (dialogue->mType==ESM::Dialogue::Journal) + mJournalInfos.load (reader, base, *dialogue); + else + mTopicInfos.load (reader, base, *dialogue); + break; } default: /// \todo throw an exception instead, once all records are implemented + /// or maybe report error and continue? reader.skipRecord(); } } diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 858f788fa..42425ecf5 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -30,7 +30,7 @@ void CSMWorld::InfoCollection::load (const ESM::DialInfo& record, bool base) } } -void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base) +void CSMWorld::InfoCollection::load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue) { /// \todo put records into proper order /// \todo adjust ID diff --git a/apps/opencs/model/world/infocollection.hpp b/apps/opencs/model/world/infocollection.hpp index 8dca2b219..8bb8e5309 100644 --- a/apps/opencs/model/world/infocollection.hpp +++ b/apps/opencs/model/world/infocollection.hpp @@ -5,6 +5,11 @@ #include "collection.hpp" +namespace ESM +{ + class Dialogue; +} + namespace CSMWorld { class InfoCollection : public Collection > @@ -13,7 +18,7 @@ namespace CSMWorld public: - void load (ESM::ESMReader& reader, bool base); + void load (ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue); }; }