From 6319b7c8bf1689c990f8849c76e1871bcea9584d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 15 Oct 2024 14:42:40 +0200 Subject: use C++-style structs and move tile XY to tile.data --- Canvas.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Canvas.cpp') 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(x), + .y = static_cast(y), + }); } } } -- cgit v1.2.3