Porytiles
Loading...
Searching...
No Matches
tile_sharing_packing.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 biased,
43};
44
60[[nodiscard]] inline std::optional<TileSharingPacking> tile_sharing_packing_from_str(const std::string &str)
61{
62 // Phase 1: Exact match against C++ constant names
63 if (str == "off") {
64 return std::optional{ TileSharingPacking::off };
65 }
66 if (str == "biased") {
67 return std::optional{ TileSharingPacking::biased };
68 }
69 if (str == "optimal") {
70 return std::optional{ TileSharingPacking::optimal };
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{ TileSharingPacking::off };
81 }
82 // Fuzzy names for biased
83 if (lower_str == "biased") {
84 return std::optional{ TileSharingPacking::biased };
85 }
86 // Fuzzy names for optimal
87 if (lower_str == "optimal") {
88 return std::optional{ TileSharingPacking::optimal };
89 }
90
91 return std::nullopt;
92}
93
104[[nodiscard]] inline std::string to_string(const TileSharingPacking m)
105{
106 switch (m) {
108 return "off";
110 return "biased";
112 return "optimal";
113 }
114 panic("unhandled TileSharingPacking value");
115}
116
124inline std::ostream &operator<<(std::ostream &os, const TileSharingPacking m)
125{
126 return os << to_string(m);
127}
128
129} // namespace porytiles
130
131template <>
132struct std::formatter<porytiles::TileSharingPacking> {
133 constexpr auto parse(std::format_parse_context &ctx)
134 {
135 return ctx.begin();
136 }
137
138 auto format(const porytiles::TileSharingPacking &value, auto &ctx) const
139 {
140 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
141 }
142};
@ 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
@ optimal
CSP-based globally optimal alignment (not yet implemented).
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
TileSharingPacking
Controls whether palette packing considers tile sharing shape group membership.
@ off
Packing ignores shape group membership (default).
@ optimal
Hard constraint rejecting sibling co-placement (not yet implemented).
@ biased
Soft penalty steers shape group siblings toward different palettes.
std::optional< TileSharingPacking > tile_sharing_packing_from_str(const std::string &str)
Parses a string into a TileSharingPacking with fuzzy matching.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
auto format(const porytiles::TileSharingPacking &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)