From 14600de185acb24646a3b80c24c8ef6940adad20 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 27 May 2023 21:54:13 +0200 Subject: [PATCH] Remove sAttributeIds and sSkillIds --- apps/openmw/mwgui/charactercreation.cpp | 9 +++++---- apps/openmw/mwgui/class.cpp | 15 ++++++++------- apps/openmw/mwgui/review.cpp | 20 +++++++++++--------- apps/openmw/mwgui/statswindow.cpp | 7 ++++--- apps/openmw/mwworld/store.cpp | 2 +- components/esm/attr.cpp | 15 ++------------- components/esm/attr.hpp | 1 - components/esm3/loadskil.cpp | 8 ++------ components/esm3/loadskil.hpp | 1 - 9 files changed, 33 insertions(+), 45 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 257c01d996..e0ac94db93 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -94,11 +94,12 @@ namespace MWGui mGenerateClassSpecializations[2] = 0; // Setup player stats - for (int i = 0; i < ESM::Attribute::Length; ++i) - mPlayerAttributes.emplace(ESM::Attribute::sAttributeIds[i], MWMechanics::AttributeValue()); + const auto& store = MWBase::Environment::get().getWorld()->getStore(); + for (const ESM::Attribute& attribute : store.get()) + mPlayerAttributes.emplace(attribute.mId, MWMechanics::AttributeValue()); - for (int i = 0; i < ESM::Skill::Length; ++i) - mPlayerSkillValues.emplace(ESM::Skill::sSkillIds[i], MWMechanics::SkillValue()); + for (const auto& skill : store.get()) + mPlayerSkillValues.emplace(skill.second.mIndex, MWMechanics::SkillValue()); } void CharacterCreation::setValue(std::string_view id, const MWMechanics::AttributeValue& value) diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 68c1465743..864740aac5 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -745,15 +745,16 @@ namespace MWGui // Centre dialog center(); - for (int i = 0; i < 8; ++i) + const auto& store = MWBase::Environment::get().getWorld()->getStore().get(); + for (const ESM::Attribute& attribute : store) { - Widgets::MWAttributePtr attribute; - char theIndex = '0' + i; + Widgets::MWAttributePtr widget; + char theIndex = '0' + attribute.mId; - getWidget(attribute, std::string("Attribute").append(1, theIndex)); - attribute->setAttributeId(ESM::Attribute::sAttributeIds[i]); - attribute->eventClicked += MyGUI::newDelegate(this, &SelectAttributeDialog::onAttributeClicked); - ToolTips::createAttributeToolTip(attribute, attribute->getAttributeId()); + getWidget(widget, std::string("Attribute").append(1, theIndex)); + widget->setAttributeId(attribute.mId); + widget->eventClicked += MyGUI::newDelegate(this, &SelectAttributeDialog::onAttributeClicked); + ToolTips::createAttributeToolTip(widget, widget->getAttributeId()); } MyGUI::Button* cancelButton; diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index 7fe59d7a32..b4251df3bc 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -76,13 +76,14 @@ namespace MWGui // Setup attributes - Widgets::MWAttributePtr attribute; - for (int idx = 0; idx < ESM::Attribute::Length; ++idx) + Widgets::MWAttributePtr widget; + const auto& store = MWBase::Environment::get().getWorld()->getStore().get(); + for (const ESM::Attribute& attribute : store) { - getWidget(attribute, std::string("Attribute") + MyGUI::utility::toString(idx)); - mAttributeWidgets.insert(std::make_pair(static_cast(ESM::Attribute::sAttributeIds[idx]), attribute)); - attribute->setAttributeId(ESM::Attribute::sAttributeIds[idx]); - attribute->setAttributeValue(Widgets::MWAttribute::AttributeValue()); + getWidget(widget, std::string("Attribute").append(1, '0' + attribute.mId)); + mAttributeWidgets.emplace(attribute.mId, widget); + widget->setAttributeId(attribute.mId); + widget->setAttributeValue(Widgets::MWAttribute::AttributeValue()); } // Setup skills @@ -234,10 +235,11 @@ namespace MWGui std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin())); std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin())); mMiscSkills.clear(); - for (const int skill : ESM::Skill::sSkillIds) + const auto& store = MWBase::Environment::get().getWorld()->getStore().get(); + for (const auto& skill : store) { - if (skillSet.find(skill) == skillSet.end()) - mMiscSkills.push_back(skill); + if (!skillSet.contains(skill.second.mIndex)) + mMiscSkills.push_back(skill.second.mIndex); } mUpdateSkillArea = true; diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index c0789eaf2b..b93146f5f1 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -324,10 +324,11 @@ namespace MWGui std::copy(major.begin(), major.end(), std::inserter(skillSet, skillSet.begin())); std::copy(minor.begin(), minor.end(), std::inserter(skillSet, skillSet.begin())); mMiscSkills.clear(); - for (const int skill : ESM::Skill::sSkillIds) + const auto& store = MWBase::Environment::get().getWorld()->getStore().get(); + for (const auto& skill : store) { - if (skillSet.find(skill) == skillSet.end()) - mMiscSkills.push_back(skill); + if (!skillSet.contains(skill.second.mIndex)) + mMiscSkills.push_back(skill.second.mIndex); } updateSkillArea(); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index e2bd7cafb2..0074e8cfb6 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -951,7 +951,7 @@ namespace MWWorld for (int i = 0; i < ESM::Attribute::Length; ++i) { ESM::Attribute newAttribute; - newAttribute.mId = ESM::Attribute::sAttributeIds[i]; + newAttribute.mId = ESM::Attribute::AttributeID(i); newAttribute.mName = ESM::Attribute::sGmstAttributeIds[i]; newAttribute.mDescription = ESM::Attribute::sGmstAttributeDescIds[i]; mStatic.push_back(newAttribute); diff --git a/components/esm/attr.cpp b/components/esm/attr.cpp index fef14e0c1a..cb4e94b773 100644 --- a/components/esm/attr.cpp +++ b/components/esm/attr.cpp @@ -4,17 +4,6 @@ using namespace ESM; -const Attribute::AttributeID Attribute::sAttributeIds[Attribute::Length] = { - Attribute::Strength, - Attribute::Intelligence, - Attribute::Willpower, - Attribute::Agility, - Attribute::Speed, - Attribute::Endurance, - Attribute::Personality, - Attribute::Luck, -}; - const std::string Attribute::sAttributeNames[Attribute::Length] = { "Strength", "Intelligence", @@ -61,9 +50,9 @@ const std::string Attribute::sAttributeIcons[Attribute::Length] = { Attribute::AttributeID Attribute::stringToAttributeId(std::string_view attribute) { - for (auto id : sAttributeIds) + for (int id = 0; id < Attribute::Length; ++id) if (Misc::StringUtils::ciEqual(sAttributeNames[id], attribute)) - return id; + return Attribute::AttributeID(id); throw std::logic_error("No such attribute: " + std::string(attribute)); } diff --git a/components/esm/attr.hpp b/components/esm/attr.hpp index dd8321c5be..2d643e2e1b 100644 --- a/components/esm/attr.hpp +++ b/components/esm/attr.hpp @@ -28,7 +28,6 @@ namespace ESM AttributeID mId; std::string mName, mDescription; - static const AttributeID sAttributeIds[Length]; static const std::string sAttributeNames[Length]; static const std::string sGmstAttributeIds[Length]; static const std::string sGmstAttributeDescIds[Length]; diff --git a/components/esm3/loadskil.cpp b/components/esm3/loadskil.cpp index 47bfbbbda8..ec110702b6 100644 --- a/components/esm3/loadskil.cpp +++ b/components/esm3/loadskil.cpp @@ -94,16 +94,12 @@ namespace ESM "stealth_speechcraft.dds", "stealth_handtohand.dds", }; - const std::array Skill::sSkillIds - = { { Block, Armorer, MediumArmor, HeavyArmor, BluntWeapon, LongBlade, Axe, Spear, Athletics, Enchant, - Destruction, Alteration, Illusion, Conjuration, Mysticism, Restoration, Alchemy, Unarmored, Security, Sneak, - Acrobatics, LightArmor, ShortBlade, Marksman, Mercantile, Speechcraft, HandToHand } }; Skill::SkillEnum Skill::stringToSkillId(std::string_view skill) { - for (auto id : sSkillIds) + for (int id = 0; id < Skill::Length; ++id) if (Misc::StringUtils::ciEqual(sSkillNames[id], skill)) - return id; + return Skill::SkillEnum(id); throw std::logic_error("No such skill: " + std::string(skill)); } diff --git a/components/esm3/loadskil.hpp b/components/esm3/loadskil.hpp index d472706bcf..ce2d3bf531 100644 --- a/components/esm3/loadskil.hpp +++ b/components/esm3/loadskil.hpp @@ -79,7 +79,6 @@ namespace ESM static const std::string sSkillNames[Length]; static const std::string sSkillNameIds[Length]; static const std::string sIconNames[Length]; - static const std::array sSkillIds; static SkillEnum stringToSkillId(std::string_view skill);