mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
Load config using JSON
This commit is contained in:
@@ -18,6 +18,9 @@ bool GameApplication::initialize() {
|
||||
SDL_Log("无法初始化 SDL_ttf: %s", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
if (!ConfigLoader::load("assets/config.json", m_config)) {
|
||||
SDL_Log("无法加载json");
|
||||
}
|
||||
// 输入管理
|
||||
m_inputManager = std::make_unique<InputManager>();
|
||||
// 窗口管理
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "scenes/base/SceneManager.h"
|
||||
#include "input/InputManager.h"
|
||||
#include "utils/Config.h"
|
||||
|
||||
#include "utils/ConfigLoader.h"
|
||||
#include "graphics/font/TextRenderer.h"
|
||||
#include "graphics/font/FontManager.h"
|
||||
|
||||
@@ -21,7 +21,7 @@ private:
|
||||
std::unique_ptr<TextRenderer> m_textRenderer;
|
||||
std::unique_ptr<UIRenderer> m_uiRenderer;
|
||||
|
||||
WindowConfig m_config;
|
||||
Config m_config;
|
||||
|
||||
public:
|
||||
GameApplication();
|
||||
|
||||
@@ -10,17 +10,18 @@ WindowManager::~WindowManager() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
bool WindowManager::Initialize(WindowConfig& config) {
|
||||
m_viewport.logicalWidth = config.logicalWidth;
|
||||
m_viewport.logicalHeight = config.logicalHeight;
|
||||
bool WindowManager::Initialize(Config& config) {
|
||||
m_viewport.logicalWidth = config.render.logicalWidth;
|
||||
m_viewport.logicalHeight = config.render.logicalHeight;
|
||||
// 创建窗口(支持高DPI和横屏)[3,4](@ref)
|
||||
m_window = SDL_CreateWindow(
|
||||
"孢子棋", // 窗口标题,显示在标题栏上
|
||||
m_viewport.logicalWidth, // 窗口的逻辑宽度(例如 800),用于统一布局,不受屏幕 DPI 影响
|
||||
m_viewport.logicalHeight, // 窗口的逻辑高度(例如 600)
|
||||
config.window.title.c_str(), // 窗口标题,显示在标题栏上
|
||||
config.window.width, // 窗口的逻辑宽度(例如 800),用于统一布局,不受屏幕 DPI 影响
|
||||
config.window.height, // 窗口的逻辑高度(例如 600)
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | // 启用高像素密度支持(HiDPI/Retina),确保在高分屏上画面清晰
|
||||
SDL_WINDOW_RESIZABLE // 允许用户调整窗口大小(可拉伸)
|
||||
);
|
||||
//SDL_Log("window width %d\nwindow height %d\ntitle %s\n", config.window.width, config.window.height, config.window.title);
|
||||
if (!m_window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"创建窗口失败: %s", SDL_GetError());
|
||||
@@ -44,7 +45,7 @@ bool WindowManager::Initialize(WindowConfig& config) {
|
||||
m_height,
|
||||
SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
*/
|
||||
SDL_SetWindowSize(m_window, UI::StartWindowWidth, UI::StartWindowHeight);
|
||||
//SDL_SetWindowSize(m_window, UI::StartWindowWidth, UI::StartWindowHeight);
|
||||
// 创建逻辑画布
|
||||
// RGBA8888: 32位色,8位红绿蓝和透明度
|
||||
// TARGET: 纹理可作为渲染目标
|
||||
|
||||
@@ -6,7 +6,7 @@ public:
|
||||
WindowManager();
|
||||
~WindowManager();
|
||||
// 初始化
|
||||
bool Initialize(WindowConfig& config);
|
||||
bool Initialize(Config& config);
|
||||
//关闭
|
||||
void Shutdown();
|
||||
//清理上一帧窗口
|
||||
|
||||
Reference in New Issue
Block a user