feat(editor): spacing, border i centrat vertical del tilepicker via editor.yaml
This commit is contained in:
1 parent
bcbf990a5f
commit
a53cf4b797
7 files changed
+235
-29
No files matched your search
@@ -0,0 +1,85 @@
|
||||
#include "game/editor/editor_config.hpp"
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
#include "external/fkyaml_node.hpp"
|
||||
#include "utils/defaults.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) {
|
||||
std::cerr << "EditorConfig: color '" << key << "' invàlid (" << e.what() << ") — ignorat\n";
|
||||
}
|
||||
}
|
||||
|
||||
} // 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()) {
|
||||
std::cerr << "EditorConfig: no s'ha pogut obrir " << file_path << " — s'usaran els defaults compilats\n";
|
||||
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_);
|
||||
}
|
||||
|
||||
std::cout << "EditorConfig: carregat des de " << file_path << '\n';
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "EditorConfig: error parsejant " << file_path << ": " << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _DEBUG
|
||||
Reference in new issue
Block a user