1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-06 13:15:35 +00:00

Fix loading ESM3 QuickKeys

This commit is contained in:
elsid 2023-03-21 20:44:42 +01:00
parent 4b5de083d8
commit 2135eba103
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
3 changed files with 37 additions and 3 deletions

View file

@ -5,6 +5,7 @@
#include <components/esm3/loadregn.hpp> #include <components/esm3/loadregn.hpp>
#include <components/esm3/loadscpt.hpp> #include <components/esm3/loadscpt.hpp>
#include <components/esm3/player.hpp> #include <components/esm3/player.hpp>
#include <components/esm3/quickkeys.hpp>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -27,6 +28,11 @@ namespace ESM
{ {
return std::tie(value.mSound, value.mChance); 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) 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 namespace
{ {
using namespace ::testing; using namespace ::testing;
@ -291,6 +307,25 @@ namespace ESM
EXPECT_EQ(result.mData.mNumShorts, record.mData.mNumShorts); 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)); INSTANTIATE_TEST_SUITE_P(FormatVersions, Esm3SaveLoadRecordTest, ValuesIn(formats));
} }
} }

View file

@ -15,12 +15,10 @@ namespace ESM
{ {
int keyType; int keyType;
esm.getHT(keyType); esm.getHT(keyType);
std::string id;
id = esm.getHNString("ID__");
QuickKey key; QuickKey key;
key.mType = keyType; key.mType = keyType;
key.mId = ESM::RefId::stringRefId(id); key.mId = esm.getHNRefId("ID__");
mKeys.push_back(key); mKeys.push_back(key);

View file

@ -2,6 +2,7 @@
#define OPENMW_COMPONENTS_ESM_QUICKKEYS_H #define OPENMW_COMPONENTS_ESM_QUICKKEYS_H
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include <string> #include <string>
#include <vector> #include <vector>