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 porytiles {
10
41template <typename PixelType>
42class ShapeTile {
43 public:
44 virtual ~ShapeTile() = default;
45
46 ShapeTile() = default;
47
48 auto operator<=>(const ShapeTile &other) const = default;
49
66 [[nodiscard]] static bool compare_shape_only(const ShapeTile &lhs, const ShapeTile &rhs)
67 {
68 auto keys1 = lhs.colors_ | std::views::keys;
69 auto keys2 = rhs.colors_ | std::views::keys;
70 return std::ranges::lexicographical_compare(keys1, keys2);
71 }
72
80 [[nodiscard]] bool is_transparent() const
81 {
82 auto keys = colors_ | std::views::keys;
83 return std::ranges::all_of(keys, &ShapeMask::is_transparent);
84 }
85
102 [[nodiscard]] ShapeTile flip(bool h, bool v) const
103 {
104 if (!h && !v) {
105 return *this;
106 }
107
108 ShapeTile result;
109 for (const auto &[mask, color] : colors_) {
110 result.colors_.insert_or_assign(mask.flip(h, v), color);
111 }
112 return result;
113 }
114
122 [[nodiscard]] const std::map<ShapeMask, PixelType> &colors() const
123 {
124 return colors_;
125 }
126
135 void set(const ShapeMask &mask, const PixelType &color)
136 {
137 colors_.insert_or_assign(mask, color);
138 }
139
140 private:
141 std::map<ShapeMask, PixelType> colors_;
142};
143
144} // namespace porytiles
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.
virtual ~ShapeTile()=default
void set(const ShapeMask &mask, const PixelType &color)
Sets or updates the pixel value for a specific shape mask.
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.
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.