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
21 public:
26 PaletteHint(std::string name, Palette<Rgba32> palette) : name_{std::move(name)}, palette_{std::move(palette)} {}
27
28 [[nodiscard]] const std::string &name() const
29 {
30 return name_;
31 }
32
33 [[nodiscard]] const Palette<Rgba32> &palette() const
34 {
35 return palette_;
36 }
37
38 private:
39 std::string name_;
40 Palette<Rgba32> palette_;
41};
42
50inline std::string to_string(const PaletteHint &hint)
51{
52 return hint.name();
53}
54
63inline std::ostream &operator<<(std::ostream &os, const PaletteHint &hint)
64{
65 return os << to_string(hint);
66}
67
68} // namespace porytiles
69
70template <>
71struct std::formatter<porytiles::PaletteHint> {
72 constexpr auto parse(std::format_parse_context &ctx)
73 {
74 return ctx.begin();
75 }
76
77 auto format(const porytiles::PaletteHint &value, auto &ctx) const
78 {
79 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
80 }
81};
82
83template <>
84struct std::formatter<std::vector<porytiles::PaletteHint>> {
85 constexpr auto parse(std::format_parse_context &ctx)
86 {
87 return ctx.begin();
88 }
89
90 auto format(const std::vector<porytiles::PaletteHint> &value, auto &ctx) const
91 {
92 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
93 }
94};
Represents a palette hint for the palette packing algorithm.
PaletteHint(std::string name, Palette< Rgba32 > palette)
Constructs a PaletteHint with a name and palette.
const std::string & name() const
const Palette< Rgba32 > & palette() const
A generic palette container for colors that support transparency checking.
Definition palette.hpp:45
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