Turn Config::Info into a class with getters
This commit is contained in:
parent
11e8783893
commit
b285991b88
|
@ -52,11 +52,11 @@ T Get(LayerType layer, const Info<T>& info)
|
|||
template <typename T>
|
||||
T Get(const Info<T>& info)
|
||||
{
|
||||
const std::optional<std::string> str = GetAsString(info.location);
|
||||
const std::optional<std::string> str = GetAsString(info.GetLocation());
|
||||
if (!str)
|
||||
return info.default_value;
|
||||
return info.GetDefaultValue();
|
||||
|
||||
return detail::TryParse<T>(*str).value_or(info.default_value);
|
||||
return detail::TryParse<T>(*str).value_or(info.GetDefaultValue());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -68,7 +68,7 @@ T GetBase(const Info<T>& info)
|
|||
template <typename T>
|
||||
LayerType GetActiveLayerForConfig(const Info<T>& info)
|
||||
{
|
||||
return GetActiveLayerForConfig(info.location);
|
||||
return GetActiveLayerForConfig(info.GetLocation());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -30,10 +30,11 @@ struct Location
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct Info
|
||||
class Info
|
||||
{
|
||||
Info(const Location& location_, const T& default_value_)
|
||||
: location{location_}, default_value{default_value_}
|
||||
public:
|
||||
constexpr Info(const Location& location, const T& default_value)
|
||||
: m_location{location}, m_default_value{default_value}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,13 +42,17 @@ struct Info
|
|||
// so that enum settings can still easily work with code that doesn't care about the enum values.
|
||||
template <typename Enum,
|
||||
std::enable_if_t<std::is_same<T, detail::UnderlyingType<Enum>>::value>* = nullptr>
|
||||
Info(const Info<Enum>& other)
|
||||
: location{other.location}, default_value{static_cast<detail::UnderlyingType<Enum>>(
|
||||
other.default_value)}
|
||||
constexpr Info(const Info<Enum>& other)
|
||||
: m_location{other.GetLocation()}, m_default_value{static_cast<detail::UnderlyingType<Enum>>(
|
||||
other.GetDefaultValue())}
|
||||
{
|
||||
}
|
||||
|
||||
Location location;
|
||||
T default_value;
|
||||
constexpr const Location& GetLocation() const { return m_location; }
|
||||
constexpr const T& GetDefaultValue() const { return m_default_value; }
|
||||
|
||||
private:
|
||||
Location m_location;
|
||||
T m_default_value;
|
||||
};
|
||||
} // namespace Config
|
||||
|
|
|
@ -45,7 +45,7 @@ inline std::optional<std::string> TryParse(const std::string& str_value)
|
|||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
struct Info;
|
||||
class Info;
|
||||
|
||||
class Layer;
|
||||
using LayerMap = std::map<Location, std::optional<std::string>>;
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
template <typename T>
|
||||
T Get(const Info<T>& config_info) const
|
||||
{
|
||||
return Get<T>(config_info.location).value_or(config_info.default_value);
|
||||
return Get<T>(config_info.GetLocation()).value_or(config_info.GetDefaultValue());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
template <typename T>
|
||||
void Set(const Info<T>& config_info, const std::common_type_t<T>& value)
|
||||
{
|
||||
Set(config_info.location, value);
|
||||
Set(config_info.GetLocation(), value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -41,7 +41,7 @@ void SaveToSYSCONF(Config::LayerType layer)
|
|||
{
|
||||
std::visit(
|
||||
[layer, &setting, &sysconf](auto& info) {
|
||||
const std::string key = info.location.section + "." + info.location.key;
|
||||
const std::string key = info.GetLocation().section + "." + info.GetLocation().key;
|
||||
|
||||
if (setting.type == SysConf::Entry::Type::Long)
|
||||
{
|
||||
|
@ -180,27 +180,28 @@ private:
|
|||
{
|
||||
std::visit(
|
||||
[&](auto& info) {
|
||||
const std::string key = info.location.section + "." + info.location.key;
|
||||
const Config::Location location = info.GetLocation();
|
||||
const std::string key = location.section + "." + location.key;
|
||||
if (setting.type == SysConf::Entry::Type::Long)
|
||||
{
|
||||
layer->Set(info.location, sysconf.GetData<u32>(key, info.default_value));
|
||||
layer->Set(location, sysconf.GetData<u32>(key, info.GetDefaultValue()));
|
||||
}
|
||||
else if (setting.type == SysConf::Entry::Type::Byte)
|
||||
{
|
||||
layer->Set(info.location, sysconf.GetData<u8>(key, info.default_value));
|
||||
layer->Set(location, sysconf.GetData<u8>(key, info.GetDefaultValue()));
|
||||
}
|
||||
else if (setting.type == SysConf::Entry::Type::BigArray)
|
||||
{
|
||||
// Somewhat hacky support for IPL.SADR. The setting only stores the
|
||||
// first 4 bytes even thought the SYSCONF entry is much bigger.
|
||||
u32 value = info.default_value;
|
||||
u32 value = info.GetDefaultValue();
|
||||
SysConf::Entry* entry = sysconf.GetEntry(key);
|
||||
if (entry)
|
||||
{
|
||||
std::memcpy(&value, entry->bytes.data(),
|
||||
std::min(entry->bytes.size(), sizeof(u32)));
|
||||
}
|
||||
layer->Set(info.location, value);
|
||||
layer->Set(location, value);
|
||||
}
|
||||
},
|
||||
setting.config_info);
|
||||
|
|
|
@ -69,10 +69,10 @@ using INIToSectionMap = std::map<std::string, std::pair<Config::System, std::str
|
|||
static const INIToLocationMap& GetINIToLocationMap()
|
||||
{
|
||||
static const INIToLocationMap ini_to_location = {
|
||||
{{"Core", "ProgressiveScan"}, {Config::SYSCONF_PROGRESSIVE_SCAN.location}},
|
||||
{{"Core", "PAL60"}, {Config::SYSCONF_PAL60.location}},
|
||||
{{"Wii", "Widescreen"}, {Config::SYSCONF_WIDESCREEN.location}},
|
||||
{{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.location}},
|
||||
{{"Core", "ProgressiveScan"}, {Config::SYSCONF_PROGRESSIVE_SCAN.GetLocation()}},
|
||||
{{"Core", "PAL60"}, {Config::SYSCONF_PAL60.GetLocation()}},
|
||||
{{"Wii", "Widescreen"}, {Config::SYSCONF_WIDESCREEN.GetLocation()}},
|
||||
{{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.GetLocation()}},
|
||||
};
|
||||
return ini_to_location;
|
||||
}
|
||||
|
|
|
@ -36,32 +36,32 @@ bool IsSettingSaveable(const Config::Location& config_location)
|
|||
static constexpr std::array<const Config::Location*, 17> s_setting_saveable = {
|
||||
// Main.Core
|
||||
|
||||
&Config::MAIN_DEFAULT_ISO.location,
|
||||
&Config::MAIN_MEMCARD_A_PATH.location,
|
||||
&Config::MAIN_MEMCARD_B_PATH.location,
|
||||
&Config::MAIN_AUTO_DISC_CHANGE.location,
|
||||
&Config::MAIN_ALLOW_SD_WRITES.location,
|
||||
&Config::MAIN_DPL2_DECODER.location,
|
||||
&Config::MAIN_DPL2_QUALITY.location,
|
||||
&Config::MAIN_RAM_OVERRIDE_ENABLE.location,
|
||||
&Config::MAIN_MEM1_SIZE.location,
|
||||
&Config::MAIN_MEM2_SIZE.location,
|
||||
&Config::MAIN_GFX_BACKEND.location,
|
||||
&Config::MAIN_ENABLE_SAVESTATES.location,
|
||||
&Config::MAIN_FALLBACK_REGION.location,
|
||||
&Config::MAIN_DEFAULT_ISO.GetLocation(),
|
||||
&Config::MAIN_MEMCARD_A_PATH.GetLocation(),
|
||||
&Config::MAIN_MEMCARD_B_PATH.GetLocation(),
|
||||
&Config::MAIN_AUTO_DISC_CHANGE.GetLocation(),
|
||||
&Config::MAIN_ALLOW_SD_WRITES.GetLocation(),
|
||||
&Config::MAIN_DPL2_DECODER.GetLocation(),
|
||||
&Config::MAIN_DPL2_QUALITY.GetLocation(),
|
||||
&Config::MAIN_RAM_OVERRIDE_ENABLE.GetLocation(),
|
||||
&Config::MAIN_MEM1_SIZE.GetLocation(),
|
||||
&Config::MAIN_MEM2_SIZE.GetLocation(),
|
||||
&Config::MAIN_GFX_BACKEND.GetLocation(),
|
||||
&Config::MAIN_ENABLE_SAVESTATES.GetLocation(),
|
||||
&Config::MAIN_FALLBACK_REGION.GetLocation(),
|
||||
|
||||
// Main.Interface
|
||||
|
||||
&Config::MAIN_USE_PANIC_HANDLERS.location,
|
||||
&Config::MAIN_OSD_MESSAGES.location,
|
||||
&Config::MAIN_USE_PANIC_HANDLERS.GetLocation(),
|
||||
&Config::MAIN_OSD_MESSAGES.GetLocation(),
|
||||
|
||||
// Main.Interface
|
||||
|
||||
&Config::MAIN_SKIP_NKIT_WARNING.location,
|
||||
&Config::MAIN_SKIP_NKIT_WARNING.GetLocation(),
|
||||
|
||||
// UI.General
|
||||
|
||||
&Config::MAIN_USE_DISCORD_PRESENCE.location,
|
||||
&Config::MAIN_USE_DISCORD_PRESENCE.GetLocation(),
|
||||
};
|
||||
|
||||
return std::any_of(s_setting_saveable.cbegin(), s_setting_saveable.cend(),
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct Info;
|
||||
class Info;
|
||||
}
|
||||
|
||||
class GraphicsBool : public ToolTipCheckBox
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct Info;
|
||||
class Info;
|
||||
}
|
||||
|
||||
class GraphicsInteger : public ToolTipSpinBox
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Config
|
||||
{
|
||||
template <typename T>
|
||||
struct Info;
|
||||
class Info;
|
||||
}
|
||||
|
||||
class GraphicsSlider : public ToolTipSlider
|
||||
|
|
|
@ -381,13 +381,13 @@ void NetPlaySetupDialog::PopulateGameList()
|
|||
void NetPlaySetupDialog::ResetTraversalHost()
|
||||
{
|
||||
Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_SERVER,
|
||||
Config::NETPLAY_TRAVERSAL_SERVER.default_value);
|
||||
Config::NETPLAY_TRAVERSAL_SERVER.GetDefaultValue());
|
||||
Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_PORT,
|
||||
Config::NETPLAY_TRAVERSAL_PORT.default_value);
|
||||
Config::NETPLAY_TRAVERSAL_PORT.GetDefaultValue());
|
||||
|
||||
ModalMessageBox::information(
|
||||
this, tr("Reset Traversal Server"),
|
||||
tr("Reset Traversal Server to %1:%2")
|
||||
.arg(QString::fromStdString(Config::NETPLAY_TRAVERSAL_SERVER.default_value),
|
||||
QString::number(Config::NETPLAY_TRAVERSAL_PORT.default_value)));
|
||||
.arg(QString::fromStdString(Config::NETPLAY_TRAVERSAL_SERVER.GetDefaultValue()),
|
||||
QString::number(Config::NETPLAY_TRAVERSAL_PORT.GetDefaultValue())));
|
||||
}
|
||||
|
|
|
@ -26,15 +26,18 @@ public:
|
|||
: ConfigLayerLoader(Config::LayerType::CommandLine)
|
||||
{
|
||||
if (!video_backend.empty())
|
||||
m_values.emplace_back(Config::MAIN_GFX_BACKEND.location, video_backend);
|
||||
m_values.emplace_back(Config::MAIN_GFX_BACKEND.GetLocation(), video_backend);
|
||||
|
||||
if (!audio_backend.empty())
|
||||
m_values.emplace_back(Config::MAIN_DSP_HLE.location, ValueToString(audio_backend == "HLE"));
|
||||
{
|
||||
m_values.emplace_back(Config::MAIN_DSP_HLE.GetLocation(),
|
||||
ValueToString(audio_backend == "HLE"));
|
||||
}
|
||||
|
||||
// Batch mode hides the main window, and render to main hides the render window. To avoid a
|
||||
// situation where we would have no window at all, disable render to main when using batch mode.
|
||||
if (batch)
|
||||
m_values.emplace_back(Config::MAIN_RENDER_TO_MAIN.location, ValueToString(false));
|
||||
m_values.emplace_back(Config::MAIN_RENDER_TO_MAIN.GetLocation(), ValueToString(false));
|
||||
|
||||
// Arguments are in the format of <System>.<Section>.<Key>=Value
|
||||
for (const auto& arg : args)
|
||||
|
|
|
@ -50,7 +50,7 @@ void HandleDiscordJoin(const char* join_secret)
|
|||
if (event_handler == nullptr)
|
||||
return;
|
||||
|
||||
if (Config::Get(Config::NETPLAY_NICKNAME) == Config::NETPLAY_NICKNAME.default_value)
|
||||
if (Config::Get(Config::NETPLAY_NICKNAME) == Config::NETPLAY_NICKNAME.GetDefaultValue())
|
||||
Config::SetCurrent(Config::NETPLAY_NICKNAME, username);
|
||||
|
||||
std::string secret(join_secret);
|
||||
|
|
Loading…
Reference in New Issue