#include "infocollection.hpp" #include #include #include #include #include #include "collection.hpp" #include "info.hpp" bool CSMWorld::InfoCollection::load(const Info& record, bool base) { int index = searchId(record.mId.getRefIdString()); if (index == -1) { // new record auto record2 = std::make_unique>(); record2->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; (base ? record2->mBase : record2->mModified) = record; appendRecord(std::move(record2)); return true; } else { // old record auto record2 = std::make_unique>(getRecord(index)); if (base) record2->mBase = record; else record2->setModified(record); setRecord(index, std::move(record2)); return false; } } void CSMWorld::InfoCollection::load( ESM::ESMReader& reader, bool base, const ESM::Dialogue& dialogue, InfosByTopic& infosByTopic) { Info info; bool isDeleted = false; info.load(reader, isDeleted); std::string id = dialogue.mId.getRefIdString() + "#" + info.mId.getRefIdString(); if (isDeleted) { int index = searchId(id); if (index == -1) { // deleting a record that does not exist // ignore it for now /// \todo report the problem to the user } else if (base) { removeRows(index, 1); } else { auto record = std::make_unique>(getRecord(index)); record->mState = RecordBase::State_Deleted; setRecord(index, std::move(record)); } } else { info.mTopicId = dialogue.mId; info.mOriginalId = info.mId; info.mId = ESM::RefId::stringRefId(id); if (load(info, base)) infosByTopic[dialogue.mId].push_back(info.mId); } } std::vector*> CSMWorld::InfoCollection::getTopicInfos(const ESM::RefId& topic) const { std::vector*> result; for (const std::unique_ptr>& record : getRecords()) if (record->mBase.mTopicId == topic) result.push_back(record.get()); return result; }