Porytiles
Loading...
Searching...
No Matches
artifact_edit_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
27enum class ArtifactEditMode {
29 locked,
31 patch,
34};
35
49[[nodiscard]] inline std::optional<ArtifactEditMode> artifact_edit_mode_from_str(const std::string &str)
50{
51 // Phase 1: Exact match against C++ constant names
52 if (str == "locked") {
53 return std::optional{ArtifactEditMode::locked};
54 }
55 if (str == "patch") {
56 return std::optional{ArtifactEditMode::patch};
57 }
58 if (str == "optimize") {
59 return std::optional{ArtifactEditMode::optimize};
60 }
61
62 // Phase 2: Case-insensitive fuzzy match
63 std::string lower_str = str;
64 std::ranges::transform(
65 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
66
67 // Fuzzy names for locked
68 if (lower_str == "locked") {
69 return std::optional{ArtifactEditMode::locked};
70 }
71 // Fuzzy names for patch
72 if (lower_str == "patch") {
73 return std::optional{ArtifactEditMode::patch};
74 }
75 // Fuzzy names for optimize
76 if (lower_str == "optimize") {
77 return std::optional{ArtifactEditMode::optimize};
78 }
79
80 return std::nullopt;
81}
82
91[[nodiscard]] inline std::string to_string(const ArtifactEditMode m)
92{
93 switch (m) {
95 return "locked";
97 return "patch";
99 return "optimize";
100 }
101 panic("unhandled ArtifactEditMode value");
102}
103
109inline std::ostream &operator<<(std::ostream &os, const ArtifactEditMode m)
110{
111 return os << to_string(m);
112}
113
114} // namespace porytiles
115
116template <>
117struct std::formatter<porytiles::ArtifactEditMode> {
118 constexpr auto parse(std::format_parse_context &ctx)
119 {
120 return ctx.begin();
121 }
122
123 auto format(const porytiles::ArtifactEditMode &value, auto &ctx) const
124 {
125 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
126 }
127};
std::optional< ArtifactEditMode > artifact_edit_mode_from_str(const std::string &str)
Parses a string into a ArtifactEditMode with fuzzy matching.
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.
ArtifactEditMode
Specifies whether artifacts (tiles or palettes) can be modified during patch compilation.
@ locked
Artifacts cannot be edited; must use existing from base tileset.
@ optimize
The Porytiles1 behavior; artifact is cleared and packed optimally.
@ patch
Artifacts can be freely edited in "open" slots during compilation.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
auto format(const porytiles::ArtifactEditMode &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)