Acaba la migració dels std::cout/cerr a Log::*:
- core/locale, core/ui/ui_config, core/rendering/{screen,text,gif,
surface, sprite/animated_sprite, sdl3gpu/*}.
- game/{options, debug_config, editor/editor_config, levels/level_manager,
map/{map,tilemap,paint_layer}, entities/entity_manager_loadlevel}.
Severitats coherents: warns per a configs absents amb fallback,
errors per a YAML malformat o E/S fallida, infos per a estats.
Resultat:
- 0 occurrences de std::cout/std::cerr a source/.
- Cap #include <iostream> orfà (eliminat de surface.cpp).
- Output funcional idèntic al històric; AEE_LOG filtra (ex.
`AEE_LOG=warn` només mostra warnings, `AEE_LOG=*:warn,Tag:info`
combina globals i overrides).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
86 lines
2.9 KiB
C++
86 lines
2.9 KiB
C++
#include "game/editor/editor_config.hpp"
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#include <cstdint>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
#include "core/resources/resource_helper.hpp"
|
|
#include "external/fkyaml_node.hpp"
|
|
#include "utils/defaults.hpp"
|
|
#include "utils/log.hpp"
|
|
|
|
namespace {
|
|
|
|
template <typename T>
|
|
void readField(const fkyaml::node& node, const char* key, T& dst) {
|
|
if (node.contains(key)) { dst = node[key].get_value<T>(); }
|
|
}
|
|
|
|
// Llegeix un color ARGB. Accepta enter (0xFF2244FF al YAML) o cadena
|
|
// ("0xFF2244FF" / "#FF2244FF"). std::stoul amb base=0 detecta el prefix
|
|
// "0x" automàticament; si el valor és invàlid, deixem `dst` intacte i
|
|
// avisem perquè l'error no passi en silenci.
|
|
void readArgb(const fkyaml::node& node, const char* key, std::uint32_t& dst) {
|
|
if (!node.contains(key)) { return; }
|
|
try {
|
|
const auto& v = node[key];
|
|
if (v.is_integer()) {
|
|
dst = static_cast<std::uint32_t>(v.get_value<std::uint64_t>());
|
|
return;
|
|
}
|
|
auto s = v.get_value<std::string>();
|
|
if (!s.empty() && s.front() == '#') { s.erase(0, 1); }
|
|
dst = static_cast<std::uint32_t>(std::stoul(s, nullptr, 0));
|
|
} catch (const std::exception& e) {
|
|
Log::warn("EditorConfig", "color '{}' invàlid ({}) — ignorat", key, e.what());
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
EditorConfig::EditorConfig()
|
|
: picker_margin_(Defaults::Editor::PICKER_MARGIN),
|
|
picker_spacing_(Defaults::Editor::PICKER_SPACING),
|
|
border_argb_(Defaults::Editor::BORDER_ARGB),
|
|
picker_bg_argb_(Defaults::Editor::PICKER_BG_ARGB),
|
|
picker_hover_argb_(Defaults::Editor::PICKER_HOVER_ARGB) {
|
|
}
|
|
|
|
auto EditorConfig::get() -> EditorConfig& {
|
|
static EditorConfig instance_;
|
|
return instance_;
|
|
}
|
|
|
|
void EditorConfig::load(const std::string& file_path) {
|
|
auto bytes = Resource::Helper::loadFile(file_path);
|
|
if (bytes.empty()) {
|
|
Log::warn("EditorConfig", "no s'ha pogut obrir {} — s'usaran els defaults compilats", file_path);
|
|
return;
|
|
}
|
|
try {
|
|
const auto* begin = reinterpret_cast<const char*>(bytes.data());
|
|
const auto* end = begin + bytes.size();
|
|
auto yaml = fkyaml::node::deserialize(begin, end);
|
|
|
|
if (yaml.contains("picker")) {
|
|
const auto& p = yaml["picker"];
|
|
readField(p, "margin", picker_margin_);
|
|
readField(p, "spacing", picker_spacing_);
|
|
}
|
|
if (yaml.contains("colors")) {
|
|
const auto& c = yaml["colors"];
|
|
readArgb(c, "border", border_argb_);
|
|
readArgb(c, "picker_bg", picker_bg_argb_);
|
|
readArgb(c, "picker_hover", picker_hover_argb_);
|
|
}
|
|
|
|
Log::info("EditorConfig", "carregat des de {}", file_path);
|
|
} catch (const std::exception& e) {
|
|
Log::error("EditorConfig", "error parsejant {}: {}", file_path, e.what());
|
|
}
|
|
}
|
|
|
|
#endif // _DEBUG
|