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>
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace grove {
|
|
|
|
class Resource {
|
|
private:
|
|
std::string resource_id;
|
|
std::string name;
|
|
std::string category;
|
|
std::string logistic_category;
|
|
float density;
|
|
int stack_size;
|
|
std::string container_type;
|
|
json ui_data;
|
|
|
|
public:
|
|
Resource() = default;
|
|
Resource(const json& resource_data);
|
|
|
|
const std::string& getResourceId() const { return resource_id; }
|
|
const std::string& getName() const { return name; }
|
|
const std::string& getCategory() const { return category; }
|
|
const std::string& getLogisticCategory() const { return logistic_category; }
|
|
float getDensity() const { return density; }
|
|
int getStackSize() const { return stack_size; }
|
|
const std::string& getContainerType() const { return container_type; }
|
|
const json& getUIData() const { return ui_data; }
|
|
|
|
static Resource loadFromJson(const std::string& resource_id, const json& resource_data);
|
|
};
|
|
|
|
} // namespace grove
|