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/*
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
31enum class ArtifactEditMode {
35 locked,
39 patch,
44};
45
61[[nodiscard]] inline std::optional<ArtifactEditMode> artifact_edit_mode_from_str(const std::string &str)
62{
63 // Phase 1: Exact match against C++ constant names
64 if (str == "locked") {
65 return std::optional{ ArtifactEditMode::locked };
66 }
67 if (str == "patch") {
68 return std::optional{ ArtifactEditMode::patch };
69 }
70 if (str == "optimize") {
71 return std::optional{ ArtifactEditMode::optimize };
72 }
73
74 // Phase 2: Case-insensitive fuzzy match
75 std::string lower_str = str;
76 std::ranges::transform(
77 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
78
79 // Fuzzy names for locked
80 if (lower_str == "locked") {
81 return std::optional{ ArtifactEditMode::locked };
82 }
83 // Fuzzy names for patch
84 if (lower_str == "patch") {
85 return std::optional{ ArtifactEditMode::patch };
86 }
87 // Fuzzy names for optimize
88 if (lower_str == "optimize") {
89 return std::optional{ ArtifactEditMode::optimize };
90 }
91
92 return std::nullopt;
93}
94
105[[nodiscard]] inline std::string to_string(const ArtifactEditMode m)
106{
107 switch (m) {
109 return "locked";
111 return "patch";
113 return "optimize";
114 }
115 panic("unhandled ArtifactEditMode value");
116}
117
125inline std::ostream &operator<<(std::ostream &os, const ArtifactEditMode m)
126{
127 return os << to_string(m);
128}
129
130} // namespace porytiles
131
132template <>
133struct std::formatter<porytiles::ArtifactEditMode> {
134 constexpr auto parse(std::format_parse_context &ctx)
135 {
136 return ctx.begin();
137 }
138
139 auto format(const porytiles::ArtifactEditMode &value, auto &ctx) const
140 {
141 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
142 }
143};
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)