From af59106533590aee1360f708f44b72a3c2a453ba Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 30 Jun 2014 12:35:34 +0200 Subject: [PATCH] for regular IdCollections when loading a record make the record a copy of the existing record first (adresses some incomplete records in some content files) --- apps/opencs/model/world/idcollection.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index a7b37be5bc..7e7756ff3e 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -15,7 +15,10 @@ namespace CSMWorld void load (ESM::ESMReader& reader, bool base); - void load (const ESXRecordT& record, bool base); + /// \param index Index at which the record can be found. + /// Special values: -2 index unknown, -1 record does not exist yet and therefore + /// does not have an index + void load (const ESXRecordT& record, bool base, int index = -2); 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. @@ -56,17 +59,28 @@ namespace CSMWorld else { ESXRecordT record; - IdAccessorT().getId (record) = id; + + int index = this->searchId (id); + + if (index==-1) + IdAccessorT().getId (record) = id; + else + { + record = this->getRecord (index).get(); + } + record.load (reader); - load (record, base); + load (record, base, index); } } template - void IdCollection::load (const ESXRecordT& record, bool base) + void IdCollection::load (const ESXRecordT& record, bool base, + int index) { - int index = this->searchId (IdAccessorT().getId (record)); + if (index==-2) + index = this->searchId (IdAccessorT().getId (record)); if (index==-1) {