From 3b85d970872afc58954c1f5b9e3ec2951b5a2fb5 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 21 Oct 2013 15:38:13 +0200 Subject: [PATCH] handle deleted dialogue records --- apps/opencs/model/world/data.cpp | 13 +++++++++- apps/opencs/model/world/idcollection.hpp | 32 +++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index c854711b1..130ce334f 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -493,7 +493,18 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) } else if (record.mType==ESM::Dialogue::Deleted) { - /// \todo handle deleted records + if (mJournals.tryDelete (id)) + { + /// \todo handle info records + } + else if (mTopics.tryDelete (id)) + { + /// \todo handle info records + } + else + { + /// \todo report deletion of non-existing record + } } else { diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index b6ae04572..0d723bef1 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -7,7 +7,6 @@ namespace CSMWorld { - /// \brief Single type collection of top level records template > class IdCollection : public Collection @@ -17,6 +16,11 @@ namespace CSMWorld void load (ESM::ESMReader& reader, bool base); void load (const ESXRecordT& record, bool base); + + bool tryDelete (const std::string& id); + ///< Try deleting \a id. If the id does not exist or can't be deleted the call is ignored. + /// + /// \return Has the ID been deleted? }; template @@ -86,6 +90,32 @@ namespace CSMWorld this->setRecord (index, record2); } } + + template + bool IdCollection::tryDelete (const std::string& id) + { + int index = this->searchId (id); + + if (index==-1) + return false; + + Record record = Collection::getRecord (index); + + if (record.isDeleted()) + return false; + + if (record.mState==RecordBase::State_ModifiedOnly) + { + Collection::removeRows (index, 1); + } + else + { + record.mState = RecordBase::State_Deleted; + setRecord (index, record); + } + + return true; + } } #endif