Porytiles
Loading...
Searching...
No Matches
tiles_pal_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
27enum class TilesPalMode {
36};
37
53[[nodiscard]] inline std::optional<TilesPalMode> tiles_pal_mode_from_str(const std::string &str)
54{
55 // Phase 1: Exact match against C++ constant names
56 if (str == "true_color") {
57 return std::optional{ TilesPalMode::true_color };
58 }
59 if (str == "greyscale") {
60 return std::optional{ TilesPalMode::greyscale };
61 }
62
63 // Phase 2: Case-insensitive fuzzy match
64 std::string lower_str = str;
65 std::ranges::transform(
66 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
67
68 // Fuzzy names for true_color
69 if (lower_str == "true-color") {
70 return std::optional{ TilesPalMode::true_color };
71 }
72 if (lower_str == "true_color") {
73 return std::optional{ TilesPalMode::true_color };
74 }
75 if (lower_str == "truecolor") {
76 return std::optional{ TilesPalMode::true_color };
77 }
78 if (lower_str == "color") {
79 return std::optional{ TilesPalMode::true_color };
80 }
81 // Fuzzy names for greyscale
82 if (lower_str == "greyscale") {
83 return std::optional{ TilesPalMode::greyscale };
84 }
85 if (lower_str == "grayscale") {
86 return std::optional{ TilesPalMode::greyscale };
87 }
88 if (lower_str == "grey") {
89 return std::optional{ TilesPalMode::greyscale };
90 }
91 if (lower_str == "gray") {
92 return std::optional{ TilesPalMode::greyscale };
93 }
94
95 return std::nullopt;
96}
97
108[[nodiscard]] inline std::string to_string(const TilesPalMode m)
109{
110 switch (m) {
112 return "true_color";
114 return "greyscale";
115 }
116 panic("unhandled TilesPalMode value");
117}
118
126inline std::ostream &operator<<(std::ostream &os, const TilesPalMode m)
127{
128 return os << to_string(m);
129}
130
131} // namespace porytiles
132
133template <>
134struct std::formatter<porytiles::TilesPalMode> {
135 constexpr auto parse(std::format_parse_context &ctx)
136 {
137 return ctx.begin();
138 }
139
140 auto format(const porytiles::TilesPalMode &value, auto &ctx) const
141 {
142 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
143 }
144};
std::optional< TilesPalMode > tiles_pal_mode_from_str(const std::string &str)
Parses a string into a TilesPalMode with fuzzy matching.
TilesPalMode
Controls how tiles.png is rendered.
@ greyscale
Render tiles in greyscale (useful for debugging).
@ true_color
Render tiles with true colors from the palette.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
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.
constexpr auto parse(std::format_parse_context &ctx)
auto format(const porytiles::TilesPalMode &value, auto &ctx) const