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>
105 lines
3.4 KiB
C++
105 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <stdexcept>
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include "IEngine.h"
|
|
#include "DebugEngine.h"
|
|
|
|
namespace grove {
|
|
|
|
/**
|
|
* @brief Factory for creating engine implementations
|
|
*
|
|
* EngineFactory provides a centralized way to create different engine types
|
|
* based on configuration or runtime requirements.
|
|
*
|
|
* Supported engine types:
|
|
* - "debug" or "DEBUG" -> DebugEngine (maximum logging, step debugging)
|
|
* - "production" or "PRODUCTION" -> ProductionEngine (future implementation)
|
|
* - "high_performance" or "HIGH_PERFORMANCE" -> HighPerformanceEngine (future)
|
|
*
|
|
* Usage:
|
|
* ```cpp
|
|
* auto engine = EngineFactory::createEngine("debug");
|
|
* auto engine = EngineFactory::createEngine(EngineType::DEBUG);
|
|
* auto engine = EngineFactory::createFromConfig("config/engine.json");
|
|
* ```
|
|
*/
|
|
class EngineFactory {
|
|
public:
|
|
/**
|
|
* @brief Create engine from string type
|
|
* @param engineType String representation of engine type
|
|
* @return Unique pointer to engine implementation
|
|
* @throws std::invalid_argument if engine type is unknown
|
|
*/
|
|
static std::unique_ptr<IEngine> createEngine(const std::string& engineType);
|
|
|
|
/**
|
|
* @brief Create engine from enum type
|
|
* @param engineType Engine type enum value
|
|
* @return Unique pointer to engine implementation
|
|
* @throws std::invalid_argument if engine type is not implemented
|
|
*/
|
|
static std::unique_ptr<IEngine> createEngine(EngineType engineType);
|
|
|
|
/**
|
|
* @brief Create engine from configuration file
|
|
* @param configPath Path to JSON configuration file
|
|
* @return Unique pointer to engine implementation
|
|
* @throws std::runtime_error if config file cannot be read
|
|
* @throws std::invalid_argument if engine type in config is invalid
|
|
*
|
|
* Expected config format:
|
|
* ```json
|
|
* {
|
|
* "engine": {
|
|
* "type": "debug",
|
|
* "log_level": "trace",
|
|
* "features": {
|
|
* "step_debugging": true,
|
|
* "performance_monitoring": true
|
|
* }
|
|
* }
|
|
* }
|
|
* ```
|
|
*/
|
|
static std::unique_ptr<IEngine> createFromConfig(const std::string& configPath);
|
|
|
|
/**
|
|
* @brief Get list of available engine types
|
|
* @return Vector of supported engine type strings
|
|
*/
|
|
static std::vector<std::string> getAvailableEngineTypes();
|
|
|
|
/**
|
|
* @brief Check if engine type is supported
|
|
* @param engineType Engine type string to check
|
|
* @return True if engine type is supported
|
|
*/
|
|
static bool isEngineTypeSupported(const std::string& engineType);
|
|
|
|
/**
|
|
* @brief Get engine type from string (case-insensitive)
|
|
* @param engineTypeStr String representation of engine type
|
|
* @return EngineType enum value
|
|
* @throws std::invalid_argument if string is not a valid engine type
|
|
*/
|
|
static EngineType parseEngineType(const std::string& engineTypeStr);
|
|
|
|
/**
|
|
* @brief Convert engine type enum to string
|
|
* @param engineType Engine type enum value
|
|
* @return String representation of engine type
|
|
*/
|
|
static std::string engineTypeToString(EngineType engineType);
|
|
|
|
private:
|
|
static std::shared_ptr<spdlog::logger> getFactoryLogger();
|
|
static std::string toLowercase(const std::string& str);
|
|
};
|
|
|
|
} // namespace grove
|