added textRepresentation to Layer

This commit is contained in:
Niklas Kapelle 2023-11-15 20:35:23 +01:00
parent e0d4844890
commit ca79714e8d
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -1,5 +1,7 @@
package lib.turtle; package lib.turtle;
typedef Block = Bool;
abstract Structure(Array<Layer>) from Array<Layer> { abstract Structure(Array<Layer>) from Array<Layer> {
public inline function getLayer(i:Int):Layer { public inline function getLayer(i:Int):Layer {
return this[i]; return this[i];
@ -10,8 +12,8 @@ abstract Structure(Array<Layer>) from Array<Layer> {
} }
} }
abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> { abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
public inline function get(x:Int, y:Int):Bool { public inline function get(x:Int, y:Int):Block {
return this[y][x]; return this[y][x];
} }
@ -22,4 +24,19 @@ abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> {
public inline function height():Int { public inline function height():Int {
return this.length; 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;
}
} }