Files
Boundard/include/config.hpp
T

71 lines
1.5 KiB
C++

#pragma once
#include <array>
#include <cstdint>
#include <string>
#include <vector>
namespace boundard {
struct WindowConfig {
int width = 800;
int height = 600;
std::string title = "OpenCGE";
};
struct MeshConfig {
std::string shape = "quad";
std::string texture;
std::array<float, 4> color{0.5F, 0.5F, 0.5F, 1.0F};
};
struct ActorConfig {
std::string name;
std::string type = "actor";
std::string init_function;
std::string tick_function;
std::array<float, 2> position{0.0F, 0.0F};
std::array<float, 2> facing{1.0F, 0.0F};
float zoom = 1.0F;
MeshConfig mesh;
std::vector<ActorConfig> children;
};
struct InputBindingConfig {
std::string action;
std::vector<int> keys;
std::vector<int> mouse_buttons;
};
struct SceneConfig {
std::string name;
std::string path;
std::vector<ActorConfig> actors;
std::string default_camera;
bool grid_background = false;
};
struct GameConfig {
WindowConfig window;
std::vector<InputBindingConfig> input_bindings;
std::vector<SceneConfig> scenes;
std::string start_scene;
// 兼容旧的单场景写法:直接写在游戏配置里的 actors。
std::vector<ActorConfig> actors;
};
// 从 JSON 加载游戏场景配置(类似 Godot 的场景描述)。
class ConfigLoader {
public:
bool load(const std::string& path);
const GameConfig& config() const;
const std::string& last_error() const;
private:
GameConfig config_;
std::string last_error_;
};
} // namespace boundard