From 2135eba10387955eedcadf7077ac3c020c62e45a Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 21 Mar 2023 20:44:42 +0100 Subject: [PATCH] Fix loading ESM3 QuickKeys --- apps/openmw_test_suite/esm3/testsaveload.cpp | 35 ++++++++++++++++++++ components/esm3/quickkeys.cpp | 4 +-- components/esm3/quickkeys.hpp | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/openmw_test_suite/esm3/testsaveload.cpp b/apps/openmw_test_suite/esm3/testsaveload.cpp index 2204b3fcec..fd6df2da3a 100644 --- a/apps/openmw_test_suite/esm3/testsaveload.cpp +++ b/apps/openmw_test_suite/esm3/testsaveload.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,11 @@ namespace ESM { return std::tie(value.mSound, value.mChance); } + + auto tie(const ESM::QuickKeys::QuickKey& value) + { + return std::tie(value.mType, value.mId); + } } inline bool operator==(const ESM::ContItem& lhs, const ESM::ContItem& rhs) @@ -50,6 +56,16 @@ namespace ESM << "}"; } + inline bool operator==(const ESM::QuickKeys::QuickKey& lhs, const ESM::QuickKeys::QuickKey& rhs) + { + return tie(lhs) == tie(rhs); + } + + inline std::ostream& operator<<(std::ostream& stream, const ESM::QuickKeys::QuickKey& value) + { + return stream << "ESM::QuickKeys::QuickKey {.mType = '" << value.mType << "', .mId = " << value.mId << "}"; + } + namespace { using namespace ::testing; @@ -291,6 +307,25 @@ namespace ESM EXPECT_EQ(result.mData.mNumShorts, record.mData.mNumShorts); } + TEST_P(Esm3SaveLoadRecordTest, quickKeysShouldNotChange) + { + const QuickKeys record { + .mKeys = { + { + .mType = 42, + .mId = generateRandomRefId(32), + }, + { + .mType = 13, + .mId = generateRandomRefId(32), + }, + }, + }; + QuickKeys result; + saveAndLoadRecord(record, GetParam(), result); + EXPECT_EQ(result.mKeys, record.mKeys); + } + INSTANTIATE_TEST_SUITE_P(FormatVersions, Esm3SaveLoadRecordTest, ValuesIn(formats)); } } diff --git a/components/esm3/quickkeys.cpp b/components/esm3/quickkeys.cpp index ec9c1ed307..84200836bd 100644 --- a/components/esm3/quickkeys.cpp +++ b/components/esm3/quickkeys.cpp @@ -15,12 +15,10 @@ namespace ESM { int keyType; esm.getHT(keyType); - std::string id; - id = esm.getHNString("ID__"); QuickKey key; key.mType = keyType; - key.mId = ESM::RefId::stringRefId(id); + key.mId = esm.getHNRefId("ID__"); mKeys.push_back(key); diff --git a/components/esm3/quickkeys.hpp b/components/esm3/quickkeys.hpp index 0a525efd75..91877fc7fc 100644 --- a/components/esm3/quickkeys.hpp +++ b/components/esm3/quickkeys.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_ESM_QUICKKEYS_H #include "components/esm/refid.hpp" + #include #include