Porytiles
Loading...
Searching...
No Matches
primary_pairing_mode.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 off,
38 manual,
43};
44
60[[nodiscard]] inline std::optional<PrimaryPairingMode> primary_pairing_mode_from_str(const std::string &str)
61{
62 // Phase 1: Exact match against C++ constant names
63 if (str == "off") {
64 return std::optional{ PrimaryPairingMode::off };
65 }
66 if (str == "manual") {
67 return std::optional{ PrimaryPairingMode::manual };
68 }
69 if (str == "automatic") {
70 return std::optional{ PrimaryPairingMode::automatic };
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 off
79 if (lower_str == "off") {
80 return std::optional{ PrimaryPairingMode::off };
81 }
82 if (lower_str == "none") {
83 return std::optional{ PrimaryPairingMode::off };
84 }
85 if (lower_str == "disabled") {
86 return std::optional{ PrimaryPairingMode::off };
87 }
88 // Fuzzy names for manual
89 if (lower_str == "manual") {
90 return std::optional{ PrimaryPairingMode::manual };
91 }
92 // Fuzzy names for automatic
93 if (lower_str == "automatic") {
94 return std::optional{ PrimaryPairingMode::automatic };
95 }
96 if (lower_str == "auto") {
97 return std::optional{ PrimaryPairingMode::automatic };
98 }
99
100 return std::nullopt;
101}
102
113[[nodiscard]] inline std::string to_string(const PrimaryPairingMode m)
114{
115 switch (m) {
117 return "off";
119 return "manual";
121 return "automatic";
122 }
123 panic("unhandled PrimaryPairingMode value");
124}
125
133inline std::ostream &operator<<(std::ostream &os, const PrimaryPairingMode m)
134{
135 return os << to_string(m);
136}
137
138} // namespace porytiles
139
140template <>
141struct std::formatter<porytiles::PrimaryPairingMode> {
142 constexpr auto parse(std::format_parse_context &ctx)
143 {
144 return ctx.begin();
145 }
146
147 auto format(const porytiles::PrimaryPairingMode &value, auto &ctx) const
148 {
149 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
150 }
151};
PrimaryPairingMode
Controls how a secondary tileset finds its partner primary for compilation.
@ automatic
Scan layout metadata to find the partner primary automatically.
@ off
Skip primary loading entirely. Compile as a standalone secondary.
@ 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< PrimaryPairingMode > primary_pairing_mode_from_str(const std::string &str)
Parses a string into a PrimaryPairingMode with fuzzy matching.
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
auto format(const porytiles::PrimaryPairingMode &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)