added refuel functions to TurtleCtl

This commit is contained in:
Niklas Kapelle 2024-05-02 15:04:15 +02:00
parent 757d7098cf
commit a9f6adcd9d
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -48,6 +48,53 @@ class TurtleCtl extends CLIAppBase {
handle.writeLine('${lvl}/${limit} (${(lvl / limit) * 100}%)');
return true;
});
registerAsyncSubcommand("fuel-sources", (args) -> {
return asynPerform(() -> {
var items = InvManager.getCombustableItems();
for (i in items) {
handle.writeLine(i);
}
return Success(null);
}, 1);
});
registerAsyncSubcommand("refuel", (args) -> {
var refuelTo = Turtle.getFuelLimit();
if (args.length > 0) {
var split = args[0].split("%");
if (split.length > 1) {
// Is percentage
var parsed = Std.parseFloat(split[0]);
if (parsed == null) {
handle.writeLine("Failed to parse ammount");
return Future.sync(false);
}
refuelTo = Math.round(refuelTo * (parsed / 100));
} else {
// Is absolute
var parsed = Std.parseInt(args[0]);
if (parsed == null) {
handle.writeLine("Failed to parse ammount");
return Future.sync(false);
}
refuelTo = parsed;
}
}
return asynPerform(() -> {
InvManager.refuel(refuelTo, []);
return Success(null);
}, 1);
}, "<to|to%>");
}
private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> {