From 74d17b76ef8459c7d031111aeff1b7ac6af93ac1 Mon Sep 17 00:00:00 2001 From: dtookey Date: Sun, 6 Aug 2023 21:40:10 -0400 Subject: [PATCH] usage examples for HelperFunctions.kt --- src/main/kotlin/Entry.kt | 3 ++- src/main/kotlin/HelperFunctions.kt | 43 +++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/Entry.kt b/src/main/kotlin/Entry.kt index 3664ece..11193ea 100644 --- a/src/main/kotlin/Entry.kt +++ b/src/main/kotlin/Entry.kt @@ -2,6 +2,7 @@ import java.awt.Point fun main() { // Routines.fullRunIncense(0, 0, 0, 257) - Routines.processInventoryAtFurnace(3566) +// Routines.processInventoryAtFurnace(3566) + println(HelperFunctions.prettyTimeString(72134)) } diff --git a/src/main/kotlin/HelperFunctions.kt b/src/main/kotlin/HelperFunctions.kt index f25b7de..b43fdc1 100644 --- a/src/main/kotlin/HelperFunctions.kt +++ b/src/main/kotlin/HelperFunctions.kt @@ -5,6 +5,17 @@ object HelperFunctions { /** * Computes the total number of steps needed to process the given total volume. * + * This takes the total volume that needs to be processed and th + * and calculates the total steps required. + * Usage examples: + * ``` + * val total = 550 + * val perStep = 200 + * val steps = calculateTotalSteps(total, perStep) // 3 steps + * + * val steps = calculateTotalSteps(1000, 100) // 10 steps + * ``` + * * @param totalVolume the total amount that needs to be processed * @param volumePerStep the amount to process per step * @return the number of steps required to process the total volume @@ -20,6 +31,21 @@ object HelperFunctions { /** * Prints a progress report to console showing current step, total steps, elapsed time, and estimated remaining time. * + * This takes the current step number, total steps, and elapsed duration and prints a progress report. + * Typical usage is to call this within a loop, passing the loop index for current step and total loop count. + * + * + * Usage example: + * ``` + * val totalSteps = 100 + * val start = System.currentTimeMillis() + * for (i in 1..totalSteps) { + * // Do work + * + * report(i, totalSteps, System.currentTimeMillis() - start) + * } + * ``` + * * @param step The current step number * @param of The total number of steps * @param dur The elapsed duration so far in milliseconds @@ -32,6 +58,16 @@ object HelperFunctions { /** * Converts a duration in milliseconds to a human-readable string. * + * This takes a duration in ms and converts it to a formatted string like "2h13m4s". + * + * Usage example: + * + * ``` + * val duration = 72134 // ms + * val timeStr = prettyTimeString(duration) + * // "1m12s" + * ``` + * * @param durationMillis The duration to convert, in milliseconds * @return A string representation of the duration, in the format XhYmZs */ @@ -61,9 +97,10 @@ object HelperFunctions { * It then formats this location into a string declaring a val with the provided * variable name, like: * - * ``` - * val myPoint = Point(123, 456) - * ``` + * ``` + * val location = getPointerLocationAsValDeclarationString("clickPoint") + * // val clickPoint = Point(123, 456) + * ``` * * The delay before getting the pointer location helps ensure the mouse has * settled after any prior movements.