From a9f6adcd9d18517edd90fabafdcf261d57c437c5 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Thu, 2 May 2024 15:04:15 +0200 Subject: [PATCH] added refuel functions to TurtleCtl --- src/bin/TurtleCtl.hx | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/bin/TurtleCtl.hx b/src/bin/TurtleCtl.hx index 706be0d..cf612e9 100644 --- a/src/bin/TurtleCtl.hx +++ b/src/bin/TurtleCtl.hx @@ -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); + }, ""); } private function asynPerform(op:Void->Outcome, times:Int):Future {