Porytiles
Loading...
Searching...
No Matches
shape_tile.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <map>
5#include <ranges>
6
8
9namespace porytiles2 {
10
43template <typename PixelType>
44class ShapeTile {
45 public:
46 virtual ~ShapeTile() = default;
47
48 ShapeTile() = default;
49
50 auto operator<=>(const ShapeTile &other) const = default;
51
70 [[nodiscard]] static bool compare_shape_only(const ShapeTile &lhs, const ShapeTile &rhs)
71 {
72 auto keys1 = lhs.colors_ | std::views::keys;
73 auto keys2 = rhs.colors_ | std::views::keys;
74 return std::ranges::lexicographical_compare(keys1, keys2);
75 }
76
86 [[nodiscard]] bool is_transparent() const
87 {
88 auto keys = colors_ | std::views::keys;
89 return std::ranges::all_of(keys, &ShapeMask::is_transparent);
90 }
91
110 [[nodiscard]] ShapeTile flip(bool h, bool v) const
111 {
112 if (!h && !v) {
113 return *this;
114 }
115
116 ShapeTile result;
117 for (const auto &[mask, color] : colors_) {
118 result.colors_.insert_or_assign(mask.flip(h, v), color);
119 }
120 return result;
121 }
122
132 [[nodiscard]] const std::map<ShapeMask, PixelType> &colors() const
133 {
134 return colors_;
135 }
136
147 void set(const ShapeMask &mask, const PixelType &color)
148 {
149 colors_.insert_or_assign(mask, color);
150 }
151
152 private:
153 std::map<ShapeMask, PixelType> colors_;
154};
155
156} // namespace porytiles2
Represents which pixels in an 8x8 tile are non-transparent.
bool is_transparent() const
Checks if this entire ShapeMask is transparent.
An 8x8 tile backed by mask-based storage that maps shape regions to pixel values.
const std::map< ShapeMask, PixelType > & colors() const
Returns the internal map of shape masks to pixel values.
ShapeTile flip(bool h, bool v) const
Creates a flipped version of this ShapeTile.
static bool compare_shape_only(const ShapeTile &lhs, const ShapeTile &rhs)
Compares two ShapeTiles based ONLY on shape masks, ignoring pixel values.
auto operator<=>(const ShapeTile &other) const =default
bool is_transparent() const
Checks if this entire ShapeTile is transparent.
virtual ~ShapeTile()=default
void set(const ShapeMask &mask, const PixelType &color)
Sets or updates the pixel value for a specific shape mask.