mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 13:09:42 +00:00
Merge branch 'caius4friends' into 'master'
Fix dialogue insertion again See merge request OpenMW/openmw!3212
This commit is contained in:
commit
ec9b4c4563
3 changed files with 54 additions and 65 deletions
|
@ -328,7 +328,7 @@ namespace CSMWorld
|
|||
EXPECT_THAT(infoOrder.find(dialogue.mId)->second.getOrderedInfo(), ElementsAre(InfoId(info.mValue.mId)));
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldOrderRecordsBasedOnPrevAndNext)
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldOrderRecordsBasedOnPrev)
|
||||
{
|
||||
const DialogueData<ESM::DialInfo> data = generateDialogueWithInfos(3);
|
||||
|
||||
|
@ -345,7 +345,7 @@ namespace CSMWorld
|
|||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 2);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldOrderRecordsBasedOnPrevAndNextWhenReversed)
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldOrderRecordsBasedOnPrevWhenReversed)
|
||||
{
|
||||
DialogueData<ESM::DialInfo> data = generateDialogueWithInfos(3);
|
||||
|
||||
|
@ -360,8 +360,8 @@ namespace CSMWorld
|
|||
|
||||
EXPECT_EQ(collection.getSize(), 3);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info0")), 0);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info1")), 1);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 2);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 1);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info1")), 2);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldInsertNewRecordBasedOnPrev)
|
||||
|
@ -391,33 +391,6 @@ namespace CSMWorld
|
|||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 3);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldInsertNewRecordBasedOnNextWhenPrevIsNotFound)
|
||||
{
|
||||
const bool base = true;
|
||||
InfoOrderByTopic infoOrder;
|
||||
InfoCollection collection;
|
||||
|
||||
const DialogueData<ESM::DialInfo> data = generateDialogueWithInfos(3);
|
||||
|
||||
saveAndLoadDialogueWithInfos(data, base, collection, infoOrder);
|
||||
|
||||
ESM::DialInfo newInfo;
|
||||
newInfo.blank();
|
||||
newInfo.mId = ESM::RefId::stringRefId("newInfo");
|
||||
newInfo.mPrev = ESM::RefId::stringRefId("invalid");
|
||||
newInfo.mNext = data.mInfos[2].mId;
|
||||
|
||||
saveAndLoadDialogueWithInfos(data.mDialogue, std::array{ newInfo }, base, collection, infoOrder);
|
||||
|
||||
collection.sort(infoOrder);
|
||||
|
||||
EXPECT_EQ(collection.getSize(), 4);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info0")), 0);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info1")), 1);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#newInfo")), 2);
|
||||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 3);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldInsertNewRecordToFrontWhenPrevIsEmpty)
|
||||
{
|
||||
const bool base = true;
|
||||
|
@ -444,7 +417,7 @@ namespace CSMWorld
|
|||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 3);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldInsertNewRecordToBackWhenNextIsEmpty)
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldInsertNewRecordToBackWhenPrevIsNotFound)
|
||||
{
|
||||
const bool base = true;
|
||||
InfoOrderByTopic infoOrder;
|
||||
|
@ -539,7 +512,7 @@ namespace CSMWorld
|
|||
EXPECT_EQ(collection.searchId(ESM::RefId::stringRefId("dialogue#info2")), 0);
|
||||
}
|
||||
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldMoveToBackUpdatedRecordWhenNextIsEmpty)
|
||||
TEST(CSMWorldInfoCollectionTest, sortShouldMoveToBackUpdatedRecordWhenPrevIsNotFound)
|
||||
{
|
||||
const bool base = true;
|
||||
InfoOrderByTopic infoOrder;
|
||||
|
|
|
@ -692,7 +692,7 @@ namespace
|
|||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info1"), HasIdEqualTo("info2")));
|
||||
}
|
||||
|
||||
TEST(MWWorldStoreTest, shouldLoadDialogueWithInfosAndOrderWhenReversed)
|
||||
TEST(MWWorldStoreTest, shouldIgnoreNextWhenLoadingDialogueInfos)
|
||||
{
|
||||
DialogueData data = generateDialogueWithInfos(3);
|
||||
|
||||
|
@ -704,7 +704,7 @@ namespace
|
|||
|
||||
const ESM::Dialogue* dialogue = esmStore.get<ESM::Dialogue>().search(ESM::RefId::stringRefId("dialogue"));
|
||||
ASSERT_NE(dialogue, nullptr);
|
||||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info1"), HasIdEqualTo("info2")));
|
||||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info2"), HasIdEqualTo("info1")));
|
||||
}
|
||||
|
||||
TEST(MWWorldStoreTest, shouldLoadDialogueWithInfosInsertingNewRecordBasedOnPrev)
|
||||
|
@ -803,6 +803,7 @@ namespace
|
|||
|
||||
ESM::DialInfo updatedInfo = data.mInfos[0];
|
||||
updatedInfo.mPrev = data.mInfos[2].mId;
|
||||
updatedInfo.mActor = ESM::RefId::stringRefId("newActor");
|
||||
|
||||
loadEsmStore(1, saveDialogueWithInfos(data.mDialogue, std::array{ updatedInfo }), esmStore);
|
||||
|
||||
|
@ -811,6 +812,7 @@ namespace
|
|||
const ESM::Dialogue* dialogue = esmStore.get<ESM::Dialogue>().search(ESM::RefId::stringRefId("dialogue"));
|
||||
ASSERT_NE(dialogue, nullptr);
|
||||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info1"), HasIdEqualTo("info2"), HasIdEqualTo("info0")));
|
||||
EXPECT_EQ(std::prev(dialogue->mInfo.end())->mActor, "newActor");
|
||||
}
|
||||
|
||||
TEST(MWWorldStoreTest, shouldLoadDialogueWithInfosMovingBackwardExistingRecordBasedOnPrev)
|
||||
|
@ -822,6 +824,7 @@ namespace
|
|||
|
||||
ESM::DialInfo updatedInfo = data.mInfos[2];
|
||||
updatedInfo.mPrev = data.mInfos[0].mId;
|
||||
updatedInfo.mActor = ESM::RefId::stringRefId("newActor");
|
||||
|
||||
loadEsmStore(1, saveDialogueWithInfos(data.mDialogue, std::array{ updatedInfo }), esmStore);
|
||||
|
||||
|
@ -830,5 +833,32 @@ namespace
|
|||
const ESM::Dialogue* dialogue = esmStore.get<ESM::Dialogue>().search(ESM::RefId::stringRefId("dialogue"));
|
||||
ASSERT_NE(dialogue, nullptr);
|
||||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info0"), HasIdEqualTo("info2"), HasIdEqualTo("info1")));
|
||||
EXPECT_EQ(std::next(dialogue->mInfo.begin())->mActor, "newActor");
|
||||
}
|
||||
|
||||
TEST(MWWorldStoreTest, shouldPreservePositionWhenPrevIsTheSame)
|
||||
{
|
||||
const DialogueData data = generateDialogueWithInfos(3);
|
||||
|
||||
MWWorld::ESMStore esmStore;
|
||||
loadEsmStore(0, saveDialogueWithInfos(data.mDialogue, data.mInfos), esmStore);
|
||||
|
||||
ESM::DialInfo newInfo = data.mInfos[0];
|
||||
newInfo.mPrev = data.mInfos[2].mId;
|
||||
newInfo.mNext = {};
|
||||
|
||||
loadEsmStore(1, saveDialogueWithInfos(data.mDialogue, std::array{ newInfo }), esmStore);
|
||||
|
||||
newInfo = data.mInfos[1];
|
||||
newInfo.mResponse = "test";
|
||||
|
||||
loadEsmStore(2, saveDialogueWithInfos(data.mDialogue, std::array{ newInfo }), esmStore);
|
||||
|
||||
esmStore.setUp();
|
||||
|
||||
const ESM::Dialogue* dialogue = esmStore.get<ESM::Dialogue>().search(ESM::RefId::stringRefId("dialogue"));
|
||||
ASSERT_NE(dialogue, nullptr);
|
||||
EXPECT_THAT(dialogue->mInfo, ElementsAre(HasIdEqualTo("info1"), HasIdEqualTo("info2"), HasIdEqualTo("info0")));
|
||||
EXPECT_EQ(dialogue->mInfo.begin()->mResponse, "test");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,47 +24,33 @@ namespace ESM
|
|||
|
||||
auto it = mInfoPositions.find(value.mId);
|
||||
|
||||
if (it != mInfoPositions.end() && it->second.mPosition->mPrev == value.mPrev)
|
||||
if (it != mInfoPositions.end())
|
||||
{
|
||||
bool samePrev = it->second.mPosition->mPrev == value.mPrev;
|
||||
*it->second.mPosition = std::forward<V>(value);
|
||||
it->second.mDeleted = deleted;
|
||||
return;
|
||||
if (samePrev)
|
||||
return;
|
||||
}
|
||||
|
||||
if (it == mInfoPositions.end())
|
||||
else
|
||||
it = mInfoPositions.emplace(value.mId, Item{ .mPosition = mOrderedInfo.end(), .mDeleted = deleted })
|
||||
.first;
|
||||
|
||||
Item& item = it->second;
|
||||
|
||||
const auto insertOrSplice = [&](typename std::list<T>::const_iterator before) {
|
||||
if (item.mPosition == mOrderedInfo.end())
|
||||
item.mPosition = mOrderedInfo.insert(before, std::forward<V>(value));
|
||||
auto before = mOrderedInfo.begin();
|
||||
if (!value.mPrev.empty())
|
||||
{
|
||||
const auto prevIt = mInfoPositions.find(value.mPrev);
|
||||
if (prevIt != mInfoPositions.end())
|
||||
before = std::next(prevIt->second.mPosition);
|
||||
else
|
||||
mOrderedInfo.splice(before, mOrderedInfo, item.mPosition);
|
||||
};
|
||||
|
||||
if (value.mPrev.empty())
|
||||
{
|
||||
insertOrSplice(mOrderedInfo.begin());
|
||||
return;
|
||||
before = mOrderedInfo.end();
|
||||
}
|
||||
|
||||
const auto prevIt = mInfoPositions.find(value.mPrev);
|
||||
if (prevIt != mInfoPositions.end())
|
||||
{
|
||||
insertOrSplice(std::next(prevIt->second.mPosition));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto nextIt = mInfoPositions.find(value.mNext);
|
||||
if (nextIt != mInfoPositions.end())
|
||||
{
|
||||
insertOrSplice(nextIt->second.mPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
insertOrSplice(mOrderedInfo.end());
|
||||
if (item.mPosition == mOrderedInfo.end())
|
||||
item.mPosition = mOrderedInfo.insert(before, std::forward<V>(value));
|
||||
else
|
||||
mOrderedInfo.splice(before, mOrderedInfo, item.mPosition);
|
||||
}
|
||||
|
||||
void removeInfo(const RefId& infoRefId)
|
||||
|
|
Loading…
Reference in a new issue