FlappyBug: Use LibConfig instead of Core::ConfigFile
This commit is contained in:
parent
b54573739c
commit
5a0be07cf0
Notes:
sideshowbarker
2024-07-18 05:16:17 +09:00
Author: https://github.com/doctor-rd Commit: https://github.com/SerenityOS/serenity/commit/5a0be07cf01 Pull-request: https://github.com/SerenityOS/serenity/pull/9616
2 changed files with 7 additions and 14 deletions
|
@ -10,4 +10,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_app(FlappyBug ICON app-flappybug)
|
||||
target_link_libraries(FlappyBug LibGUI)
|
||||
target_link_libraries(FlappyBug LibGUI LibConfig)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "Game.h"
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
|
@ -22,9 +22,10 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
auto app = GUI::Application::construct(argc, argv);
|
||||
auto config = Core::ConfigFile::open_for_app("FlappyBug", Core::ConfigFile::AllowWriting::Yes);
|
||||
|
||||
if (pledge("stdio rpath wpath cpath recvfd sendfd", nullptr) < 0) {
|
||||
Config::pledge_domains("FlappyBug");
|
||||
|
||||
if (pledge("stdio rpath recvfd sendfd", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
@ -34,17 +35,12 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (unveil(config->filename().characters(), "crw") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (unveil(nullptr, nullptr) < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 high_score = static_cast<u32>(config->read_num_entry("Game", "HighScore", 0));
|
||||
u32 high_score = Config::read_i32("FlappyBug", "Game", "HighScore", 0);
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
window->resize(FlappyBug::Game::game_width, FlappyBug::Game::game_height);
|
||||
|
@ -59,12 +55,9 @@ int main(int argc, char** argv)
|
|||
if (score <= high_score)
|
||||
return high_score;
|
||||
|
||||
config->write_num_entry("Game", "HighScore", static_cast<int>(score));
|
||||
Config::write_i32("FlappyBug", "Game", "HighScore", score);
|
||||
high_score = score;
|
||||
|
||||
if (!config->sync())
|
||||
GUI::MessageBox::show(window, "Configuration could not be saved", "Error", GUI::MessageBox::Type::Error);
|
||||
|
||||
return high_score;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue