diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-10 00:39:24 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-10 00:39:24 +0200 |
commit | 3d62a3cf54465a521c6c30ae21c80a2e18871478 (patch) | |
tree | ff1fb4d4b521746289f0d05d50f5c98ff49ef801 /Canvas.cpp | |
parent | 2fb206efb3dc62508306ca293e808648efbba9f7 (diff) |
print Canvas
Diffstat (limited to 'Canvas.cpp')
-rw-r--r-- | Canvas.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1,6 +1,10 @@ #include <cstdio> +#include <string> #include "Canvas.h" +#include "util.h" + +using namespace std; Tile & Canvas::get_tile(unsigned x, unsigned y) { return *this->tiles[this->pos_to_index(x, y)]; @@ -35,3 +39,25 @@ Canvas::~Canvas() { } } +string Canvas::to_string(bool truecolor) { + string out = ""; + + for (size_t y = 0; y < this->data.rows; y++) { + for (size_t x = 0; x < this->data.columns; x++) { + Tile & tile = this->get_tile(x, y); + string type_str = tile.data.type; + if (type_str.length() == 0) type_str = "."; + + if (truecolor) + out += stringf("\e[48;2;%d;%d;%dm", tile.appearance.color.red, + tile.appearance.color.green, tile.appearance.color.blue); + + out += stringf("%-2s ", type_str.c_str()); + } + if (truecolor) out += "\e[0m"; + out += "\n"; + } + + return out; +} + |