From d87b2e3730e67cc637fad48140664a32ed619ba7 Mon Sep 17 00:00:00 2001 From: chris bell Date: Sun, 2 Aug 2026 23:48:34 -0500 Subject: [PATCH] Setting up data, and added SQLite and TOML --- CMakeLists.txt | 8 ++++++++ assets/main.rml | 3 ++- flake.nix | 4 ++-- src/critter.hpp | 35 +++++++++++++++++++++++++++++++++++ src/main.cpp | 36 ++++++++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/critter.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ed51903..e7b3f09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,14 @@ find_package(Lua REQUIRED) pkg_check_modules(LUNASVG REQUIRED IMPORTED_TARGET lunasvg) add_library(lunasvg::lunasvg ALIAS PkgConfig::LUNASVG) +pkg_check_modules(SQLITE3 REQUIRED IMPORTED_TARGET sqlite3) +add_library(sqlite3::sqlite3 ALIAS PkgConfig::SQLITE3) + +find_package(toml11 CONFIG REQUIRED) + find_package(RmlUi CONFIG REQUIRED) + add_executable(${PROJECT_NAME} src/main.cpp vendor/rmlui_backend/RmlUi_Backend_GLFW_GL3.cpp @@ -37,6 +43,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Freetype::Freetype lunasvg::lunasvg glfw + sqlite3::sqlite3 + toml11::toml11 ) install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/assets/main.rml b/assets/main.rml index 65f0d88..f976d9d 100644 --- a/assets/main.rml +++ b/assets/main.rml @@ -5,7 +5,8 @@ - + +

{{page_title}}

Hello world!

diff --git a/flake.nix b/flake.nix index 1706431..917dfdc 100644 --- a/flake.nix +++ b/flake.nix @@ -55,7 +55,6 @@ raylib glfw libGL - clang-tools libX11 libXcursor libXrandr @@ -67,7 +66,8 @@ freetype lunasvg lua - lua-language-server + sqlite.dev + toml11 ]; in { diff --git a/src/critter.hpp b/src/critter.hpp new file mode 100644 index 0000000..cbf11b1 --- /dev/null +++ b/src/critter.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +class CritterEvent { + public: + std::string name; + std::string date; + std::string time; + std::string description; +}; + +class CritterDocument { + public: + std::string name; + std::string doc_type; + std::string cached_path; +}; + +class Critter { + + enum Sex {Male, Female}; + + public: + std::string name; + Sex sex; + std::string birthdate; + Critter *mother; + Critter *father; + std::vector children; + std::string notes; + std::vector events; + std::vector documents; +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3551053..0d2fe14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include #include @@ -10,18 +12,37 @@ #include #include #include - - +#include "critter.hpp" +#include static bool is_initalized = false; static bool is_running = false; static Rml::Context *ctx; +struct AppData { + Rml::String page_title = "Main"; + sqlite3 *db; +} app_data; + void Shutdown() { Rml::Shutdown(); Backend::Shutdown(); } +bool SetupDataBinding(Rml::Context *context, Rml::DataModelHandle &model_handle) { + Rml::DataModelConstructor dmc = ctx->CreateDataModel("app_data"); + if (!dmc) { + std::cout << "[ERROR] could not create 'app_data' data binding."; + return false; + } + + dmc.Bind("page_title", &app_data.page_title); + + model_handle = dmc.GetModelHandle(); + + return true; +} + bool Initalize() { if (!Backend::Initialize("CritterFolio", 800, 600, true)) { std::cout << "[ERROR] Failed to initalize the backend."; @@ -41,11 +62,16 @@ bool Initalize() { Rml::Debugger::Initialise(ctx); + + // lua_State *L = Rml::Lua::Interpreter::GetLuaState(); return true; } +void Update(Rml::DataModelHandle model_handle) { + +} int main() { std::cout << "Hello world!\n"; @@ -59,6 +85,10 @@ int main() { is_running = true; + Rml::DataModelHandle app_data_handle; + + SetupDataBinding(ctx, app_data_handle); + Rml::ElementDocument *doc; doc = ctx->LoadDocument("./assets/main.rml"); if (!doc) { @@ -72,6 +102,8 @@ int main() { while(is_running) { is_running = Backend::ProcessEvents(ctx); + Update(app_data_handle); + ctx->Update(); Backend::BeginFrame(); ctx->Render();