Porytiles
Loading...
Searching...
No Matches
anim_key_frame_resolution_strategy.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cctype>
5#include <format>
6#include <optional>
7#include <ostream>
8#include <string>
9
11
12/*
13 * NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
14 * To add new config values or make other changes, edit config_schema.yaml and regenerate via:
15 *
16 * uv run scripts/generate_config.py
17 */
18
19namespace porytiles {
20
34 error,
38 warning,
42 mangle
43};
44
60[[nodiscard]] inline std::optional<AnimKeyFrameResolutionStrategy> anim_key_frame_resolution_strategy_from_str(const std::string &str)
61{
62 // Phase 1: Exact match against C++ constant names
63 if (str == "error") {
64 return std::optional{ AnimKeyFrameResolutionStrategy::error };
65 }
66 if (str == "warning") {
67 return std::optional{ AnimKeyFrameResolutionStrategy::warning };
68 }
69 if (str == "mangle") {
70 return std::optional{ AnimKeyFrameResolutionStrategy::mangle };
71 }
72
73 // Phase 2: Case-insensitive fuzzy match
74 std::string lower_str = str;
75 std::ranges::transform(
76 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
77
78 // Fuzzy names for error
79 if (lower_str == "error") {
80 return std::optional{ AnimKeyFrameResolutionStrategy::error };
81 }
82 if (lower_str == "err") {
83 return std::optional{ AnimKeyFrameResolutionStrategy::error };
84 }
85 // Fuzzy names for warning
86 if (lower_str == "warning") {
87 return std::optional{ AnimKeyFrameResolutionStrategy::warning };
88 }
89 if (lower_str == "warn") {
90 return std::optional{ AnimKeyFrameResolutionStrategy::warning };
91 }
92 // Fuzzy names for mangle
93 if (lower_str == "mangle") {
94 return std::optional{ AnimKeyFrameResolutionStrategy::mangle };
95 }
96
97 return std::nullopt;
98}
99
110[[nodiscard]] inline std::string to_string(const AnimKeyFrameResolutionStrategy m)
111{
112 switch (m) {
114 return "error";
116 return "warning";
118 return "mangle";
119 }
120 panic("unhandled AnimKeyFrameResolutionStrategy value");
121}
122
130inline std::ostream &operator<<(std::ostream &os, const AnimKeyFrameResolutionStrategy m)
131{
132 return os << to_string(m);
133}
134
135} // namespace porytiles
136
137template <>
138struct std::formatter<porytiles::AnimKeyFrameResolutionStrategy> {
139 constexpr auto parse(std::format_parse_context &ctx)
140 {
141 return ctx.begin();
142 }
143
144 auto format(const porytiles::AnimKeyFrameResolutionStrategy &value, auto &ctx) const
145 {
146 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
147 }
148};
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
AnimKeyFrameResolutionStrategy
Strategy for handling duplicate key frame tiles in animation decompilation.
@ warning
Emit a warning and continue decompilation.
@ mangle
Mangle duplicate tiles to make them unique, then backport changes to tiles.png.
@ error
Emit a formatted error and fail decompilation.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
std::optional< AnimKeyFrameResolutionStrategy > anim_key_frame_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimKeyFrameResolutionStrategy with fuzzy matching.
auto format(const porytiles::AnimKeyFrameResolutionStrategy &value, auto &ctx) const