Snake: Use LibConfig instead of Core::ConfigFile

This commit is contained in:
Mustafa Quraish 2021-08-26 20:19:41 -04:00 committed by Andreas Kling
parent 3ad9df1522
commit 458471cc37
3 changed files with 8 additions and 14 deletions

View file

@ -10,4 +10,4 @@ set(SOURCES
)
serenity_app(Snake ICON app-snake)
target_link_libraries(Snake LibGUI)
target_link_libraries(Snake LibGUI LibConfig)

View file

@ -1,11 +1,12 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "SnakeGame.h"
#include <LibCore/ConfigFile.h>
#include <LibConfig/Client.h>
#include <LibGUI/Painter.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h>
@ -23,8 +24,7 @@ SnakeGame::SnakeGame()
srand(time(nullptr));
reset();
auto config = Core::ConfigFile::open_for_app("Snake");
m_high_score = config->read_num_entry("Snake", "HighScore", 0);
m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0);
m_high_score_text = String::formatted("Best: {}", m_high_score);
}
@ -131,8 +131,7 @@ void SnakeGame::timer_event(Core::TimerEvent&)
m_high_score = m_score;
m_high_score_text = String::formatted("Best: {}", m_high_score);
update(high_score_rect());
auto config = Core::ConfigFile::open_for_app("Snake", Core::ConfigFile::AllowWriting::Yes);
config->write_num_entry("Snake", "HighScore", m_high_score);
Config::write_i32("Snake", "Snake", "HighScore", m_high_score);
}
update(score_rect());
dirty_cells.append(m_fruit);

View file

@ -5,7 +5,7 @@
*/
#include "SnakeGame.h"
#include <LibCore/ConfigFile.h>
#include <LibConfig/Client.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@ -26,23 +26,18 @@ int main(int argc, char** argv)
auto app = GUI::Application::construct(argc, argv);
Config::pledge_domains("Snake");
if (pledge("stdio rpath wpath cpath recvfd sendfd", nullptr) < 0) {
perror("pledge");
return 1;
}
auto config = Core::ConfigFile::open_for_app("Snake");
if (unveil("/res", "r") < 0) {
perror("unveil");
return 1;
}
if (unveil(config->filename().characters(), "crw") < 0) {
perror("unveil");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;