aboutsummaryrefslogtreecommitdiff
path: root/Canvas.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-15 14:42:40 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-15 14:42:40 +0200
commit6319b7c8bf1689c990f8849c76e1871bcea9584d (patch)
treeeacc4f3284897bd93468627a6f00981128e16755 /Canvas.cpp
parentee2aedc27eeb8c0c50bf662dfa3a2dcdcdb3ff91 (diff)
use C++-style structs and move tile XY to tile.data
Diffstat (limited to 'Canvas.cpp')
-rw-r--r--Canvas.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Canvas.cpp b/Canvas.cpp
index 94ffe14..423670d 100644
--- a/Canvas.cpp
+++ b/Canvas.cpp
@@ -13,13 +13,11 @@ Tile & Canvas::get_tile(unsigned x, unsigned y) {
return *this->tiles[this->pos_to_index(x, y)];
}
-void Canvas::set_tile(unsigned x, unsigned y, TileData data) {
- size_t index = this->pos_to_index(x, y);
+void Canvas::set_tile(TileData data) {
+ size_t index = this->pos_to_index(data.x, data.y);
if (this->tiles[index] != nullptr)
delete this->tiles[index];
this->tiles[index] = new Tile(this->museum, data);
- this->tiles[index]->x = x;
- this->tiles[index]->y = y;
}
size_t Canvas::pos_to_index(unsigned x, unsigned y) {
@@ -39,7 +37,10 @@ void Canvas::set_data(CanvasData data) {
for (size_t x = 0; x < this->data.columns; x++) {
if (this->tiles[this->pos_to_index(x, y)] != nullptr)
continue;
- this->set_tile(x, y, {});
+ this->set_tile({
+ .x = static_cast<unsigned int>(x),
+ .y = static_cast<unsigned int>(y),
+ });
}
}
}