From c2ebe4c174a49785b9c4b6ae799e54e1dadac3b2 Mon Sep 17 00:00:00 2001 From: NadavY Date: Sun, 21 Jan 2024 22:30:40 +0200 Subject: [PATCH] WPR-7 - Improve help and route show --- README.md | 2 +- .../wpreplace/commands/RouteCommand.java | 30 ++++++------------- .../faulty/wpreplace/utils/RouteUtils.java | 20 +++++++++++++ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d032ff4..42e997f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Before running the script, ensure that you have the following: To run the script, use the following command: ```bash -java -jar waypoint-replace-0.0.8.jar +java -jar waypoint-replace-0.0.9.jar ``` Note!
* Replace 0.0.8 with the actual version downloaded diff --git a/src/main/java/org/faulty/wpreplace/commands/RouteCommand.java b/src/main/java/org/faulty/wpreplace/commands/RouteCommand.java index cd9e847..f856c50 100644 --- a/src/main/java/org/faulty/wpreplace/commands/RouteCommand.java +++ b/src/main/java/org/faulty/wpreplace/commands/RouteCommand.java @@ -1,13 +1,11 @@ package org.faulty.wpreplace.commands; -import java.util.ArrayList; import java.util.List; import org.faulty.wpreplace.context.MissionMizService; import org.faulty.wpreplace.context.RouteContext; import org.faulty.wpreplace.utils.LuaWriter; import org.faulty.wpreplace.utils.RouteUtils; -import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +23,7 @@ public class RouteCommand extends BaseCommand { private RouteContext routeContext; @ShellMethodAvailability("isMissionLoaded") - @ShellMethod(key = "route get", value = "Single selector", group = "Route") + @ShellMethod(key = "route get", value = "Select a source route", group = "Route") public String routeGet() { String coalition = getCoalition(); int countryId = getIntInput("country id:", "1"); @@ -41,27 +39,15 @@ public String routeGet() { } @ShellMethodAvailability("isMissionAndRouteLoaded") - @ShellMethod(key = "route show", value = "Multi selector", group = "Route") + @ShellMethod(key = "route show", value = "Show source route coordinates", group = "Route") public String showRoute() { LuaTable route = routeContext.getRoute().get("points").checktable(); - return "Showing results for " + routeContext.printDetails() + "\n" - + LuaWriter.luaTableToString(compactPoints(route)); - } - - public LuaTable compactPoints(LuaTable points) { - List newPoints = new ArrayList<>(); - for (LuaValue key : points.keys()) { - LuaString point = LuaString.valueOf(String.format("x=%s, y=%s, alt=%s", - points.get(key).get("x"), - points.get(key).get("y"), - points.get(key).get("alt"))); - newPoints.add(point); - } - return LuaValue.listOf(newPoints.toArray(new LuaValue[] {})); + return String.format("Showing %d points for %s\n%s", route.length(), routeContext.printDetails(), + LuaWriter.luaTableToString(RouteUtils.compactPoints(route))); } @ShellMethodAvailability("isMissionAndRouteLoaded") - @ShellMethod(key = "route copy", value = "Multi selector", group = "Route") + @ShellMethod(key = "route copy", value = "Copy source route to choosen destinations", group = "Route") public String routeCopy() { String coalition = getCoalition(); int countryId = Integer.parseInt(getStringInput("country id:", "1")); @@ -69,8 +55,10 @@ public String routeCopy() { if (unitTypes.isEmpty()) { return "No units selected"; } - unitTypes.forEach(unitType -> RouteUtils.setRoute(missionContext.getMission(), routeContext.getRoute(), coalition, countryId, unitType)); - return String.format("Route set for coalition %s, country %d, units '%s'", coalition, countryId, String.join(",", unitTypes)); + unitTypes.forEach(unitType -> RouteUtils.setRoute(missionContext.getMission(), routeContext.getRoute(), + coalition, countryId, unitType)); + return String.format("Route set for coalition %s, country %d, units '%s'", coalition, countryId, + String.join(",", unitTypes)); } private Availability isMissionLoaded() { diff --git a/src/main/java/org/faulty/wpreplace/utils/RouteUtils.java b/src/main/java/org/faulty/wpreplace/utils/RouteUtils.java index bbd90fc..6ad1dfd 100644 --- a/src/main/java/org/faulty/wpreplace/utils/RouteUtils.java +++ b/src/main/java/org/faulty/wpreplace/utils/RouteUtils.java @@ -1,5 +1,9 @@ package org.faulty.wpreplace.utils; +import java.util.ArrayList; +import java.util.List; + +import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; @@ -30,4 +34,20 @@ public static void setRoute(LuaValue mission, LuaValue route, String coalition, } } } + + /** + * Compact a route points to x,y,alt only + */ + public static LuaTable compactPoints(LuaTable points) { + List newPoints = new ArrayList<>(); + for (LuaValue key : points.keys()) { + LuaString point = LuaString.valueOf(String.format("x=%s, y=%s, alt=%s", + points.get(key).get("x"), + points.get(key).get("y"), + points.get(key).get("alt"))); + newPoints.add(point); + } + return LuaValue.listOf(newPoints.toArray(new LuaValue[] {})); + } + }