mirror of https://github.com/snes9xgit/snes9x.git
qt: Clean up EmuConfig a bit.
This commit is contained in:
parent
8973d9a60f
commit
2a0a9d0454
|
@ -324,7 +324,7 @@ bool EmuConfig::setDefaults(int section)
|
|||
return restart;
|
||||
}
|
||||
|
||||
void EmuConfig::config(std::string filename, bool write)
|
||||
void EmuConfig::config(const std::string &filename, bool write)
|
||||
{
|
||||
QSettings settings(QString::fromStdString(filename), QSettings::IniFormat);
|
||||
|
||||
|
@ -339,25 +339,26 @@ void EmuConfig::config(std::string filename, bool write)
|
|||
|
||||
if (write)
|
||||
{
|
||||
Bool = [&](std::string key, bool &value) {
|
||||
Bool = [&](const std::string &key, bool &value) {
|
||||
settings.setValue(key, value);
|
||||
};
|
||||
Int = [&](std::string key, int &value) {
|
||||
Int = [&](const std::string &key, int &value) {
|
||||
settings.setValue(key, value);
|
||||
};
|
||||
String = [&](std::string key, std::string &value) {
|
||||
String = [&](const std::string &key, std::string &value) {
|
||||
settings.setValue(key, QString::fromStdString(value));
|
||||
};
|
||||
Enum = [&](std::string key, int &value, std::vector<const char *> map) {
|
||||
Enum = [&](const std::string &key, int &value,
|
||||
const std::vector<const char *> &map) {
|
||||
settings.setValue(key, map[value]);
|
||||
};
|
||||
Double = [&](std::string key, double &value) {
|
||||
Double = [&](const std::string &key, double &value) {
|
||||
settings.setValue(key, value);
|
||||
};
|
||||
Binding = [&](std::string key, EmuBinding &binding) {
|
||||
Binding = [&](const std::string &key, EmuBinding &binding) {
|
||||
settings.setValue(key, QString::fromStdString(binding.to_config_string()));
|
||||
};
|
||||
BeginSection = [&](std::string str) {
|
||||
BeginSection = [&](const std::string &str) {
|
||||
settings.beginGroup(str);
|
||||
};
|
||||
EndSection = [&]() {
|
||||
|
@ -366,27 +367,28 @@ void EmuConfig::config(std::string filename, bool write)
|
|||
}
|
||||
else
|
||||
{
|
||||
Bool = [&](std::string key, bool &value) {
|
||||
Bool = [&](const std::string &key, bool &value) {
|
||||
if (settings.contains(key))
|
||||
value = settings.value(key).toBool();
|
||||
};
|
||||
Int = [&](std::string key, int &value) {
|
||||
Int = [&](const std::string &key, int &value) {
|
||||
if (settings.contains(key))
|
||||
value = settings.value(key).toInt();
|
||||
};
|
||||
String = [&](std::string key, std::string &value) {
|
||||
String = [&](const std::string &key, std::string &value) {
|
||||
if (settings.contains(key))
|
||||
value = settings.value(key).toString().toStdString();
|
||||
};
|
||||
Binding = [&](std::string key, EmuBinding &binding) {
|
||||
Binding = [&](const std::string &key, EmuBinding &binding) {
|
||||
if (settings.contains(key))
|
||||
binding = EmuBinding::from_config_string(settings.value(key).toString().toStdString());
|
||||
};
|
||||
Double = [&](std::string key, double &value) {
|
||||
Double = [&](const std::string &key, double &value) {
|
||||
if (settings.contains(key))
|
||||
value = settings.value(key).toDouble();
|
||||
};
|
||||
Enum = [&](std::string key, int &value, std::vector<const char *> map) {
|
||||
Enum = [&](const std::string &key, int &value,
|
||||
const std::vector<const char *> &map) {
|
||||
QString entry;
|
||||
|
||||
if (settings.contains(key))
|
||||
|
@ -403,7 +405,7 @@ void EmuConfig::config(std::string filename, bool write)
|
|||
}
|
||||
}
|
||||
};
|
||||
BeginSection = [&](std::string str) {
|
||||
BeginSection = [&](const std::string &str) {
|
||||
settings.beginGroup(QString::fromStdString(str));
|
||||
};
|
||||
EndSection = [&]() {
|
||||
|
@ -498,7 +500,6 @@ void EmuConfig::config(std::string filename, bool write)
|
|||
Enum("PortConfiguration", port_configuration, { "OneController", "TwoControllers", "Mouse", "SuperScope", "Multitap" });
|
||||
EndSection();
|
||||
|
||||
const char *names[] = { "Up", "Down", "Left", "Right", "A", "B", "X", "Y", "L", "R", "Start", "Select", "Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y", "Turbo_L", "Turbo_R" };
|
||||
for (int c = 0; c < 5; c++)
|
||||
{
|
||||
BeginSection("Controller_" + std::to_string(c));
|
||||
|
@ -506,6 +507,11 @@ void EmuConfig::config(std::string filename, bool write)
|
|||
for (int y = 0; y < num_controller_bindings; y++)
|
||||
for (int x = 0; x < allowed_bindings; x++)
|
||||
{
|
||||
const char *names[] = {"Up", "Down", "Left", "Right",
|
||||
"A", "B", "X", "Y",
|
||||
"L", "R", "Start", "Select",
|
||||
"Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y",
|
||||
"Turbo_L", "Turbo_R"};
|
||||
std::string keyname = names[y] + std::to_string(x);
|
||||
Binding(keyname, binding.controller[c].buttons[y * allowed_bindings + x]);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#ifndef __EMU_CONFIG_HPP
|
||||
#define __EMU_CONFIG_HPP
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -11,12 +9,12 @@ struct EmuConfig
|
|||
static std::string findConfigFile();
|
||||
static std::string findConfigDir();
|
||||
bool setDefaults(int section = -1);
|
||||
void config(std::string filename, bool write);
|
||||
void loadFile(std::string filename)
|
||||
void config(const std::string &filename, bool write);
|
||||
void loadFile(const std::string &filename)
|
||||
{
|
||||
config(filename, false);
|
||||
}
|
||||
void saveFile(std::string filename)
|
||||
void saveFile(const std::string &filename)
|
||||
{
|
||||
config(filename, true);
|
||||
}
|
||||
|
@ -242,6 +240,4 @@ struct EmuConfig
|
|||
eStopRecording,
|
||||
eSeekToFrame,
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
|
@ -182,7 +182,7 @@ void Snes9xController::updateSettings(const EmuConfig * const config)
|
|||
|
||||
high_resolution_effect = config->high_resolution_effect;
|
||||
|
||||
config_folder = config->findConfigDir();
|
||||
config_folder = EmuConfig::findConfigDir();
|
||||
|
||||
auto doFolder = [&](int location, std::string &dest, const std::string &src, const char *subfolder_name)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue