From ca79714e8df9ecebdf68d4bd02f04fb7d9cf6fe5 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Wed, 15 Nov 2023 20:35:23 +0100 Subject: [PATCH] added textRepresentation to Layer --- src/lib/turtle/Structure.hx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib/turtle/Structure.hx b/src/lib/turtle/Structure.hx index c5e9a9e..d0d8c8f 100644 --- a/src/lib/turtle/Structure.hx +++ b/src/lib/turtle/Structure.hx @@ -1,5 +1,7 @@ package lib.turtle; +typedef Block = Bool; + abstract Structure(Array) from Array { public inline function getLayer(i:Int):Layer { return this[i]; @@ -10,8 +12,8 @@ abstract Structure(Array) from Array { } } -abstract Layer(Array>) from Array> { - public inline function get(x:Int, y:Int):Bool { +abstract Layer(Array>) from Array> { + public inline function get(x:Int, y:Int):Block { return this[y][x]; } @@ -22,4 +24,19 @@ abstract Layer(Array>) from Array> { public inline function height():Int { return this.length; } + + public function getTextRepresentation():String { + var str = ""; + for (y in 0...height()) { + for (x in 0...width()) { + if (get(x, y)) { + str += "X"; + } else { + str += " "; + } + } + str += "\n"; + } + return str; + } }