added digEmpty function
This commit is contained in:
parent
73e2ccdcb8
commit
be405887e2
@ -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<Noise, String> {
|
||||
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<Noise, String> {
|
||||
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<Noise, String> {
|
||||
var r:cc.Turtle.TurtleActionResult;
|
||||
switch dir {
|
||||
|
Loading…
Reference in New Issue
Block a user