isTurtle check

This commit is contained in:
Djeeberjr 2023-07-31 16:40:11 +02:00
parent 016063e3be
commit 98b8465436
2 changed files with 15 additions and 7 deletions

View File

@ -7,30 +7,38 @@ using tink.CoreApi;
class Turtle extends CLIAppBase {
public function new() {
registerSyncSubcommand("forward", (args) -> {
return perform(kernel.turtle.Turtle.instance.forward());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.forward());
});
registerSyncSubcommand("back", (args) -> {
return perform(kernel.turtle.Turtle.instance.back());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.back());
});
registerSyncSubcommand("left", (args) -> {
return perform(kernel.turtle.Turtle.instance.turnLeft());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.turnLeft());
});
registerSyncSubcommand("right", (args) -> {
return perform(kernel.turtle.Turtle.instance.turnRight());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.turnRight());
});
registerSyncSubcommand("up", (args) -> {
return perform(kernel.turtle.Turtle.instance.up());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.up());
});
registerSyncSubcommand("down", (args) -> {
return perform(kernel.turtle.Turtle.instance.down());
return checkAvailable() && perform(kernel.turtle.Turtle.instance.down());
});
}
private function checkAvailable(): Bool {
if (!kernel.turtle.Turtle.isTurtle()){
handle.write("No turtle attached");
return false;
}
return true;
}
private function perform(outcome:Outcome<Noise, String>):Bool {
switch outcome {
case Success(_):

View File

@ -18,7 +18,7 @@ class Turtle {
}
public static function isTurtle():Bool {
return true; // TODO: Implement
return cc.Turtle != null;
}
private function conterToOutcome(r:cc.Turtle.TurtleActionResult):Outcome<Noise, String> {