Porytiles
Loading...
Searching...
No Matches
domain_config_validators.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <cstddef>
13#include <functional>
14#include <string>
15#include <vector>
16
23
24namespace porytiles {
25
34{
35 if (val.value().alpha() != Rgba32::alpha_opaque) {
36 std::vector<std::string> err_text{};
37 std::vector<std::vector<FormatParam>> params{};
38
39 err_text.emplace_back("'{}' alpha component '{}' is not opaque ('{}').");
40 params.emplace_back(
41 std::vector{
43 FormatParam{std::to_string(val.value().alpha()), Style::bold},
45 err_text.emplace_back("");
46 params.emplace_back();
47
48 auto [format_text, format_params] = val.format_data();
49 err_text.append_range(format_text);
50 params.append_range(format_params);
51 return FormattableError{err_text, params};
52 }
53 return val;
54}
55
75template <typename T, typename ConfigInterface, typename FetchFunc>
77 const ConfigValue<T> &val,
78 const ConfigInterface &config,
79 ConfigScopeType type,
80 const std::string &scope,
81 const std::string &other_field_name,
82 FetchFunc fetch_other)
83{
84 if (val.value() == TileSharingPacking::off) {
85 return val;
86 }
87
88 auto other_result = fetch_other(config, type, scope);
89
90 if (!other_result.has_value()) {
91 return other_result.error();
92 }
93
94 const auto &other_val = other_result.value();
95
96 if (other_val.value() != PackingStrategyType::backtracking) {
97 std::vector<std::string> err_text{};
98 std::vector<std::vector<FormatParam>> params{};
99
100 err_text.emplace_back("'{}' set to '{}' requires '{}' to be '{}'.");
101 params.emplace_back(
102 std::vector{
105 FormatParam{other_field_name, Style::bold},
107 err_text.emplace_back("");
108 params.emplace_back();
109
110 auto [format_text, format_params] = val.format_data();
111 err_text.append_range(format_text);
112 params.append_range(format_params);
113
114 err_text.emplace_back("");
115 params.emplace_back();
116 err_text.emplace_back("{}");
117 params.emplace_back(std::vector{FormatParam{"Comparison value:", Style::italic}});
118 err_text.emplace_back("");
119 params.emplace_back();
120
121 auto [other_format_text, other_format_params] = other_val.format_data();
122 err_text.append_range(other_format_text);
123 params.append_range(other_format_params);
124
125 return FormattableError{err_text, params};
126 }
127
128 return val;
129}
130
131} // namespace porytiles
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A container that wraps a configuration value with its name and source information.
std::pair< std::vector< std::string >, std::vector< std::vector< FormatParam > > > format_data() const
Generates formatted text data for displaying this configuration value.
const std::string & canonical_name() const
const T & value() const &
A text parameter with associated styling for formatted output.
General-purpose error implementation with formatted message support.
Definition error.hpp:63
static constexpr std::uint8_t alpha_opaque
Definition rgba32.hpp:26
static const Style italic
Italic text formatting.
static const Style bold
Bold text formatting.
ChainableResult< ConfigValue< T > > require_packing_strategy_backtracking(const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other)
Validates that 'biased' or 'optimal' tile sharing packing requires 'backtracking' packing strategy.
@ off
Packing ignores shape group membership (default).
ConfigScopeType
Specifies the scope type for configuration value lookups.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
ChainableResult< ConfigValue< Rgba32 > > rgba_alpha_component_opaque(const ConfigValue< Rgba32 > &val)
Validates that an Rgba32 alpha component is opaque.
@ backtracking
DFS/BFS backtracking search (default).