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 { class Turtle extends CLIAppBase {
public function new() { public function new() {
registerSyncSubcommand("forward", (args) -> { registerSyncSubcommand("forward", (args) -> {
return perform(kernel.turtle.Turtle.instance.forward()); return checkAvailable() && perform(kernel.turtle.Turtle.instance.forward());
}); });
registerSyncSubcommand("back", (args) -> { registerSyncSubcommand("back", (args) -> {
return perform(kernel.turtle.Turtle.instance.back()); return checkAvailable() && perform(kernel.turtle.Turtle.instance.back());
}); });
registerSyncSubcommand("left", (args) -> { registerSyncSubcommand("left", (args) -> {
return perform(kernel.turtle.Turtle.instance.turnLeft()); return checkAvailable() && perform(kernel.turtle.Turtle.instance.turnLeft());
}); });
registerSyncSubcommand("right", (args) -> { registerSyncSubcommand("right", (args) -> {
return perform(kernel.turtle.Turtle.instance.turnRight()); return checkAvailable() && perform(kernel.turtle.Turtle.instance.turnRight());
}); });
registerSyncSubcommand("up", (args) -> { registerSyncSubcommand("up", (args) -> {
return perform(kernel.turtle.Turtle.instance.up()); return checkAvailable() && perform(kernel.turtle.Turtle.instance.up());
}); });
registerSyncSubcommand("down", (args) -> { 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 { private function perform(outcome:Outcome<Noise, String>):Bool {
switch outcome { switch outcome {
case Success(_): case Success(_):

View File

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