Porytiles
Loading...
Searching...
No Matches
color_index.hpp
Go to the documentation of this file.
1#pragma once
2
3// ReSharper disable once CppUnusedIncludeDirective
4#include <compare>
5#include <cstddef>
6#include <string>
7
9
10namespace porytiles2 {
11
12inline constexpr std::size_t colors_per_pal = 16;
13inline constexpr std::size_t num_pals = 16;
14inline constexpr std::size_t num_colors = colors_per_pal * num_pals;
15
32 public:
33 // NOLINTNEXTLINE(google-explicit-constructor)
34 ColorIndex(unsigned int index) : index_{index}
35 {
36 // TODO: do we want validation here?
37 // I think not, since ideally we should allow ColorIndexMap to grow to arbitrary size.
38 // The domain compiler service can then check the size and throw based on exogenous config params.
39 // if (index_ >= num_colors) {
40 // panic("invalid ColorIndex value: " + std::to_string(index_));
41 // }
42 }
43
44 auto operator<=>(const ColorIndex &) const = default;
45
51 [[nodiscard]] unsigned int index() const
52 {
53 return index_;
54 }
55
56 private:
57 unsigned int index_{};
58};
59
60} // namespace porytiles2
Represents a color index value for palette operations.
ColorIndex(unsigned int index)
auto operator<=>(const ColorIndex &) const =default
unsigned int index() const
Returns the underlying unsigned integer index value.
constexpr std::size_t colors_per_pal
constexpr std::size_t num_colors
constexpr std::size_t num_pals