Compare commits

..

2 Commits

Author SHA1 Message Date
b05dae958d tunnel command to turtle ctl 2024-08-05 16:58:46 +02:00
3e993b84eb added turtle ctl dig command 2024-08-05 15:41:03 +02:00

View File

@@ -1,5 +1,6 @@
package bin; package bin;
import lib.turtle.Helper;
import kernel.turtle.TurtleMutex; import kernel.turtle.TurtleMutex;
import kernel.turtle.Turtle; import kernel.turtle.Turtle;
import lib.turtle.InvManager; import lib.turtle.InvManager;
@@ -96,6 +97,25 @@ class TurtleCtl extends CLIAppBase {
return Success(null); return Success(null);
}, 1); }, 1);
}, [Optional(String("to"))]); }, [Optional(String("to"))]);
registerAsyncSubcommand("dig", (args) -> {
var direction = args.getString("direction");
switch (direction) {
case "front" | "f":
return asynPerform(() -> Turtle.dig(Front), 1);
case "top" | "t" | "up" | "u":
return asynPerform(() -> Turtle.dig(Up), 1);
case "bot" | "bottom" | "b" | "down" | "d":
return asynPerform(() -> Turtle.dig(Down), 1);
default:
return Future.sync(false);
}
}, [String("direction")]);
registerAsyncSubcommand("tunnel", (args) -> {
var len = args.getInt("length");
return asynPerform(Helper.combine.bind([Turtle.dig.bind(Front), Turtle.forward, Turtle.dig.bind(Up)]), len);
}, [Int("length")]);
} }
private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> { private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> {
@@ -134,18 +154,4 @@ class TurtleCtl extends CLIAppBase {
return null; return null;
}); });
} }
private function parseTimes(args:Array<String>):Int {
if (args.length > 0) {
var num = Std.parseInt(args[0]);
if (num == null) {
handle.writeLine("Failed to parse args");
return 0;
} else {
return num;
}
} else {
return 1;
}
}
} }