42LayerValue<std::size_t> parse_size_t(
const std::optional<std::string> &raw_value,
const std::string &option_name)
44 if (!raw_value.has_value()) {
48 const auto &str = raw_value.value();
51 std::size_t value = 0;
52 const auto *begin = str.data();
53 const auto *
end = str.data() + str.size();
54 auto [ptr, ec] = std::from_chars(begin,
end, value);
56 if (ec == std::errc{} && ptr ==
end) {
60 if (ec == std::errc::result_out_of_range) {
61 const auto error = std::format(
"Invalid value '{}' for '{}': value out of range.", str, option_name);
66 const auto error = std::format(
"Invalid value '{}' for '{}': not a valid integer.", str, option_name);
81LayerValue<bool> parse_bool(
const std::optional<std::string> &raw_value,
const std::string &option_name)
83 if (!raw_value.has_value()) {
87 const auto &str = raw_value.value();
96 const auto error = std::format(
"Invalid value '{}' for '{}': expected 'true' or 'false'.", str, option_name);
111LayerValue<Rgba32> parse_rgba32(
const std::optional<std::string> &raw_value,
const std::string &option_name)
113 if (!raw_value.has_value()) {
117 const auto &input = raw_value.value();
118 std::istringstream iss{input};
120 std::vector<int> values;
122 while (std::getline(iss, token,
',')) {
125 const auto *begin = token.data();
126 const auto *
end = token.data() + token.size();
127 auto [ptr, ec] = std::from_chars(begin,
end, val);
129 if (ec != std::errc{} || ptr !=
end) {
131 std::format(
"Invalid value '{}' for '{}': '{}' is not a valid integer.", input, option_name, token);
135 if (val < 0 || val > 255) {
136 const auto error = std::format(
137 "Invalid value '{}' for '{}': component {} is out of range (must be 0-255).", input, option_name, val);
141 values.push_back(val);
144 if (values.size() == 3) {
146 static_cast<std::uint8_t
>(values[0]),
147 static_cast<std::uint8_t
>(values[1]),
148 static_cast<std::uint8_t
>(values[2]),
153 if (values.size() == 4) {
155 static_cast<std::uint8_t
>(values[0]),
156 static_cast<std::uint8_t
>(values[1]),
157 static_cast<std::uint8_t
>(values[2]),
158 static_cast<std::uint8_t
>(values[3])};
162 const auto error = std::format(
163 "Invalid value '{}' for '{}': expected R,G,B or R,G,B,A format (got {} components).",
180LayerValue<std::string> parse_string(
const std::optional<std::string> &raw_value,
const std::string &option_name)
182 if (!raw_value.has_value()) {
204parse_string_vector(
const std::vector<std::string> &raw_values,
const std::string &option_name)
206 if (raw_values.empty()) {
225parse_artifact_edit_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
227 if (!raw_value.has_value()) {
231 const auto &str = raw_value.value();
234 if (result.has_value()) {
238 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
254parse_tiles_pal_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
256 if (!raw_value.has_value()) {
260 const auto &str = raw_value.value();
263 if (result.has_value()) {
267 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
283parse_anim_pal_resolution_strategy(
const std::optional<std::string> &raw_value,
const std::string &option_name)
285 if (!raw_value.has_value()) {
289 const auto &str = raw_value.value();
292 if (result.has_value()) {
296 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
312parse_anim_key_frame_resolution_strategy(
const std::optional<std::string> &raw_value,
const std::string &option_name)
314 if (!raw_value.has_value()) {
318 const auto &str = raw_value.value();
321 if (result.has_value()) {
325 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
341 const std::optional<std::string> &raw_value,
const std::string &option_name)
343 if (!raw_value.has_value()) {
347 const auto &str = raw_value.value();
350 if (result.has_value()) {
354 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
370parse_frame_linking(
const std::optional<std::string> &raw_value,
const std::string &option_name)
372 if (!raw_value.has_value()) {
376 const auto &str = raw_value.value();
379 if (result.has_value()) {
383 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
399parse_tile_sharing_packing(
const std::optional<std::string> &raw_value,
const std::string &option_name)
401 if (!raw_value.has_value()) {
405 const auto &str = raw_value.value();
408 if (result.has_value()) {
412 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
428parse_tile_sharing_alignment(
const std::optional<std::string> &raw_value,
const std::string &option_name)
430 if (!raw_value.has_value()) {
434 const auto &str = raw_value.value();
437 if (result.has_value()) {
441 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
446parse_packing_strategy_type(
const std::optional<std::string> &raw_value,
const std::string &option_name)
448 if (!raw_value.has_value()) {
452 const auto &str = raw_value.value();
455 if (result.has_value()) {
459 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
464parse_primary_pairing_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
466 if (!raw_value.has_value()) {
470 const auto &str = raw_value.value();
473 if (result.has_value()) {
477 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
Represents a 32-bit RGBA color.
std::optional< TilesPalMode > tiles_pal_mode_from_str(const std::string &str)
Parses a string into a TilesPalMode with fuzzy matching.
std::optional< ArtifactEditMode > artifact_edit_mode_from_str(const std::string &str)
Parses a string into a ArtifactEditMode with fuzzy matching.
std::optional< PackingStrategyType > packing_strategy_type_from_str(const std::string &str)
Parses a string into a PackingStrategyType with fuzzy matching.
std::optional< FrameLinking > frame_linking_from_str(const std::string &str)
Parses a string into a FrameLinking with fuzzy matching.
std::optional< PrimaryPairingMode > primary_pairing_mode_from_str(const std::string &str)
Parses a string into a PrimaryPairingMode with fuzzy matching.
std::optional< AnimPalResolutionStrategy > anim_pal_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimPalResolutionStrategy with fuzzy matching.
@ error
Emit a formatted error and fail decompilation.
std::optional< TileSharingPacking > tile_sharing_packing_from_str(const std::string &str)
Parses a string into a TileSharingPacking with fuzzy matching.
std::optional< TileSharingAlignment > tile_sharing_alignment_from_str(const std::string &str)
Parses a string into a TileSharingAlignment with fuzzy matching.
std::optional< AnimMultiPalSubtileResolutionStrategy > anim_multi_pal_subtile_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimMultiPalSubtileResolutionStrategy with fuzzy matching.
std::optional< AnimKeyFrameResolutionStrategy > anim_key_frame_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimKeyFrameResolutionStrategy with fuzzy matching.
A small container that holds an optional-wrapped value, validation state, and metadata about the valu...
static LayerValue valid(T val, std::string source_key, std::string source_info)
Creates a LayerValue representing a valid configuration value.
static LayerValue not_provided()
Creates a LayerValue representing that the provider does not supply this configuration.
static LayerValue invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.