1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-19 15:09:43 +00:00

Only allow StringRefId for Skill ids

This commit is contained in:
Evil Eye 2023-07-14 17:33:32 +02:00
parent f7be94aa21
commit cd8f2355c0
5 changed files with 68 additions and 60 deletions
apps
opencs/model
openmw/mwlua
components/esm3

View file

@ -204,7 +204,7 @@ void CSMDoc::Document::createBase()
for (int i = 0; i < ESM::Skill::Length; ++i) for (int i = 0; i < ESM::Skill::Length; ++i)
{ {
ESM::Skill record; ESM::Skill record;
record.mId = ESM::Skill::indexToRefId(i); record.mId = *ESM::Skill::indexToRefId(i).getIf<ESM::SkillId>();
record.blank(); record.blank();
getData().getSkills().add(record); getData().getSkills().add(record);

View file

@ -15,6 +15,7 @@
#include <QVariant> #include <QVariant>
#include <components/esm3/loaddial.hpp> #include <components/esm3/loaddial.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include "collectionbase.hpp" #include "collectionbase.hpp"
@ -86,6 +87,13 @@ namespace CSMWorld
return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex)); return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex));
} }
inline void setRecordId(const ESM::RefId& id, ESM::Skill& record)
{
if (const auto* skillId = id.getIf<ESM::SkillId>())
record.mId = *skillId;
throw std::runtime_error("Invalid skill id: " + id.toDebugString());
}
/// \brief Single-type record collection /// \brief Single-type record collection
template <typename ESXRecordT> template <typename ESXRecordT>
class Collection : public CollectionBase class Collection : public CollectionBase

View file

@ -392,6 +392,6 @@ namespace MWLua
sol::table skills(context.mLua->sol(), sol::create); sol::table skills(context.mLua->sol(), sol::create);
npcStats["skills"] = LuaUtil::makeReadOnly(skills); npcStats["skills"] = LuaUtil::makeReadOnly(skills);
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>()) for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
skills[skill.mId.serializeText()] = addIndexedAccessor<SkillStat>(skill.mId); skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
} }
} }

View file

@ -7,33 +7,33 @@
namespace ESM namespace ESM
{ {
const RefId Skill::Block = RefId::stringRefId("Block"); const SkillId Skill::Block("Block");
const RefId Skill::Armorer = RefId::stringRefId("Armorer"); const SkillId Skill::Armorer("Armorer");
const RefId Skill::MediumArmor = RefId::stringRefId("MediumArmor"); const SkillId Skill::MediumArmor("MediumArmor");
const RefId Skill::HeavyArmor = RefId::stringRefId("HeavyArmor"); const SkillId Skill::HeavyArmor("HeavyArmor");
const RefId Skill::BluntWeapon = RefId::stringRefId("BluntWeapon"); const SkillId Skill::BluntWeapon("BluntWeapon");
const RefId Skill::LongBlade = RefId::stringRefId("LongBlade"); const SkillId Skill::LongBlade("LongBlade");
const RefId Skill::Axe = RefId::stringRefId("Axe"); const SkillId Skill::Axe("Axe");
const RefId Skill::Spear = RefId::stringRefId("Spear"); const SkillId Skill::Spear("Spear");
const RefId Skill::Athletics = RefId::stringRefId("Athletics"); const SkillId Skill::Athletics("Athletics");
const RefId Skill::Enchant = RefId::stringRefId("Enchant"); const SkillId Skill::Enchant("Enchant");
const RefId Skill::Destruction = RefId::stringRefId("Destruction"); const SkillId Skill::Destruction("Destruction");
const RefId Skill::Alteration = RefId::stringRefId("Alteration"); const SkillId Skill::Alteration("Alteration");
const RefId Skill::Illusion = RefId::stringRefId("Illusion"); const SkillId Skill::Illusion("Illusion");
const RefId Skill::Conjuration = RefId::stringRefId("Conjuration"); const SkillId Skill::Conjuration("Conjuration");
const RefId Skill::Mysticism = RefId::stringRefId("Mysticism"); const SkillId Skill::Mysticism("Mysticism");
const RefId Skill::Restoration = RefId::stringRefId("Restoration"); const SkillId Skill::Restoration("Restoration");
const RefId Skill::Alchemy = RefId::stringRefId("Alchemy"); const SkillId Skill::Alchemy("Alchemy");
const RefId Skill::Unarmored = RefId::stringRefId("Unarmored"); const SkillId Skill::Unarmored("Unarmored");
const RefId Skill::Security = RefId::stringRefId("Security"); const SkillId Skill::Security("Security");
const RefId Skill::Sneak = RefId::stringRefId("Sneak"); const SkillId Skill::Sneak("Sneak");
const RefId Skill::Acrobatics = RefId::stringRefId("Acrobatics"); const SkillId Skill::Acrobatics("Acrobatics");
const RefId Skill::LightArmor = RefId::stringRefId("LightArmor"); const SkillId Skill::LightArmor("LightArmor");
const RefId Skill::ShortBlade = RefId::stringRefId("ShortBlade"); const SkillId Skill::ShortBlade("ShortBlade");
const RefId Skill::Marksman = RefId::stringRefId("Marksman"); const SkillId Skill::Marksman("Marksman");
const RefId Skill::Mercantile = RefId::stringRefId("Mercantile"); const SkillId Skill::Mercantile("Mercantile");
const RefId Skill::Speechcraft = RefId::stringRefId("Speechcraft"); const SkillId Skill::Speechcraft("Speechcraft");
const RefId Skill::HandToHand = RefId::stringRefId("HandToHand"); const SkillId Skill::HandToHand("HandToHand");
void Skill::load(ESMReader& esm, bool& isDeleted) void Skill::load(ESMReader& esm, bool& isDeleted)
{ {
@ -70,9 +70,7 @@ namespace ESM
if (!hasData) if (!hasData)
esm.fail("Missing SKDT"); esm.fail("Missing SKDT");
// create an ID from the index and the name (only used in the editor and likely to change in the mId = *indexToRefId(index).getIf<SkillId>();
// future)
mId = indexToRefId(index);
} }
void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const

View file

@ -14,6 +14,8 @@ namespace ESM
class ESMReader; class ESMReader;
class ESMWriter; class ESMWriter;
using SkillId = StringRefId;
struct MagicSchool struct MagicSchool
{ {
ESM::RefId mAreaSound; ESM::RefId mAreaSound;
@ -43,7 +45,7 @@ namespace ESM
static std::string_view getRecordType() { return "Skill"; } static std::string_view getRecordType() { return "Skill"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
RefId mId; SkillId mId;
struct SKDTstruct struct SKDTstruct
{ {
@ -61,33 +63,33 @@ namespace ESM
float mWerewolfValue{}; float mWerewolfValue{};
std::optional<MagicSchool> mSchool; std::optional<MagicSchool> mSchool;
static const RefId Block; static const SkillId Block;
static const RefId Armorer; static const SkillId Armorer;
static const RefId MediumArmor; static const SkillId MediumArmor;
static const RefId HeavyArmor; static const SkillId HeavyArmor;
static const RefId BluntWeapon; static const SkillId BluntWeapon;
static const RefId LongBlade; static const SkillId LongBlade;
static const RefId Axe; static const SkillId Axe;
static const RefId Spear; static const SkillId Spear;
static const RefId Athletics; static const SkillId Athletics;
static const RefId Enchant; static const SkillId Enchant;
static const RefId Destruction; static const SkillId Destruction;
static const RefId Alteration; static const SkillId Alteration;
static const RefId Illusion; static const SkillId Illusion;
static const RefId Conjuration; static const SkillId Conjuration;
static const RefId Mysticism; static const SkillId Mysticism;
static const RefId Restoration; static const SkillId Restoration;
static const RefId Alchemy; static const SkillId Alchemy;
static const RefId Unarmored; static const SkillId Unarmored;
static const RefId Security; static const SkillId Security;
static const RefId Sneak; static const SkillId Sneak;
static const RefId Acrobatics; static const SkillId Acrobatics;
static const RefId LightArmor; static const SkillId LightArmor;
static const RefId ShortBlade; static const SkillId ShortBlade;
static const RefId Marksman; static const SkillId Marksman;
static const RefId Mercantile; static const SkillId Mercantile;
static const RefId Speechcraft; static const SkillId Speechcraft;
static const RefId HandToHand; static const SkillId HandToHand;
static constexpr int Length = 27; static constexpr int Length = 27;
void load(ESMReader& esm, bool& isDeleted); void load(ESMReader& esm, bool& isDeleted);