mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:59:54 +00:00
Convert setting value int to CollisionShapeType on initialization
This commit is contained in:
parent
47978dcb71
commit
86e5b94ef6
5 changed files with 54 additions and 5 deletions
|
@ -31,11 +31,21 @@ namespace
|
|||
comboBox.setCurrentIndex(value);
|
||||
}
|
||||
|
||||
void loadSettingInt(const Settings::SettingValue<DetourNavigator::CollisionShapeType>& value, QComboBox& comboBox)
|
||||
{
|
||||
comboBox.setCurrentIndex(static_cast<int>(value.get()));
|
||||
}
|
||||
|
||||
void saveSettingInt(const QComboBox& comboBox, Settings::SettingValue<int>& value)
|
||||
{
|
||||
value.set(comboBox.currentIndex());
|
||||
}
|
||||
|
||||
void saveSettingInt(const QComboBox& comboBox, Settings::SettingValue<DetourNavigator::CollisionShapeType>& value)
|
||||
{
|
||||
value.set(static_cast<DetourNavigator::CollisionShapeType>(comboBox.currentIndex()));
|
||||
}
|
||||
|
||||
void loadSettingInt(const Settings::SettingValue<int>& value, QSpinBox& spinBox)
|
||||
{
|
||||
spinBox.setValue(value);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef OPENMW_COMPONENTS_SETTINGS_CATEGORIES_GAME_H
|
||||
#define OPENMW_COMPONENTS_SETTINGS_CATEGORIES_GAME_H
|
||||
|
||||
#include "components/detournavigator/collisionshapetype.hpp"
|
||||
#include "components/settings/sanitizerimpl.hpp"
|
||||
#include "components/settings/settingvalue.hpp"
|
||||
|
||||
|
@ -69,8 +70,8 @@ namespace Settings
|
|||
SettingValue<bool> mDayNightSwitches{ mIndex, "Game", "day night switches" };
|
||||
SettingValue<bool> mUnarmedCreatureAttacksDamageArmor{ mIndex, "Game",
|
||||
"unarmed creature attacks damage armor" };
|
||||
SettingValue<int> mActorCollisionShapeType{ mIndex, "Game", "actor collision shape type",
|
||||
makeEnumSanitizerInt({ 0, 1, 2 }) };
|
||||
SettingValue<DetourNavigator::CollisionShapeType> mActorCollisionShapeType{ mIndex, "Game",
|
||||
"actor collision shape type" };
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -444,6 +444,11 @@ namespace Settings
|
|||
setVector3(setting, category, value);
|
||||
}
|
||||
|
||||
void Manager::set(std::string_view setting, std::string_view category, DetourNavigator::CollisionShapeType value)
|
||||
{
|
||||
setInt(setting, category, static_cast<int>(value));
|
||||
}
|
||||
|
||||
void Manager::recordInit(std::string_view setting, std::string_view category)
|
||||
{
|
||||
sInitialized.emplace(category, setting);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "categories.hpp"
|
||||
|
||||
#include "components/detournavigator/collisionshapetype.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -101,6 +103,7 @@ namespace Settings
|
|||
static void set(std::string_view setting, std::string_view category, bool value);
|
||||
static void set(std::string_view setting, std::string_view category, const osg::Vec2f& value);
|
||||
static void set(std::string_view setting, std::string_view category, const osg::Vec3f& value);
|
||||
static void set(std::string_view setting, std::string_view category, DetourNavigator::CollisionShapeType value);
|
||||
|
||||
private:
|
||||
static std::set<std::pair<std::string_view, std::string_view>> sInitialized;
|
||||
|
@ -170,6 +173,13 @@ namespace Settings
|
|||
{
|
||||
return getVector3(setting, category);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline DetourNavigator::CollisionShapeType Manager::getImpl<DetourNavigator::CollisionShapeType>(
|
||||
std::string_view setting, std::string_view category)
|
||||
{
|
||||
return DetourNavigator::toCollisionShapeType(getInt(setting, category));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // COMPONENTS_SETTINGS_H
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "settings.hpp"
|
||||
|
||||
#include "components/debug/debuglog.hpp"
|
||||
#include "components/detournavigator/collisionshapetype.hpp"
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
|
@ -31,10 +32,11 @@ namespace Settings
|
|||
String,
|
||||
Vec2f,
|
||||
Vec3f,
|
||||
CollisionShapeType,
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr SettingValueType getSettingValueType();
|
||||
constexpr SettingValueType getSettingValueType() = delete;
|
||||
|
||||
template <>
|
||||
inline constexpr SettingValueType getSettingValueType<bool>()
|
||||
|
@ -108,6 +110,12 @@ namespace Settings
|
|||
return SettingValueType::Vec3f;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline constexpr SettingValueType getSettingValueType<DetourNavigator::CollisionShapeType>()
|
||||
{
|
||||
return SettingValueType::CollisionShapeType;
|
||||
}
|
||||
|
||||
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -136,6 +144,8 @@ namespace Settings
|
|||
return "vec2f";
|
||||
case SettingValueType::Vec3f:
|
||||
return "vec3f";
|
||||
case SettingValueType::CollisionShapeType:
|
||||
return "collision shape type";
|
||||
}
|
||||
return "unsupported";
|
||||
}
|
||||
|
@ -274,6 +284,19 @@ namespace Settings
|
|||
T mDefaultValue{};
|
||||
T mValue{};
|
||||
|
||||
struct WriteValue
|
||||
{
|
||||
const T& mValue;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const WriteValue& value)
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
return stream << static_cast<std::underlying_type_t<T>>(value.mValue);
|
||||
else
|
||||
return stream << value.mValue;
|
||||
}
|
||||
};
|
||||
|
||||
T sanitize(const T& value) const
|
||||
{
|
||||
if (mSanitizer == nullptr)
|
||||
|
@ -283,8 +306,8 @@ namespace Settings
|
|||
T sanitizedValue = mSanitizer->apply(value);
|
||||
if (sanitizedValue != value)
|
||||
Log(Debug::Warning) << getSettingDescription<T>(mCategory, mName)
|
||||
<< " value is out of allowed values set: " << value << ", sanitized to "
|
||||
<< sanitizedValue;
|
||||
<< " value is out of allowed values set: " << WriteValue{ value }
|
||||
<< ", sanitized to " << WriteValue{ sanitizedValue };
|
||||
return sanitizedValue;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
|
Loading…
Reference in a new issue