GroveEngine/include/grove/IUI.h
StillHammer fad105afb2 feat: Implement complete IDataNode/IDataTree system with JSON backend
Major feature: Unified config/data/runtime tree system

**New System Architecture:**
- Unified data tree for config, persistent data, and runtime state
- Three separate roots: config/ (read-only + hot-reload), data/ (read-write + save), runtime/ (temporary)
- Support for modding, saves, and hot-reload in single system

**Interfaces:**
- IDataValue: Abstract data value interface (type-safe access)
- IDataNode: Tree node with navigation, search, and modification
- IDataTree: Root container with config/data/runtime management

**Concrete Implementations:**
- JsonDataValue: nlohmann::json backed value
- JsonDataNode: Full tree navigation with pattern matching & queries
- JsonDataTree: File-based JSON storage with hot-reload

**Features:**
- Pattern matching search (wildcards support)
- Property-based queries with predicates
- SHA256 hashing for validation/sync
- Hot-reload for config/ directory
- Save operations for data/ persistence
- Read-only enforcement for config/

**API Changes:**
- All namespaces changed from 'warfactory' to 'grove'
- IDataTree: Added getConfigRoot(), getDataRoot(), getRuntimeRoot()
- IDataTree: Added saveData(), saveNode() for persistence
- IDataNode: Added setChild(), removeChild(), clearChildren()
- CMakeLists.txt: Added OpenSSL dependency for hashing

**Usage:**
```cpp
auto tree = DataTreeFactory::create("json", "./gamedata");
auto config = tree->getConfigRoot();     // Read-only game config
auto data = tree->getDataRoot();         // Player saves
auto runtime = tree->getRuntimeRoot();   // Temporary state

// Hot-reload config on file changes
if (tree->reloadIfChanged()) { /* refresh modules */ }

// Save player progress
data->setChild("progress", progressNode);
tree->saveData();
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 15:36:25 +08:00

129 lines
4.1 KiB
C++

#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <functional>
namespace grove {
using json = nlohmann::json;
/**
* @brief Pure Generic UI Interface - Zero assumptions about content
*
* Completely data-agnostic. Implementation decides how to handle each data type.
*/
class IUI {
public:
virtual ~IUI() = default;
// ========================================
// LIFECYCLE
// ========================================
/**
* @brief Initialize UI system
* @param config Generic config, implementation interprets
*/
virtual void initialize(const json& config) = 0;
/**
* @brief Update/render one frame
* @return true to continue, false to quit
*/
virtual bool update() = 0;
/**
* @brief Clean shutdown
*/
virtual void shutdown() = 0;
// ========================================
// GENERIC DATA FLOW
// ========================================
/**
* @brief Display any data of any type with layout/windowing info
* @param dataType "economy", "map", "inventory", "status", whatever
* @param data JSON with content + layout:
* {
* "content": {...}, // Actual data to display
* "window": { // Window/layout configuration
* "id": "economy_main", // Unique window ID
* "title": "Economy Dashboard",
* "parent": "main_dock", // Parent window/dock ID (optional)
* "dock": "left", // Dock position: "left", "right", "top", "bottom", "center", "tab"
* "size": {"width": 400, "height": 300},
* "position": {"x": 100, "y": 50},
* "floating": false, // true = floating window, false = docked
* "resizable": true,
* "closeable": true
* }
* }
*/
virtual void showData(const std::string& dataType, const json& data) = 0;
/**
* @brief Handle any user request of any type
* @param requestType "get_prices", "move_unit", "save_game", whatever
* @param callback Function to call when request happens
*/
virtual void onRequest(const std::string& requestType, std::function<void(const json&)> callback) = 0;
/**
* @brief Show any event/message
* @param level "info", "error", "debug", whatever
* @param message Human readable text
*/
virtual void showEvent(const std::string& level, const std::string& message) = 0;
// ========================================
// WINDOW MANAGEMENT
// ========================================
/**
* @brief Create or configure a dock/container window
* @param dockId Unique dock identifier
* @param config Dock configuration:
* {
* "type": "dock", // "dock", "tabbed", "split"
* "orientation": "horizontal", // "horizontal", "vertical" (for splits)
* "parent": "main_window", // Parent dock (for nested docks)
* "position": "left", // Initial position
* "size": {"width": 300}, // Initial size
* "collapsible": true, // Can be collapsed
* "tabs": true // Enable tabbed interface
* }
*/
virtual void createDock(const std::string& dockId, const json& config) = 0;
/**
* @brief Close/remove window or dock
* @param windowId Window or dock ID to close
*/
virtual void closeWindow(const std::string& windowId) = 0;
/**
* @brief Focus/bring to front a specific window
* @param windowId Window ID to focus
*/
virtual void focusWindow(const std::string& windowId) = 0;
// ========================================
// GENERIC STATE
// ========================================
/**
* @brief Get current UI state
* @return JSON state, implementation defines structure
*/
virtual json getState() const = 0;
/**
* @brief Restore UI state
* @param state JSON state from previous getState()
*/
virtual void setState(const json& state) = 0;
};
} // namespace grove