diff --git a/src/kernel/turtle/Turtle.hx b/src/kernel/turtle/Turtle.hx index 42e8dc8..a18a138 100644 --- a/src/kernel/turtle/Turtle.hx +++ b/src/kernel/turtle/Turtle.hx @@ -72,6 +72,11 @@ class Turtle { return r2; } + /** + Dig in the provided direction. + Keep in mind that digging on a empty space is considerd a failure. + Also see `digEmpty`. + **/ public static function dig(dir:InteractDirections, ?toolSide:ToolSide):Outcome { var r:cc.Turtle.TurtleActionResult; @@ -87,6 +92,36 @@ class Turtle { return conterToOutcome(r); } + /** + Dig in the provided direction. + Does not fail if there is nothing to dig. + Also see `dig`. + **/ + public static function digEmpty(dir:InteractDirections, ?toolSide:ToolSide):Outcome { + var r:cc.Turtle.TurtleActionResult; + + // FIXME: upstream needs to be fixed to accept ToolSide + switch dir { + case Front: + r = cc.Turtle.dig(); + case Up: + r = cc.Turtle.digUp(); + case Down: + r = cc.Turtle.digDown(); + } + var result = conterToOutcome(r); + + switch (result) { + case Success(_): + return result; + case Failure(failure): + if (failure == "Nothing to dig here") { + return Success(null); + } + return result; + } + } + public static function place(dir:InteractDirections):Outcome { var r:cc.Turtle.TurtleActionResult; switch dir {