1
0
Fork 0
forked from suyu/suyu

configuration/config: Use an intermediary variable for accessing players

Avoids typing the same long accessor just to retrieve player attributes.
This commit is contained in:
Lioncash 2018-12-05 03:41:31 -05:00
parent db3200b515
commit e90fa1ac54

View file

@ -206,60 +206,57 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default
void Config::ReadPlayerValues() { void Config::ReadPlayerValues() {
for (std::size_t p = 0; p < Settings::values.players.size(); ++p) { for (std::size_t p = 0; p < Settings::values.players.size(); ++p) {
Settings::values.players[p].connected = auto& player = Settings::values.players[p];
qt_config->value(QString("player_%1_connected").arg(p), false).toBool();
Settings::values.players[p].type = static_cast<Settings::ControllerType>( player.connected = qt_config->value(QString("player_%1_connected").arg(p), false).toBool();
player.type = static_cast<Settings::ControllerType>(
qt_config qt_config
->value(QString("player_%1_type").arg(p), ->value(QString("player_%1_type").arg(p),
static_cast<u8>(Settings::ControllerType::DualJoycon)) static_cast<u8>(Settings::ControllerType::DualJoycon))
.toUInt()); .toUInt());
Settings::values.players[p].body_color_left = player.body_color_left = qt_config
qt_config
->value(QString("player_%1_body_color_left").arg(p), ->value(QString("player_%1_body_color_left").arg(p),
Settings::JOYCON_BODY_NEON_BLUE) Settings::JOYCON_BODY_NEON_BLUE)
.toUInt(); .toUInt();
Settings::values.players[p].body_color_right = player.body_color_right = qt_config
qt_config
->value(QString("player_%1_body_color_right").arg(p), ->value(QString("player_%1_body_color_right").arg(p),
Settings::JOYCON_BODY_NEON_RED) Settings::JOYCON_BODY_NEON_RED)
.toUInt(); .toUInt();
Settings::values.players[p].button_color_left = player.button_color_left = qt_config
qt_config
->value(QString("player_%1_button_color_left").arg(p), ->value(QString("player_%1_button_color_left").arg(p),
Settings::JOYCON_BUTTONS_NEON_BLUE) Settings::JOYCON_BUTTONS_NEON_BLUE)
.toUInt(); .toUInt();
Settings::values.players[p].button_color_right = player.button_color_right = qt_config
qt_config
->value(QString("player_%1_button_color_right").arg(p), ->value(QString("player_%1_button_color_right").arg(p),
Settings::JOYCON_BUTTONS_NEON_RED) Settings::JOYCON_BUTTONS_NEON_RED)
.toUInt(); .toUInt();
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
Settings::values.players[p].buttons[i] = player.buttons[i] =
qt_config qt_config
->value(QString("player_%1_").arg(p) + Settings::NativeButton::mapping[i], ->value(QString("player_%1_").arg(p) + Settings::NativeButton::mapping[i],
QString::fromStdString(default_param)) QString::fromStdString(default_param))
.toString() .toString()
.toStdString(); .toStdString();
if (Settings::values.players[p].buttons[i].empty()) if (player.buttons[i].empty())
Settings::values.players[p].buttons[i] = default_param; player.buttons[i] = default_param;
} }
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
std::string default_param = InputCommon::GenerateAnalogParamFromKeys( std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_analogs[i][4], 0.5f); default_analogs[i][3], default_analogs[i][4], 0.5f);
Settings::values.players[p].analogs[i] = player.analogs[i] =
qt_config qt_config
->value(QString("player_%1_").arg(p) + Settings::NativeAnalog::mapping[i], ->value(QString("player_%1_").arg(p) + Settings::NativeAnalog::mapping[i],
QString::fromStdString(default_param)) QString::fromStdString(default_param))
.toString() .toString()
.toStdString(); .toStdString();
if (Settings::values.players[p].analogs[i].empty()) if (player.analogs[i].empty())
Settings::values.players[p].analogs[i] = default_param; player.analogs[i] = default_param;
} }
} }
@ -511,30 +508,28 @@ void Config::ReadValues() {
} }
void Config::SavePlayerValues() { void Config::SavePlayerValues() {
for (int p = 0; p < Settings::values.players.size(); ++p) { for (std::size_t p = 0; p < Settings::values.players.size(); ++p) {
qt_config->setValue(QString("player_%1_connected").arg(p), const auto& player = Settings::values.players[p];
Settings::values.players[p].connected);
qt_config->setValue(QString("player_%1_type").arg(p),
static_cast<u8>(Settings::values.players[p].type));
qt_config->setValue(QString("player_%1_body_color_left").arg(p), qt_config->setValue(QString("player_%1_connected").arg(p), player.connected);
Settings::values.players[p].body_color_left); qt_config->setValue(QString("player_%1_type").arg(p), static_cast<u8>(player.type));
qt_config->setValue(QString("player_%1_body_color_right").arg(p),
Settings::values.players[p].body_color_right); qt_config->setValue(QString("player_%1_body_color_left").arg(p), player.body_color_left);
qt_config->setValue(QString("player_%1_body_color_right").arg(p), player.body_color_right);
qt_config->setValue(QString("player_%1_button_color_left").arg(p), qt_config->setValue(QString("player_%1_button_color_left").arg(p),
Settings::values.players[p].button_color_left); player.button_color_left);
qt_config->setValue(QString("player_%1_button_color_right").arg(p), qt_config->setValue(QString("player_%1_button_color_right").arg(p),
Settings::values.players[p].button_color_right); player.button_color_right);
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
qt_config->setValue(QString("player_%1_").arg(p) + qt_config->setValue(QString("player_%1_").arg(p) +
QString::fromStdString(Settings::NativeButton::mapping[i]), QString::fromStdString(Settings::NativeButton::mapping[i]),
QString::fromStdString(Settings::values.players[p].buttons[i])); QString::fromStdString(player.buttons[i]));
} }
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
qt_config->setValue(QString("player_%1_").arg(p) + qt_config->setValue(QString("player_%1_").arg(p) +
QString::fromStdString(Settings::NativeAnalog::mapping[i]), QString::fromStdString(Settings::NativeAnalog::mapping[i]),
QString::fromStdString(Settings::values.players[p].analogs[i])); QString::fromStdString(player.analogs[i]));
} }
} }
} }