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// NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
13// To add new config values or make other changes, edit config_schema.yaml and regenerate via:
14//
15// uv run scripts/generate_config.py
16
17namespace porytiles {
18
28 error,
30 warning,
32 mangle
33};
34
48[[nodiscard]] inline std::optional<AnimKeyFrameResolutionStrategy>
50{
51 // Phase 1: Exact match against C++ constant names
52 if (str == "error") {
53 return std::optional{AnimKeyFrameResolutionStrategy::error};
54 }
55 if (str == "warning") {
56 return std::optional{AnimKeyFrameResolutionStrategy::warning};
57 }
58 if (str == "mangle") {
59 return std::optional{AnimKeyFrameResolutionStrategy::mangle};
60 }
61
62 // Phase 2: Case-insensitive fuzzy match
63 std::string lower_str = str;
64 std::ranges::transform(
65 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
66
67 // Fuzzy names for error
68 if (lower_str == "error") {
69 return std::optional{AnimKeyFrameResolutionStrategy::error};
70 }
71 if (lower_str == "err") {
72 return std::optional{AnimKeyFrameResolutionStrategy::error};
73 }
74 // Fuzzy names for warning
75 if (lower_str == "warning") {
76 return std::optional{AnimKeyFrameResolutionStrategy::warning};
77 }
78 if (lower_str == "warn") {
79 return std::optional{AnimKeyFrameResolutionStrategy::warning};
80 }
81 // Fuzzy names for mangle
82 if (lower_str == "mangle") {
83 return std::optional{AnimKeyFrameResolutionStrategy::mangle};
84 }
85
86 return std::nullopt;
87}
88
97[[nodiscard]] inline std::string to_string(const AnimKeyFrameResolutionStrategy m)
98{
99 switch (m) {
101 return "error";
103 return "warning";
105 return "mangle";
106 }
107 panic("unhandled AnimKeyFrameResolutionStrategy value");
108}
109
115inline std::ostream &operator<<(std::ostream &os, const AnimKeyFrameResolutionStrategy m)
116{
117 return os << to_string(m);
118}
119
120} // namespace porytiles
121
122template <>
123struct std::formatter<porytiles::AnimKeyFrameResolutionStrategy> {
124 constexpr auto parse(std::format_parse_context &ctx)
125 {
126 return ctx.begin();
127 }
128
129 auto format(const porytiles::AnimKeyFrameResolutionStrategy &value, auto &ctx) const
130 {
131 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
132 }
133};
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