Porytiles
Loading...
Searching...
No Matches
tiles_palette_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// 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
23enum class TilesPaletteMode {
28};
29
43[[nodiscard]] inline std::optional<TilesPaletteMode> tiles_palette_mode_from_str(const std::string &str)
44{
45 // Phase 1: Exact match against C++ constant names
46 if (str == "true_color") {
47 return std::optional{TilesPaletteMode::true_color};
48 }
49 if (str == "greyscale") {
50 return std::optional{TilesPaletteMode::greyscale};
51 }
52
53 // Phase 2: Case-insensitive fuzzy match
54 std::string lower_str = str;
55 std::ranges::transform(
56 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
57
58 // Fuzzy names for true_color
59 if (lower_str == "true-color") {
60 return std::optional{TilesPaletteMode::true_color};
61 }
62 if (lower_str == "true_color") {
63 return std::optional{TilesPaletteMode::true_color};
64 }
65 if (lower_str == "truecolor") {
66 return std::optional{TilesPaletteMode::true_color};
67 }
68 if (lower_str == "color") {
69 return std::optional{TilesPaletteMode::true_color};
70 }
71 // Fuzzy names for greyscale
72 if (lower_str == "greyscale") {
73 return std::optional{TilesPaletteMode::greyscale};
74 }
75 if (lower_str == "grayscale") {
76 return std::optional{TilesPaletteMode::greyscale};
77 }
78 if (lower_str == "grey") {
79 return std::optional{TilesPaletteMode::greyscale};
80 }
81 if (lower_str == "gray") {
82 return std::optional{TilesPaletteMode::greyscale};
83 }
84
85 return std::nullopt;
86}
87
96[[nodiscard]] inline std::string to_string(const TilesPaletteMode m)
97{
98 switch (m) {
100 return "true_color";
102 return "greyscale";
103 }
104 panic("unhandled TilesPaletteMode value");
105}
106
112inline std::ostream &operator<<(std::ostream &os, const TilesPaletteMode m)
113{
114 return os << to_string(m);
115}
116
117} // namespace porytiles
118
119template <>
120struct std::formatter<porytiles::TilesPaletteMode> {
121 constexpr auto parse(std::format_parse_context &ctx)
122 {
123 return ctx.begin();
124 }
125
126 auto format(const porytiles::TilesPaletteMode &value, auto &ctx) const
127 {
128 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
129 }
130};
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.
TilesPaletteMode
Controls how tiles.png is rendered.
@ greyscale
Render tiles in greyscale (useful for debugging).
@ true_color
Render tiles with true colors from the palette.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
std::optional< TilesPaletteMode > tiles_palette_mode_from_str(const std::string &str)
Parses a string into a TilesPaletteMode with fuzzy matching.
constexpr auto parse(std::format_parse_context &ctx)
auto format(const porytiles::TilesPaletteMode &value, auto &ctx) const