Porytiles
Loading...
Searching...
No Matches
tile_sharing_alignment.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 off,
30 greedy,
33};
34
48[[nodiscard]] inline std::optional<TileSharingAlignment> tile_sharing_alignment_from_str(const std::string &str)
49{
50 // Phase 1: Exact match against C++ constant names
51 if (str == "off") {
52 return std::optional{TileSharingAlignment::off};
53 }
54 if (str == "greedy") {
55 return std::optional{TileSharingAlignment::greedy};
56 }
57 if (str == "optimal") {
58 return std::optional{TileSharingAlignment::optimal};
59 }
60
61 // Phase 2: Case-insensitive fuzzy match
62 std::string lower_str = str;
63 std::ranges::transform(
64 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
65
66 // Fuzzy names for off
67 if (lower_str == "off") {
68 return std::optional{TileSharingAlignment::off};
69 }
70 // Fuzzy names for greedy
71 if (lower_str == "greedy") {
72 return std::optional{TileSharingAlignment::greedy};
73 }
74 // Fuzzy names for optimal
75 if (lower_str == "optimal") {
76 return std::optional{TileSharingAlignment::optimal};
77 }
78
79 return std::nullopt;
80}
81
90[[nodiscard]] inline std::string to_string(const TileSharingAlignment m)
91{
92 switch (m) {
94 return "off";
96 return "greedy";
98 return "optimal";
99 }
100 panic("unhandled TileSharingAlignment value");
101}
102
108inline std::ostream &operator<<(std::ostream &os, const TileSharingAlignment m)
109{
110 return os << to_string(m);
111}
112
113} // namespace porytiles
114
115template <>
116struct std::formatter<porytiles::TileSharingAlignment> {
117 constexpr auto parse(std::format_parse_context &ctx)
118 {
119 return ctx.begin();
120 }
121
122 auto format(const porytiles::TileSharingAlignment &value, auto &ctx) const
123 {
124 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
125 }
126};
@ off
Skip primary loading entirely. Compile as a standalone secondary.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
TileSharingAlignment
Controls palette slot alignment strategy for tile sharing deduplication.
@ greedy
Best-effort alignment via indirect link resolution.
@ off
Pure sequential fill with no sharing alignment (default).
@ optimal
CSP-based globally optimal alignment (not yet implemented).
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
std::optional< TileSharingAlignment > tile_sharing_alignment_from_str(const std::string &str)
Parses a string into a TileSharingAlignment with fuzzy matching.
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::TileSharingAlignment &value, auto &ctx) const