Porytiles
Loading...
Searching...
No Matches
frame_linking.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
25enum class FrameLinking {
29 manual,
31 hybrid
32};
33
47[[nodiscard]] inline std::optional<FrameLinking> frame_linking_from_str(const std::string &str)
48{
49 // Phase 1: Exact match against C++ constant names
50 if (str == "automatic") {
51 return std::optional{FrameLinking::automatic};
52 }
53 if (str == "manual") {
54 return std::optional{FrameLinking::manual};
55 }
56 if (str == "hybrid") {
57 return std::optional{FrameLinking::hybrid};
58 }
59
60 // Phase 2: Case-insensitive fuzzy match
61 std::string lower_str = str;
62 std::ranges::transform(
63 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
64
65 // Fuzzy names for automatic
66 if (lower_str == "automatic") {
67 return std::optional{FrameLinking::automatic};
68 }
69 if (lower_str == "auto") {
70 return std::optional{FrameLinking::automatic};
71 }
72 // Fuzzy names for manual
73 if (lower_str == "manual") {
74 return std::optional{FrameLinking::manual};
75 }
76 // Fuzzy names for hybrid
77 if (lower_str == "hybrid") {
78 return std::optional{FrameLinking::hybrid};
79 }
80
81 return std::nullopt;
82}
83
92[[nodiscard]] inline std::string to_string(const FrameLinking m)
93{
94 switch (m) {
96 return "automatic";
98 return "manual";
100 return "hybrid";
101 }
102 panic("unhandled FrameLinking value");
103}
104
110inline std::ostream &operator<<(std::ostream &os, const FrameLinking m)
111{
112 return os << to_string(m);
113}
114
115} // namespace porytiles
116
117template <>
118struct std::formatter<porytiles::FrameLinking> {
119 constexpr auto parse(std::format_parse_context &ctx)
120 {
121 return ctx.begin();
122 }
123
124 auto format(const porytiles::FrameLinking &value, auto &ctx) const
125 {
126 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
127 }
128};
@ automatic
Scan layout metadata to find the partner primary automatically.
@ manual
Use the partner primary specified via primary_pairing_partners config.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
std::optional< FrameLinking > frame_linking_from_str(const std::string &str)
Parses a string into a FrameLinking with fuzzy matching.
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
FrameLinking
Controls how animation frames are linked to metatile entries.
@ automatic
Use key.png for frame linking.
@ manual
Use manual overrides in anim.json.
@ hybrid
Automatic key.png linking plus manual override pass (not yet implemented).
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
constexpr auto parse(std::format_parse_context &ctx)
auto format(const porytiles::FrameLinking &value, auto &ctx) const