Porytiles
Loading...
Searching...
No Matches
domain_config_validators.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <cstddef>
11#include <functional>
12#include <string>
13#include <vector>
14
21
22namespace porytiles {
23
30{
31 if (val.value().alpha() != Rgba32::alpha_opaque) {
32 std::vector<std::string> err_text{};
33 std::vector<std::vector<FormatParam>> params{};
34
35 err_text.emplace_back("'{}' alpha component '{}' is not opaque ('{}').");
36 params.emplace_back(
37 std::vector{
39 FormatParam{std::to_string(val.value().alpha()), Style::bold},
41 err_text.emplace_back("");
42 params.emplace_back();
43
44 auto [format_text, format_params] = val.format_data();
45 err_text.append_range(format_text);
46 params.append_range(format_params);
47 return FormattableError{err_text, params};
48 }
49 return val;
50}
51
69template <typename T, typename ConfigInterface, typename FetchFunc>
71 const ConfigValue<T> &val,
72 const ConfigInterface &config,
73 ConfigScopeType type,
74 const std::string &scope,
75 const std::string &other_field_name,
76 FetchFunc fetch_other)
77{
78 if (val.value() == TileSharingPacking::off) {
79 return val;
80 }
81
82 auto other_result = fetch_other(config, type, scope);
83
84 if (!other_result.has_value()) {
85 return other_result.error();
86 }
87
88 const auto &other_val = other_result.value();
89
90 if (other_val.value() != PackingStrategyType::backtracking) {
91 std::vector<std::string> err_text{};
92 std::vector<std::vector<FormatParam>> params{};
93
94 err_text.emplace_back("'{}' set to '{}' requires '{}' to be '{}'.");
95 params.emplace_back(
96 std::vector{
99 FormatParam{other_field_name, Style::bold},
101 err_text.emplace_back("");
102 params.emplace_back();
103
104 auto [format_text, format_params] = val.format_data();
105 err_text.append_range(format_text);
106 params.append_range(format_params);
107
108 err_text.emplace_back("");
109 params.emplace_back();
110 err_text.emplace_back("{}");
111 params.emplace_back(std::vector{FormatParam{"Comparison value:", Style::italic}});
112 err_text.emplace_back("");
113 params.emplace_back();
114
115 auto [other_format_text, other_format_params] = other_val.format_data();
116 err_text.append_range(other_format_text);
117 params.append_range(other_format_params);
118
119 return FormattableError{err_text, params};
120 }
121
122 return val;
123}
124
125} // 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:57
static constexpr std::uint8_t alpha_opaque
Definition rgba32.hpp:24
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).