refactor(#28): renombrar Options → ConfigYaml + netejar aliases
Pas 7 final del hallazgo #28. La capa de game/options havia esdevingut exclusivament una capa de persistència YAML que llegia i escrivia Config::EngineConfig. El nom "Options" no reflectia bé aquest rol. Canvis: - Renomenats fitxers: game/options.{hpp,cpp} → game/config_yaml.{hpp,cpp} (preservant la història de git via mv). - Renomenat namespace: Options → ConfigYaml. - Esborrades del .hpp les referències-alias inline (window, rendering, player1, player2, keyboard_controls, gamepad_controls, console) que ja no tenien call-sites externs (només existien per a la transició). El .hpp ara només exposa engine_config + version + path + funcions. - A config_yaml.cpp s'introdueixen aliases internes (anonymous namespace) per mantenir llegible el codi de la implementació, sense exposar-les. - Actualitzat main.cpp per a usar ConfigYaml::*. - Actualitzats els comentaris stale a sdl_manager.hpp, director.hpp, engine_config.hpp i audio.hpp. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "options.hpp"
|
||||
#include "config_yaml.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -9,7 +9,17 @@
|
||||
#include "external/fkyaml_node.hpp"
|
||||
#include "project.h"
|
||||
|
||||
namespace Options {
|
||||
namespace ConfigYaml {
|
||||
|
||||
namespace {
|
||||
// Aliases internes per a la implementació, no exposades al .hpp.
|
||||
// Permeten escriure window.width en lloc d'engine_config.window.width.
|
||||
Config::WindowConfig& window = engine_config.window;
|
||||
Config::RenderingConfig& rendering = engine_config.rendering;
|
||||
Config::PlayerBindings& player1 = engine_config.player1;
|
||||
Config::PlayerBindings& player2 = engine_config.player2;
|
||||
bool& console = engine_config.console;
|
||||
} // namespace
|
||||
|
||||
// ========== FUNCIONS AUXILIARS PER CONVERSIÓ DE CONTROLES ==========
|
||||
|
||||
@@ -506,4 +516,4 @@ namespace Options {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Options
|
||||
} // namespace ConfigYaml
|
||||
@@ -0,0 +1,43 @@
|
||||
// config_yaml.hpp - Capa de persistència YAML de Config::EngineConfig
|
||||
// © 2026 JailDesigner
|
||||
//
|
||||
// La configuració runtime viu en Config::EngineConfig (core/config/).
|
||||
// Aquest fitxer afegeix una capa de persistència YAML que llegeix i
|
||||
// escriu aquesta struct a disc. La connexió amb el Director es fa via
|
||||
// Config::ConfigPersistence (lambdes a `main.cpp`), mantenint `core/`
|
||||
// agnòstic respecte d'aquesta capa.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/config/engine_config.hpp"
|
||||
|
||||
namespace ConfigYaml {
|
||||
|
||||
// Única font de veritat de la configuració runtime. La capa YAML llegeix
|
||||
// i escriu aquí; els consumidors (Director i sistemes de core/) reben
|
||||
// referència a aquesta struct via injecció.
|
||||
inline Config::EngineConfig engine_config{
|
||||
.player2 = {
|
||||
.keyboard = {
|
||||
.key_left = SDL_SCANCODE_A,
|
||||
.key_right = SDL_SCANCODE_D,
|
||||
.key_thrust = SDL_SCANCODE_W,
|
||||
.key_shoot = SDL_SCANCODE_LSHIFT,
|
||||
.key_start = SDL_SCANCODE_2,
|
||||
},
|
||||
.gamepad_name = "",
|
||||
},
|
||||
};
|
||||
|
||||
// Persistència YAML (no exposada a `core/`).
|
||||
inline std::string version{}; // Versión del config per validació
|
||||
inline std::string config_file_path{}; // Establert per setConfigFile()
|
||||
|
||||
void init(); // Inicialitzar engine_config amb els valors per defecte
|
||||
void setConfigFile(const std::string& path);
|
||||
auto loadFromFile() -> bool;
|
||||
auto saveToFile() -> bool;
|
||||
|
||||
} // namespace ConfigYaml
|
||||
@@ -1,56 +0,0 @@
|
||||
// options.hpp - Persistència YAML i globals d'opcions (capa game)
|
||||
// © 2026 JailDesigner
|
||||
//
|
||||
// La configuració runtime viu en una struct única (Config::EngineConfig,
|
||||
// definida a `core/config/engine_config.hpp`). Aquest fitxer hi posa al
|
||||
// damunt la capa de persistència YAML i les compatibilitats històriques
|
||||
// (Options::window, Options::rendering, ...) com a referències inline a
|
||||
// camps d'aquesta struct. Cost runtime zero, callsites existents no
|
||||
// requereixen cap canvi.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/config/engine_config.hpp"
|
||||
|
||||
namespace Options {
|
||||
|
||||
// Única font de veritat de la configuració runtime. Tota la resta de
|
||||
// globals d'aquest namespace són referències inline a camps d'aquesta
|
||||
// struct.
|
||||
inline Config::EngineConfig engine_config{
|
||||
.player2 = {
|
||||
.keyboard = {
|
||||
.key_left = SDL_SCANCODE_A,
|
||||
.key_right = SDL_SCANCODE_D,
|
||||
.key_thrust = SDL_SCANCODE_W,
|
||||
.key_shoot = SDL_SCANCODE_LSHIFT,
|
||||
.key_start = SDL_SCANCODE_2,
|
||||
},
|
||||
.gamepad_name = "",
|
||||
},
|
||||
};
|
||||
|
||||
// Aliases (referències) per al codi existent.
|
||||
inline Config::WindowConfig& window = engine_config.window;
|
||||
inline Config::RenderingConfig& rendering = engine_config.rendering;
|
||||
inline Config::PlayerBindings& player1 = engine_config.player1;
|
||||
inline Config::PlayerBindings& player2 = engine_config.player2;
|
||||
inline Config::KeyboardBindings& keyboard_controls = engine_config.keyboard_controls;
|
||||
inline Config::GamepadBindings& gamepad_controls = engine_config.gamepad_controls;
|
||||
inline bool& console = engine_config.console;
|
||||
|
||||
// Persistència YAML (es queda en game/, no en core/)
|
||||
inline std::string version{}; // Versión del config per validació
|
||||
inline std::string config_file_path{}; // Establert per setConfigFile()
|
||||
|
||||
// Funciones públiques
|
||||
|
||||
void init(); // Inicialitzar con valors per defecte
|
||||
void setConfigFile(
|
||||
const std::string& path); // Establir ruta del file de config
|
||||
auto loadFromFile() -> bool; // Carregar config YAML
|
||||
auto saveToFile() -> bool; // Guardar config YAML
|
||||
|
||||
} // namespace Options
|
||||
Reference in New Issue
Block a user