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/*
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
29enum class FrameLinking {
37 manual,
41 hybrid
42};
43
59[[nodiscard]] inline std::optional<FrameLinking> frame_linking_from_str(const std::string &str)
60{
61 // Phase 1: Exact match against C++ constant names
62 if (str == "automatic") {
63 return std::optional{ FrameLinking::automatic };
64 }
65 if (str == "manual") {
66 return std::optional{ FrameLinking::manual };
67 }
68 if (str == "hybrid") {
69 return std::optional{ FrameLinking::hybrid };
70 }
71
72 // Phase 2: Case-insensitive fuzzy match
73 std::string lower_str = str;
74 std::ranges::transform(
75 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
76
77 // Fuzzy names for automatic
78 if (lower_str == "automatic") {
79 return std::optional{ FrameLinking::automatic };
80 }
81 if (lower_str == "auto") {
82 return std::optional{ FrameLinking::automatic };
83 }
84 // Fuzzy names for manual
85 if (lower_str == "manual") {
86 return std::optional{ FrameLinking::manual };
87 }
88 // Fuzzy names for hybrid
89 if (lower_str == "hybrid") {
90 return std::optional{ FrameLinking::hybrid };
91 }
92
93 return std::nullopt;
94}
95
106[[nodiscard]] inline std::string to_string(const FrameLinking m)
107{
108 switch (m) {
110 return "automatic";
112 return "manual";
114 return "hybrid";
115 }
116 panic("unhandled FrameLinking value");
117}
118
126inline std::ostream &operator<<(std::ostream &os, const FrameLinking m)
127{
128 return os << to_string(m);
129}
130
131} // namespace porytiles
132
133template <>
134struct std::formatter<porytiles::FrameLinking> {
135 constexpr auto parse(std::format_parse_context &ctx)
136 {
137 return ctx.begin();
138 }
139
140 auto format(const porytiles::FrameLinking &value, auto &ctx) const
141 {
142 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
143 }
144};
@ 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