aboutsummaryrefslogtreecommitdiff
path: root/Canvas.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-10 00:39:24 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-10 00:39:24 +0200
commit3d62a3cf54465a521c6c30ae21c80a2e18871478 (patch)
treeff1fb4d4b521746289f0d05d50f5c98ff49ef801 /Canvas.cpp
parent2fb206efb3dc62508306ca293e808648efbba9f7 (diff)
print Canvas
Diffstat (limited to 'Canvas.cpp')
-rw-r--r--Canvas.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/Canvas.cpp b/Canvas.cpp
index 46d2f03..0a252b4 100644
--- a/Canvas.cpp
+++ b/Canvas.cpp
@@ -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;
+}
+