From e2dad5f30ca4d8502558e0560d2059a51aae4c4c Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 19 Aug 2024 09:11:09 +0200 Subject: core: add settings accessor --- core/CMakeLists.txt | 16 ++++++++++++++++ core/include/turns/core/settings.hpp | 21 +++++++++++++++++++++ core/schemas/ch.arknet.Turns.gschema.xml | 25 +++++++++++++++++++++++++ core/src/settings.cpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 core/include/turns/core/settings.hpp create mode 100644 core/schemas/ch.arknet.Turns.gschema.xml create mode 100644 core/src/settings.cpp (limited to 'core') diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 9b6390c..5ec88e4 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -4,6 +4,7 @@ add_library("core" "src/disposition.cpp" "src/init.cpp" "src/participant.cpp" + "src/settings.cpp" "src/turn_order.cpp" ) @@ -16,6 +17,12 @@ target_compile_options("core" PUBLIC "$<$:-pedantic-errors>" ) +if(NOT TURNS_USE_INSTALLED_SCHEMA_FILES) + target_compile_definitions("core" PUBLIC + "TURNS_SETTINGS_SCHEMA_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" + ) +endif() + target_include_directories("core" PUBLIC "include" ) @@ -26,8 +33,17 @@ target_link_libraries("core" PUBLIC "nlohmann_json::nlohmann_json" ) +target_add_glib_schemas("core" + SCHEMA_DIR "schemas" +) + enable_coverage("core") +install(FILES + "schemas/ch.arknet.Turns.gschema.xml" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/glib-2.0/schemas" +) + # Tests add_executable("core-tests" diff --git a/core/include/turns/core/settings.hpp b/core/include/turns/core/settings.hpp new file mode 100644 index 0000000..3e21a47 --- /dev/null +++ b/core/include/turns/core/settings.hpp @@ -0,0 +1,21 @@ +#ifndef TURNS_CORE_SETTINGS_HPP +#define TURNS_CORE_SETTINGS_HPP + +#include + +#include + +namespace turns::core +{ + namespace key + { + auto constexpr disposition_friendly_color = "disposition-friendly-color"; + auto constexpr disposition_hostile_color = "disposition-hostile-color"; + auto constexpr disposition_secret_color = "disposition-secret-color"; + auto constexpr skip_defeated = "skip-defeated"; + } // namespace key + + auto get_settings() -> Glib::RefPtr; +} // namespace turns::core + +#endif \ No newline at end of file diff --git a/core/schemas/ch.arknet.Turns.gschema.xml b/core/schemas/ch.arknet.Turns.gschema.xml new file mode 100644 index 0000000..d764608 --- /dev/null +++ b/core/schemas/ch.arknet.Turns.gschema.xml @@ -0,0 +1,25 @@ + + + + + '#33d17a' + Friendly Disposition Color + The color used to shade friendly participants. + + + '#e01b24' + Hostile Disposition Color + The color used to shade hostile participants. + + + '#9141ac' + Secret Disposition Color + The color used to shade secret participants. + + + false + Skip Defeated Participants + Whether or not defeated participants shall be skipped while stepping through the turn order. + + + \ No newline at end of file diff --git a/core/src/settings.cpp b/core/src/settings.cpp new file mode 100644 index 0000000..c98e5eb --- /dev/null +++ b/core/src/settings.cpp @@ -0,0 +1,28 @@ +#include "turns/core/settings.hpp" + +#include +#include + +#include +#include + +#include + +namespace turns::core +{ + + auto get_settings() -> Glib::RefPtr + { + auto constexpr schema_id = "ch.arknet.Turns"; + +#ifdef TURNS_SETTINGS_SCHEMA_DIR + auto source = Gio::SettingsSchemaSource::create(TURNS_SETTINGS_SCHEMA_DIR "/glib-2.0/schemas", true); + auto schema = source->lookup(schema_id, true); + auto settings = g_settings_new_full(Glib::unwrap(schema), nullptr, nullptr); + return Glib::wrap(settings); +#else + return Gio::Settings::create(schema); +#endif + } + +} // namespace turns::core -- cgit v1.2.3