mirror of https://github.com/OpenMW/openmw.git
Assign StringRefIds to attributes
parent
11ae1a1fcb
commit
e660a9ca16
@ -1,25 +1,56 @@
|
||||
#include "attr.hpp"
|
||||
#include <components/misc/strings/algorithm.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace ESM;
|
||||
#include <components/esm3/esmreader.hpp>
|
||||
#include <components/esm3/esmwriter.hpp>
|
||||
|
||||
const std::string Attribute::sAttributeNames[Attribute::Length] = {
|
||||
"Strength",
|
||||
"Intelligence",
|
||||
"Willpower",
|
||||
"Agility",
|
||||
"Speed",
|
||||
"Endurance",
|
||||
"Personality",
|
||||
"Luck",
|
||||
};
|
||||
#include <stdexcept>
|
||||
|
||||
Attribute::AttributeID Attribute::stringToAttributeId(std::string_view attribute)
|
||||
namespace ESM
|
||||
{
|
||||
for (int id = 0; id < Attribute::Length; ++id)
|
||||
if (Misc::StringUtils::ciEqual(sAttributeNames[id], attribute))
|
||||
return Attribute::AttributeID(id);
|
||||
const Attribute::AttributeID Attribute::Strength("Strength");
|
||||
const Attribute::AttributeID Attribute::Intelligence("Intelligence");
|
||||
const Attribute::AttributeID Attribute::Willpower("Willpower");
|
||||
const Attribute::AttributeID Attribute::Agility("Agility");
|
||||
const Attribute::AttributeID Attribute::Speed("Speed");
|
||||
const Attribute::AttributeID Attribute::Endurance("Endurance");
|
||||
const Attribute::AttributeID Attribute::Personality("Personality");
|
||||
const Attribute::AttributeID Attribute::Luck("Luck");
|
||||
|
||||
static const RefId sAttributes[Attribute::Length] = {
|
||||
Attribute::Strength,
|
||||
Attribute::Intelligence,
|
||||
Attribute::Willpower,
|
||||
Attribute::Agility,
|
||||
Attribute::Speed,
|
||||
Attribute::Endurance,
|
||||
Attribute::Personality,
|
||||
Attribute::Luck,
|
||||
};
|
||||
|
||||
RefId Attribute::indexToRefId(int index)
|
||||
{
|
||||
if (index < 0 || index >= Length)
|
||||
return RefId();
|
||||
return sAttributes[index];
|
||||
}
|
||||
|
||||
int Attribute::refIdToIndex(RefId id)
|
||||
{
|
||||
for (int i = 0; i < Length; ++i)
|
||||
{
|
||||
if (sAttributes[i] == id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Attribute::load(ESMReader& esm, bool& isDeleted)
|
||||
{
|
||||
throw std::runtime_error("Attribute loading not yet implemented");
|
||||
}
|
||||
|
||||
throw std::logic_error("No such attribute: " + std::string(attribute));
|
||||
void Attribute::save(ESMWriter& esm, bool isDeleted) const
|
||||
{
|
||||
throw std::runtime_error("Attribute saving not yet implemented");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue