mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 07:38:10 +00:00
LibCore: Add a CConfigFile class, a simple INI file parser.
You open the configuration for an app like so: auto config = CConfigFile::get_for_app("MyApp"); This will then open ~/MyApp.ini and parse it for you. Immediately start using it in Minesweeper to load the field size and mine count from a config file.
This commit is contained in:
parent
37c27e2e39
commit
bc5148354f
5 changed files with 269 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <LibCore/CConfigFile.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
|
@ -30,6 +31,12 @@ Field::Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidg
|
|||
, m_flag_label(flag_label)
|
||||
, m_time_label(time_label)
|
||||
{
|
||||
auto config = CConfigFile::get_for_app("Minesweeper");
|
||||
|
||||
m_mine_count = config->read_num_entry("Game", "MineCount", 10);
|
||||
m_rows = config->read_num_entry("Game", "Rows", 9);
|
||||
m_columns = config->read_num_entry("Game", "Columns", 9);
|
||||
|
||||
m_timer.on_timeout = [this] {
|
||||
m_time_label.set_text(String::format("%u", ++m_seconds_elapsed));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue