mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
Minesweeper: Use LibConfig instead of Core::ConfigFile
This commit is contained in:
parent
d9b5dae809
commit
827bf5232e
3 changed files with 14 additions and 22 deletions
|
@ -10,4 +10,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(Minesweeper ICON app-minesweeper)
|
serenity_app(Minesweeper ICON app-minesweeper)
|
||||||
target_link_libraries(Minesweeper LibGUI)
|
target_link_libraries(Minesweeper LibGUI LibConfig)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#include "Field.h"
|
#include "Field.h"
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/Queue.h>
|
#include <AK/Queue.h>
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
|
@ -137,11 +137,10 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
|
||||||
set_face(Face::Default);
|
set_face(Face::Default);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto config = Core::ConfigFile::open_for_app("Minesweeper");
|
bool single_chording = Config::read_bool("Minesweeper", "Game", "SingleChording", false);
|
||||||
bool single_chording = config->read_num_entry("Minesweeper", "SingleChording", false);
|
int mine_count = Config::read_i32("Minesweeper", "Game", "MineCount", 10);
|
||||||
int mine_count = config->read_num_entry("Game", "MineCount", 10);
|
int rows = Config::read_i32("Minesweeper", "Game", "Rows", 9);
|
||||||
int rows = config->read_num_entry("Game", "Rows", 9);
|
int columns = Config::read_i32("Minesweeper", "Game", "Columns", 9);
|
||||||
int columns = config->read_num_entry("Game", "Columns", 9);
|
|
||||||
|
|
||||||
// Do a quick sanity check to make sure the user hasn't tried anything crazy
|
// Do a quick sanity check to make sure the user hasn't tried anything crazy
|
||||||
if (mine_count > rows * columns || rows <= 0 || columns <= 0 || mine_count <= 0)
|
if (mine_count > rows * columns || rows <= 0 || columns <= 0 || mine_count <= 0)
|
||||||
|
@ -488,10 +487,9 @@ void Field::set_field_size(size_t rows, size_t columns, size_t mine_count)
|
||||||
if (m_rows == rows && m_columns == columns && m_mine_count == mine_count)
|
if (m_rows == rows && m_columns == columns && m_mine_count == mine_count)
|
||||||
return;
|
return;
|
||||||
{
|
{
|
||||||
auto config = Core::ConfigFile::open_for_app("Minesweeper", Core::ConfigFile::AllowWriting::Yes);
|
Config::write_i32("Minesweeper", "Game", "MineCount", mine_count);
|
||||||
config->write_num_entry("Game", "MineCount", mine_count);
|
Config::write_i32("Minesweeper", "Game", "Rows", rows);
|
||||||
config->write_num_entry("Game", "Rows", rows);
|
Config::write_i32("Minesweeper", "Game", "Columns", columns);
|
||||||
config->write_num_entry("Game", "Columns", columns);
|
|
||||||
}
|
}
|
||||||
m_rows = rows;
|
m_rows = rows;
|
||||||
m_columns = columns;
|
m_columns = columns;
|
||||||
|
@ -503,9 +501,8 @@ void Field::set_field_size(size_t rows, size_t columns, size_t mine_count)
|
||||||
|
|
||||||
void Field::set_single_chording(bool enabled)
|
void Field::set_single_chording(bool enabled)
|
||||||
{
|
{
|
||||||
auto config = Core::ConfigFile::open_for_app("Minesweeper", Core::ConfigFile::AllowWriting::Yes);
|
|
||||||
m_single_chording = enabled;
|
m_single_chording = enabled;
|
||||||
config->write_bool_entry("Minesweeper", "SingleChording", m_single_chording);
|
Config::write_bool("Minesweeper", "Game", "SingleChording", m_single_chording);
|
||||||
}
|
}
|
||||||
|
|
||||||
Square::Square()
|
Square::Square()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Field.h"
|
#include "Field.h"
|
||||||
#include <LibCore/ConfigFile.h>
|
#include <LibConfig/Client.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/Application.h>
|
#include <LibGUI/Application.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
@ -28,23 +28,18 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto app = GUI::Application::construct(argc, argv);
|
auto app = GUI::Application::construct(argc, argv);
|
||||||
|
|
||||||
|
Config::pledge_domains("Minesweeper");
|
||||||
|
|
||||||
if (pledge("stdio rpath wpath cpath recvfd sendfd", nullptr) < 0) {
|
if (pledge("stdio rpath wpath cpath recvfd sendfd", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto config = Core::ConfigFile::open_for_app("Minesweeper");
|
|
||||||
|
|
||||||
if (unveil("/res", "r") < 0) {
|
if (unveil("/res", "r") < 0) {
|
||||||
perror("unveil");
|
perror("unveil");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unveil(config->filename().characters(), "crw") < 0) {
|
|
||||||
perror("unveil");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unveil(nullptr, nullptr) < 0) {
|
if (unveil(nullptr, nullptr) < 0) {
|
||||||
perror("unveil");
|
perror("unveil");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue