Porytiles
Loading...
Searching...
No Matches
palette_hint.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <format>
5#include <ostream>
6#include <string>
7#include <vector>
8
12
13namespace porytiles {
14
23 public:
30 PaletteHint(std::string name, Palette<Rgba32> pal) : name_{std::move(name)}, pal_{std::move(pal)} {}
31
32 [[nodiscard]] const std::string &name() const
33 {
34 return name_;
35 }
36
37 [[nodiscard]] const Palette<Rgba32> &pal() const
38 {
39 return pal_;
40 }
41
42 private:
43 std::string name_;
44 Palette<Rgba32> pal_;
45};
46
56inline std::string to_string(const PaletteHint &hint)
57{
58 return hint.name();
59}
60
71inline std::ostream &operator<<(std::ostream &os, const PaletteHint &hint)
72{
73 return os << to_string(hint);
74}
75
76} // namespace porytiles
77
78template <>
79struct std::formatter<porytiles::PaletteHint> {
80 constexpr auto parse(std::format_parse_context &ctx)
81 {
82 return ctx.begin();
83 }
84
85 auto format(const porytiles::PaletteHint &value, auto &ctx) const
86 {
87 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
88 }
89};
90
91template <>
92struct std::formatter<std::vector<porytiles::PaletteHint>> {
93 constexpr auto parse(std::format_parse_context &ctx)
94 {
95 return ctx.begin();
96 }
97
98 auto format(const std::vector<porytiles::PaletteHint> &value, auto &ctx) const
99 {
100 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
101 }
102};
Represents a palette hint for the palette packing algorithm.
const std::string & name() const
PaletteHint(std::string name, Palette< Rgba32 > pal)
Constructs a PaletteHint with a name and palette.
const Palette< Rgba32 > & pal() const
A generic palette container for colors that support transparency checking.
Definition palette.hpp:47
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.
Utility functions for string manipulation and formatting.
constexpr auto parse(std::format_parse_context &ctx)
auto format(const porytiles::PaletteHint &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)
auto format(const std::vector< porytiles::PaletteHint > &value, auto &ctx) const