Replace Skill::mIndex with Skill::refIdToIndex

This commit is contained in:
Evil Eye 2023-06-15 20:49:14 +02:00
parent 3a1ae9df58
commit ac9378fa08
12 changed files with 49 additions and 35 deletions

View file

@ -53,13 +53,14 @@ namespace ESM
bool hasIndex = false;
bool hasData = false;
int index = -1;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().toInt())
{
case fourCC("INDX"):
esm.getHT(mIndex);
esm.getHT(index);
hasIndex = true;
break;
case fourCC("SKDT"):
@ -75,19 +76,19 @@ namespace ESM
}
if (!hasIndex)
esm.fail("Missing INDX");
else if (mIndex < 0 || mIndex >= Length)
else if (index < 0 || index >= Length)
esm.fail("Invalid INDX");
if (!hasData)
esm.fail("Missing SKDT");
// create an ID from the index and the name (only used in the editor and likely to change in the
// future)
mId = indexToRefId(mIndex);
mId = indexToRefId(index);
}
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const
{
esm.writeHNT("INDX", mIndex);
esm.writeHNT("INDX", refIdToIndex(mId));
esm.writeHNT("SKDT", mData, 24);
esm.writeHNOString("DESC", mDescription);
}
@ -108,6 +109,16 @@ namespace ESM
return RefId::index(sRecordId, static_cast<std::uint32_t>(index));
}
int Skill::refIdToIndex(RefId id)
{
if (const IndexRefId* index = id.getIf<IndexRefId>())
{
if (index->getRecordType() == sRecordId)
return index->getValue();
}
return -1;
}
const std::array<RefId, MagicSchool::Length> sMagicSchools = {
Skill::Alteration,
Skill::Conjuration,

View file

@ -55,11 +55,6 @@ namespace ESM
}; // Total size: 24 bytes
SKDTstruct mData;
// Skill index. Skils don't have an id ("NAME") like most records,
// they only have a numerical index that matches one of the
// hard-coded skills in the game.
int mIndex{ -1 };
std::string mDescription;
std::string mName;
std::string mIcon;
@ -105,6 +100,7 @@ namespace ESM
///< Set record to default state (does not touch the ID/index).
static RefId indexToRefId(int index);
static int refIdToIndex(RefId id);
};
}
#endif