1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-15 12:36:44 +00:00

Fix handling deleted DIAL records

* Use composite RefId to remove INFO record of deleted DIAL record. OrderedInfo
  stores original RefId while InfoCollection stores composite one.
* Do not erase deleted topic from InfoOrderByTopic map. To keep all deleted
  record ids for InfoCollection::sort call to make sure reorderRowsImp is called
  with correct number of indices.
This commit is contained in:
elsid 2023-06-01 23:08:47 +02:00
parent 8e3e351015
commit 6a3b6c6e4f
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
3 changed files with 13 additions and 12 deletions

View file

@ -73,17 +73,18 @@ namespace CSMWorld
for (const OrderedInfo& info : topicInfoOrder->second.getOrderedInfo()) for (const OrderedInfo& info : topicInfoOrder->second.getOrderedInfo())
{ {
const Record<Info>& record = infoCollection.getRecord(info.mId); const ESM::RefId id = makeCompositeInfoRefId(dialogueId, info.mId);
const Record<Info>& record = infoCollection.getRecord(id);
if (record.mState == RecordBase::State_ModifiedOnly) if (record.mState == RecordBase::State_ModifiedOnly)
{ {
erasedRecords.push_back(infoCollection.searchId(info.mId)); erasedRecords.push_back(infoCollection.searchId(id));
continue; continue;
} }
auto deletedRecord = std::make_unique<Record<Info>>(record); auto deletedRecord = std::make_unique<Record<Info>>(record);
deletedRecord->mState = RecordBase::State_Deleted; deletedRecord->mState = RecordBase::State_Deleted;
infoCollection.setRecord(infoCollection.searchId(info.mId), std::move(deletedRecord)); infoCollection.setRecord(infoCollection.searchId(id), std::move(deletedRecord));
} }
while (!erasedRecords.empty()) while (!erasedRecords.empty())
@ -91,8 +92,6 @@ namespace CSMWorld
infoCollection.removeRows(erasedRecords.back(), 1); infoCollection.removeRows(erasedRecords.back(), 1);
erasedRecords.pop_back(); erasedRecords.pop_back();
} }
infoOrders.erase(topicInfoOrder);
} }
} }
} }

View file

@ -18,16 +18,16 @@ namespace CSMWorld
{ {
namespace namespace
{ {
ESM::RefId makeCompositeRefId(const ESM::RefId& topicId, const ESM::RefId& infoId)
{
return ESM::RefId::stringRefId(topicId.getRefIdString() + '#' + infoId.getRefIdString());
}
std::string_view getInfoTopicId(const ESM::RefId& infoId) std::string_view getInfoTopicId(const ESM::RefId& infoId)
{ {
return parseInfoRefId(infoId).first; return parseInfoRefId(infoId).first;
} }
} }
ESM::RefId makeCompositeInfoRefId(const ESM::RefId& topicId, const ESM::RefId& infoId)
{
return ESM::RefId::stringRefId(topicId.getRefIdString() + '#' + infoId.getRefIdString());
}
} }
void CSMWorld::InfoCollection::load(const Info& value, bool base) void CSMWorld::InfoCollection::load(const Info& value, bool base)
@ -65,7 +65,7 @@ void CSMWorld::InfoCollection::load(
info.load(reader, isDeleted); info.load(reader, isDeleted);
const ESM::RefId id = makeCompositeRefId(dialogue.mId, info.mId); const ESM::RefId id = makeCompositeInfoRefId(dialogue.mId, info.mId);
if (isDeleted) if (isDeleted)
{ {
@ -107,7 +107,7 @@ void CSMWorld::InfoCollection::sort(const InfoOrderByTopic& infoOrders)
order.reserve(getSize()); order.reserve(getSize());
for (const auto& [topicId, infoOrder] : infoOrders) for (const auto& [topicId, infoOrder] : infoOrders)
for (const OrderedInfo& info : infoOrder.getOrderedInfo()) for (const OrderedInfo& info : infoOrder.getOrderedInfo())
order.push_back(getIndex(makeCompositeRefId(topicId, info.mId))); order.push_back(getIndex(makeCompositeInfoRefId(topicId, info.mId)));
reorderRowsImp(order); reorderRowsImp(order);
} }

View file

@ -55,6 +55,8 @@ namespace CSMWorld
bool reorderRows(int baseIndex, const std::vector<int>& newOrder) override; bool reorderRows(int baseIndex, const std::vector<int>& newOrder) override;
}; };
ESM::RefId makeCompositeInfoRefId(const ESM::RefId& topicId, const ESM::RefId& infoId);
} }
#endif #endif