Orchestrator.kt has usage examples on everything

This commit is contained in:
dtookey 2023-08-06 21:32:23 -04:00
parent a9b18e4e13
commit f0fd48094e
2 changed files with 66 additions and 10 deletions

View File

@ -17,8 +17,14 @@ interface Orchestrator {
/** /**
* Scrolls out to the specified height by repeating scroll in/out operations. * Scrolls out to the specified height by repeating scroll in/out operations.
* *
* This handles scrolling out by the given height through a series of repeated scroll in and * This handles scrolling out by the given height through a series of repeated
* scroll out operations using the [doLoop] method. * scroll in and scroll out operations using the [doLoop] method.
*
* Example usage:
*
* ```
* orchestrator.scrollOutToHeight(12, 2)
* ```
* *
* @param height The height in game coordinates to scroll out to. * @param height The height in game coordinates to scroll out to.
* @param scrollWaitAndVariance The number of milliseconds to wait between scroll actions. * @param scrollWaitAndVariance The number of milliseconds to wait between scroll actions.
@ -44,9 +50,14 @@ interface Orchestrator {
* The offset points are calculated by moving left/right and up/down from the * The offset points are calculated by moving left/right and up/down from the
* center point by a fixed offset amount. * center point by a fixed offset amount.
* *
* Usage Example:
* ```
* orchestrator.drawStar()
* ```
*
* @param p The center point of the star. * @param p The center point of the star.
*/ */
fun drawStar(p: Point) { fun drawStar(p: Point = automaton.getPointerLocation()) {
val offset = 100 val offset = 100
val top = Point(p.x, p.y - offset * 2) val top = Point(p.x, p.y - offset * 2)
val topright = Point(p.x + offset * 2, p.y + offset) val topright = Point(p.x + offset * 2, p.y + offset)
@ -71,13 +82,21 @@ interface Orchestrator {
* Typical usage is to provide a point where something needs to be clicked, * Typical usage is to provide a point where something needs to be clicked,
* along with a sleep duration to wait after clicking. * along with a sleep duration to wait after clicking.
* *
*
* Example usage:
*
* ```
* val clickPoint = Point(100, 200)
* orchestrator.moveMouseLeftClickAndSleep(clickPoint, 500)
* ```
*
* The random variance in sleep time helps match real human actions. * The random variance in sleep time helps match real human actions.
* *
* @param p The point location to move the mouse and left click. * @param p The point location to move the mouse and left click.
* @param sleepDuration The base duration in ms to sleep after clicking. * @param sleepDuration The base duration in ms to sleep after clicking.
* @param sleepDurationVariance The allowed variance in the sleep duration. * @param sleepDurationVariance The allowed variance in the sleep duration.
*/ */
fun moveMouseLeftClickAndSleep(p: Point, sleepDuration: Long, sleepDurationVariance: Long) { fun moveMouseLeftClickAndSleep(p: Point, sleepDuration: Long, sleepDurationVariance: Long = 1) {
automaton.moveMouse(p) automaton.moveMouse(p)
automaton.sleepWithVariance(100, 50) automaton.sleepWithVariance(100, 50)
//left click //left click
@ -90,13 +109,21 @@ interface Orchestrator {
* *
* This method counts down from a provided number of seconds to 0. * This method counts down from a provided number of seconds to 0.
* *
* It calls the provided [announceFn] function on each step, passing the current * It calls the provided [announceFn] function on each step, passing the current step number.
* step number.
* A sleep of 1 second is added between each step. * A sleep of 1 second is added between each step.
*
*
* Typical usage is to print a countdown message within [announceFn]. * Typical usage is to print a countdown message within [announceFn].
*
* Usage example:
*
* ```
*
* orchestrator.countdown(5) {
* print("\rCountdown: $step ")
* }
* ```
*
* @param nSeconds The number of seconds to count down. * @param nSeconds The number of seconds to count down.
* @param announceFn A callback function called each step, passed step number. * @param announceFn A callback function called each step, passed step number.
*/ */
@ -107,6 +134,8 @@ interface Orchestrator {
} }
} }
/** /**
* Gets the mouse pointer location after a delay. * Gets the mouse pointer location after a delay.
* *
@ -119,6 +148,12 @@ interface Orchestrator {
* The delay helps ensure any prior mouse movements have settled before * The delay helps ensure any prior mouse movements have settled before
* sampling the location. * sampling the location.
* *
* Usage example:
*
* ```
* val location = orchestrator.getMouseLocationAfterDelay(5)
* println(location) // Prints current mouse location after 5 second delay
* ```
* @param delayInSeconds The number of seconds to wait before sampling pointer location. * @param delayInSeconds The number of seconds to wait before sampling pointer location.
* @return The mouse pointer location after the delay as a Point. * @return The mouse pointer location after the delay as a Point.
*/ */
@ -143,6 +178,14 @@ interface Orchestrator {
* *
* The delay allows the mouse to settle before sampling its position. * The delay allows the mouse to settle before sampling its position.
* *
* Usage example:
*
* ```
* val prompt = "Move mouse to top left corner"
* val pos = orchestrator.promptForMousePosition(prompt)
* println(pos)
* ```
*
* @param prompt The message to display to prompt user to position mouse. * @param prompt The message to display to prompt user to position mouse.
* @return The Point position of the mouse after user positions it. * @return The Point position of the mouse after user positions it.
*/ */
@ -165,6 +208,19 @@ interface Orchestrator {
* *
* This handles iterating over the loop, tracking progress, and calling the provided task function each iteration. * This handles iterating over the loop, tracking progress, and calling the provided task function each iteration.
* *
* Typical usage is to pass a task function that performs some unit of work. doLoop() will call that task function
* repeatedly to automate a repetitive process.
*
* Usage example:
*
* ```
* val totalItems = 1000
* val itemsPerBatch = 10
* orchestrator.doLoop(totalItems, itemsPerBatch){
* // Craft one item
* }
* ```
*
* @param totalVolume The total number of units that need to be processed. * @param totalVolume The total number of units that need to be processed.
* @param volumePerStep The number of units to process per iteration. * @param volumePerStep The number of units to process per iteration.
* @param task The function to call each iteration, passing the Orchestrator as argument. * @param task The function to call each iteration, passing the Orchestrator as argument.

View File

@ -80,7 +80,7 @@ object Routines {
println("\rClean herbs infused") println("\rClean herbs infused")
val finish = System.currentTimeMillis() val finish = System.currentTimeMillis()
agent.drawStar(agent.automaton.getPointerLocation()) agent.drawStar()
println("Entire chain finished in ${HelperFunctions.prettyTimeString(finish - start)}") println("Entire chain finished in ${HelperFunctions.prettyTimeString(finish - start)}")
} }