summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorJamie Mansfield <jmansfield@cadixdev.org>2021-07-27 11:21:07 +0100
committerAndreas Kling <kling@serenityos.org>2021-07-27 16:53:56 +0200
commit29f15cfbae48868f21a61efd3365ac8f4d059a6c (patch)
tree23c43954d56d151b81a0c4a51a378d826683a33b /Userland/Games
parent78c81854cced6b1cfd390d2f8abd48b07fde8804 (diff)
downloadserenity-29f15cfbae48868f21a61efd3365ac8f4d059a6c.zip
Spider: Standardise fetching the mode identifier
This eliminates some code duplication, and will be helpful for future commits introducing further statistic tracking.
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/Spider/main.cpp21
1 files 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<u32>(config->read_num_entry("HighScores", "SingleSuit", 0));
+ return "SingleSuit";
case Spider::Mode::TwoSuit:
- return static_cast<u32>(config->read_num_entry("HighScores", "TwoSuit", 0));
+ return "TwoSuit";
default:
VERIFY_NOT_REACHED();
}
};
+ auto high_score = [&]() {
+ return static_cast<u32>(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<int>(new_high_score));
- break;
- case Spider::Mode::TwoSuit:
- config->write_num_entry("HighScores", "TwoSuit", static_cast<int>(new_high_score));
- break;
- default:
- VERIFY_NOT_REACHED();
- }
+ config->write_num_entry("HighScores", mode_id(), static_cast<int>(new_high_score));
if (!config->sync())
GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);