Skip to content

Commit

Permalink
Merge pull request #5 from neeerp/bank-pin
Browse files Browse the repository at this point in the history
Don't take screenshots when the bank pin UI is open.
  • Loading branch information
neeerp committed Jul 15, 2023
2 parents 22d2601 + 6054f35 commit 540feb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Feel free to suggest improvements/features on this repository's issues page, or

## Configuration
Every game tick, there is a 1 in `n` chance that a screenshot is taken (with `n` configurable via the "Sample Weight"
option). _This does not guarantee a screenshot will be taken every `n` ticks! It's random!_
option). _This does not guarantee a screenshot will be taken every `n` ticks! It's random!_ Moreover, the roll to take a
screenshot does not happen whenever the bank pin UI is open.

For convenience, here's a table with the number of ticks in a given interval of real time.

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/randomscreenshot/RandomScreenshotPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.util.Random;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.events.GameTick;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
Expand All @@ -26,6 +29,9 @@ public class RandomScreenshotPlugin extends Plugin
@Inject
private ScreenshotUtil screenShotUtil;

@Inject
private Client client;

private final Random rand = new Random(System.currentTimeMillis());


Expand All @@ -44,11 +50,22 @@ public void onGameTick(GameTick event)
}
}

/* TODO: Create a decider interface so that decision strategy can be made modular. */
private boolean shouldTakeScreenshot() {
return rand.nextInt(config.sampleWeight()) == 0;
return isBankPINContainerHidden() && rand.nextInt(config.sampleWeight()) == 0;
}

private void takeScreenshot() {
screenShotUtil.takeScreenshot("", "Random Screenshots");
}

private boolean isBankPINContainerHidden()
{
Widget pinContainer = client.getWidget(WidgetInfo.BANK_PIN_CONTAINER);
if (pinContainer == null) {
return true;
}

return pinContainer.isSelfHidden();
}
}

0 comments on commit 540feb8

Please sign in to comment.