From 29f15cfbae48868f21a61efd3365ac8f4d059a6c Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 27 Jul 2021 11:21:07 +0100 Subject: [PATCH] Spider: Standardise fetching the mode identifier This eliminates some code duplication, and will be helpful for future commits introducing further statistic tracking. --- Userland/Games/Spider/main.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Userland/Games/Spider/main.cpp b/Userland/Games/Spider/main.cpp index aa80c7e5fa..0343adacaf 100644 --- a/Userland/Games/Spider/main.cpp +++ b/Userland/Games/Spider/main.cpp @@ -58,28 +58,23 @@ int main(int argc, char** argv) GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error); }; - auto high_score = [&]() { + auto mode_id = [&]() { switch (mode) { case Spider::Mode::SingleSuit: - return static_cast(config->read_num_entry("HighScores", "SingleSuit", 0)); + return "SingleSuit"; case Spider::Mode::TwoSuit: - return static_cast(config->read_num_entry("HighScores", "TwoSuit", 0)); + return "TwoSuit"; default: VERIFY_NOT_REACHED(); } }; + auto high_score = [&]() { + return static_cast(config->read_num_entry("HighScores", mode_id(), 0)); + }; + auto update_high_score = [&](u32 new_high_score) { - switch (mode) { - case Spider::Mode::SingleSuit: - config->write_num_entry("HighScores", "SingleSuit", static_cast(new_high_score)); - break; - case Spider::Mode::TwoSuit: - config->write_num_entry("HighScores", "TwoSuit", static_cast(new_high_score)); - break; - default: - VERIFY_NOT_REACHED(); - } + config->write_num_entry("HighScores", mode_id(), static_cast(new_high_score)); if (!config->sync()) GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);