1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 17:53:53 +00:00
openmw/apps/opencs/model/world/infocollection.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.3 KiB
C++
Raw Normal View History

#include "infocollection.hpp"
#include <memory>
#include <string>
#include <utility>
#include <components/debug/debuglog.hpp>
2022-10-19 17:02:00 +00:00
#include <components/esm3/loaddial.hpp>
#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
2022-05-29 11:25:17 +00:00
auto record2 = std::make_unique<Record<Info>>();
record2->mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
(base ? record2->mBase : record2->mModified) = record;
appendRecord(std::move(record2));
return true;
}
else
{
// old record
2022-05-29 11:25:17 +00:00
auto record2 = std::make_unique<Record<Info>>(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
{
2022-05-29 11:25:17 +00:00
auto record = std::make_unique<Record<Info>>(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);
}
}
2023-02-16 23:08:38 +00:00
CSMWorld::InfosRecordPtrByTopic CSMWorld::InfoCollection::getInfosByTopic() const
{
2023-02-16 23:08:38 +00:00
InfosRecordPtrByTopic result;
for (const std::unique_ptr<Record<Info>>& record : getRecords())
2023-02-16 23:08:38 +00:00
result[record->mBase.mTopicId].push_back(record.get());
return result;
}