summaryrefslogtreecommitdiff
path: root/Userland/Games/2048
diff options
context:
space:
mode:
authorThitat Auareesuksakul <thitat@fluxthitat.me>2021-08-26 19:43:42 +0700
committerAndreas Kling <kling@serenityos.org>2021-08-26 16:39:22 +0200
commit666397e1a7835a5396572b54ce0437dbe221fd01 (patch)
treeb8702de95fe6a2f4d78483cfc8f349bd3394161a /Userland/Games/2048
parent1fa5fba432c338e5e5924feb9e82fa22b22e098b (diff)
downloadserenity-666397e1a7835a5396572b54ce0437dbe221fd01.zip
2048: Use LibConfig instead of Core::ConfigFile
Diffstat (limited to 'Userland/Games/2048')
-rw-r--r--Userland/Games/2048/CMakeLists.txt2
-rw-r--r--Userland/Games/2048/main.cpp46
2 files changed, 21 insertions, 27 deletions
diff --git a/Userland/Games/2048/CMakeLists.txt b/Userland/Games/2048/CMakeLists.txt
index d8f9bb2e7b..e31191c05a 100644
--- a/Userland/Games/2048/CMakeLists.txt
+++ b/Userland/Games/2048/CMakeLists.txt
@@ -12,4 +12,4 @@ set(SOURCES
)
serenity_app(2048 ICON app-2048)
-target_link_libraries(2048 LibGUI)
+target_link_libraries(2048 LibConfig LibGUI)
diff --git a/Userland/Games/2048/main.cpp b/Userland/Games/2048/main.cpp
index 1182b97223..a8a4c0a604 100644
--- a/Userland/Games/2048/main.cpp
+++ b/Userland/Games/2048/main.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2020-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -7,7 +7,7 @@
#include "BoardView.h"
#include "Game.h"
#include "GameSizeDialog.h"
-#include <LibCore/ConfigFile.h>
+#include <LibConfig/Client.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@@ -37,22 +37,7 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
- auto config = Core::ConfigFile::open_for_app("2048", Core::ConfigFile::AllowWriting::Yes);
-
- size_t board_size = config->read_num_entry("", "board_size", 4);
- u32 target_tile = config->read_num_entry("", "target_tile", 2048);
- bool evil_ai = config->read_bool_entry("", "evil_ai", false);
-
- if ((target_tile & (target_tile - 1)) != 0) {
- // If the target tile is not a power of 2, reset to its default value.
- target_tile = 2048;
- }
-
- config->write_num_entry("", "board_size", board_size);
- config->write_num_entry("", "target_tile", target_tile);
- config->write_bool_entry("", "evil_ai", evil_ai);
-
- config->sync();
+ Config::pledge_domains("2048");
if (pledge("stdio rpath recvfd sendfd wpath cpath", nullptr) < 0) {
perror("pledge");
@@ -64,7 +49,7 @@ int main(int argc, char** argv)
return 1;
}
- if (unveil(config->filename().characters(), "crw") < 0) {
+ if (unveil("/tmp/portal/config", "rw") < 0) {
perror("unveil");
return 1;
}
@@ -74,6 +59,19 @@ int main(int argc, char** argv)
return 1;
}
+ size_t board_size = Config::read_i32("2048", "", "board_size", 4);
+ u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048);
+ bool evil_ai = Config::read_bool("2048", "", "evil_ai", false);
+
+ if ((target_tile & (target_tile - 1)) != 0) {
+ // If the target tile is not a power of 2, reset to its default value.
+ target_tile = 2048;
+ }
+
+ Config::write_i32("2048", "", "board_size", board_size);
+ Config::write_i32("2048", "", "target_tile", target_tile);
+ Config::write_bool("2048", "", "evil_ai", evil_ai);
+
window->set_double_buffering_enabled(false);
window->set_title("2048");
window->resize(315, 336);
@@ -121,14 +119,10 @@ int main(int argc, char** argv)
if (!size_dialog->temporary()) {
- config->write_num_entry("", "board_size", board_size);
- config->write_num_entry("", "target_tile", target_tile);
- config->write_bool_entry("", "evil_ai", evil_ai);
+ Config::write_i32("2048", "", "board_size", board_size);
+ Config::write_i32("2048", "", "target_tile", target_tile);
+ Config::write_bool("2048", "", "evil_ai", evil_ai);
- if (!config->sync()) {
- GUI::MessageBox::show(window, "Configuration could not be synced", "Error", GUI::MessageBox::Type::Error);
- return;
- }
GUI::MessageBox::show(window, "New settings have been saved and will be applied on a new game", "Settings Changed Successfully", GUI::MessageBox::Type::Information);
return;
}