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; + } }