Skip to content

Commit 03e7e72

Browse files
committed
Improvement: Show waypoint count and format name when loading ordered waypoints
1 parent 136c9e4 commit 03e7e72

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/main/java/at/hannibal2/skyhanni/features/mining/OrderedWaypoints.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,24 @@ object OrderedWaypoints {
240240
}
241241

242242
private fun setupLoadJob(name: String): Job = SkyHanniMod.launchIOCoroutine("ordered waypoints setupLoadJob") {
243-
val loadedRoute = if (name == "") loadWaypoints(ClipboardUtils.readFromClipboard().orEmpty())
244-
else storage?.routes?.get(name) ?: return@launchIOCoroutine ChatUtils.userError(
243+
val result = if (name == "") loadWaypoints(ClipboardUtils.readFromClipboard().orEmpty())
244+
else storage?.routes?.get(name)?.let { it to "saved" } ?: return@launchIOCoroutine ChatUtils.userError(
245245
"Route $name doesn't exist.\n" +
246246
"§cSaved Routes: ${storage?.routes?.keys?.toList()?.joinToString(", ")}\n" +
247247
"§cIf you would like to import a route from your clipboard, leave the route name blank.",
248248
)
249249

250-
if (loadedRoute == null) return@launchIOCoroutine ChatUtils.userError(
250+
if (result == null) return@launchIOCoroutine ChatUtils.userError(
251251
"There was an error parsing waypoints. " +
252252
"Please make sure they are properly formatted and in a supported format.\n" +
253253
"§cSupported Formats: ${getWaypointFormats().joinToString(", ")}",
254254
)
255255

256+
val (loadedRoute, formatName) = result
256257
orderedWaypointsList = loadedRoute.deepCopy()
257258
currentOrderedWaypointIndex = orderedWaypointsList.minBy { waypoint -> waypoint.location.distanceSqToPlayer() }.number - 1
258259
renderWaypoints.clear()
259-
ChatUtils.chat("Loaded ordered waypoints!")
260+
ChatUtils.chat("Loaded ${orderedWaypointsList.size} ordered waypoints! (§e$formatName§r)")
260261

261262
if (!config.enabled) {
262263
config.enabled = true
@@ -446,11 +447,9 @@ object OrderedWaypoints {
446447
currentOrderedWaypointIndex = Math.floorMod(currentOrderedWaypointIndex + increment, orderedWaypointsList.size)
447448
}
448449

449-
private fun loadWaypoints(data: String): Waypoints<SkyHanniWaypoint>? {
450-
return ServiceLoader.load(WaypointFormat::class.java).firstNotNullOfOrNull {
451-
it.load(data)
452-
}?.let {
453-
Waypoints(it.toMutableList())
450+
private fun loadWaypoints(data: String): Pair<Waypoints<SkyHanniWaypoint>, String>? {
451+
return ServiceLoader.load(WaypointFormat::class.java).firstNotNullOfOrNull { format ->
452+
format.load(data)?.let { it to format.name }
454453
}
455454
}
456455

0 commit comments

Comments
 (0)