screenshot: Capture Barbarian Assault high gamble screenshots (#12071)

This commit is contained in:
LA
2020-07-29 22:39:22 -07:00
committed by GitHub
parent 04648664ad
commit 40f032bede
3 changed files with 61 additions and 7 deletions

View File

@@ -229,11 +229,23 @@ public interface ScreenshotConfig extends Config
return false; return false;
} }
@ConfigItem(
keyName = "baHighGamble",
name = "Screenshot BA high gambles",
description = "Take a screenshot of your reward from a high gamble at Barbarian Assault.",
position = 16,
section = whatSection
)
default boolean screenshotHighGamble()
{
return false;
}
@ConfigItem( @ConfigItem(
keyName = "hotkey", keyName = "hotkey",
name = "Screenshot hotkey", name = "Screenshot hotkey",
description = "When you press this key a screenshot will be taken", description = "When you press this key a screenshot will be taken",
position = 16 position = 17
) )
default Keybind hotkey() default Keybind hotkey()
{ {

View File

@@ -110,6 +110,7 @@ public class ScreenshotPlugin extends Plugin
private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed", private static final ImmutableList<String> PET_MESSAGES = ImmutableList.of("You have a funny feeling like you're being followed",
"You feel something weird sneaking into your backpack", "You feel something weird sneaking into your backpack",
"You have a funny feeling like you would have been followed"); "You have a funny feeling like you would have been followed");
private static final Pattern BA_HIGH_GAMBLE_REWARD_PATTERN = Pattern.compile("(?<reward>.+)!<br>High level gamble count: <col=7f0000>(?<gambleCount>.+)</col>");
private String clueType; private String clueType;
private Integer clueNumber; private Integer clueNumber;
@@ -238,8 +239,17 @@ public class ScreenshotPlugin extends Plugin
} }
else if (client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT) != null) else if (client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT) != null)
{ {
fileName = parseLevelUpWidget(WidgetInfo.DIALOG_SPRITE_TEXT); String text = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT).getText();
screenshotSubDir = "Levels"; if (Text.removeTags(text).contains("High level gamble"))
{
fileName = parseBAHighGambleWidget(text);
screenshotSubDir = "BA High Gambles";
}
else
{
fileName = parseLevelUpWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
screenshotSubDir = "Levels";
}
} }
else if (client.getWidget(WidgetInfo.QUEST_COMPLETED_NAME_TEXT) != null) else if (client.getWidget(WidgetInfo.QUEST_COMPLETED_NAME_TEXT) != null)
{ {
@@ -378,7 +388,7 @@ public class ScreenshotPlugin extends Plugin
takeScreenshot(fileName, "Pets"); takeScreenshot(fileName, "Pets");
} }
if (config.screenshotBossKills() ) if (config.screenshotBossKills())
{ {
Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage); Matcher m = BOSSKILL_MESSAGE_PATTERN.matcher(chatMessage);
if (m.matches()) if (m.matches())
@@ -455,12 +465,17 @@ public class ScreenshotPlugin extends Plugin
} }
break; break;
case LEVEL_UP_GROUP_ID: case LEVEL_UP_GROUP_ID:
case DIALOG_SPRITE_GROUP_ID:
if (!config.screenshotLevels()) if (!config.screenshotLevels())
{ {
return; return;
} }
break; break;
case DIALOG_SPRITE_GROUP_ID:
if (!(config.screenshotLevels() || config.screenshotHighGamble()))
{
return;
}
break;
case KINGDOM_GROUP_ID: case KINGDOM_GROUP_ID:
if (!config.screenshotKingdom()) if (!config.screenshotKingdom())
{ {
@@ -626,12 +641,32 @@ public class ScreenshotPlugin extends Plugin
return "Quest(" + quest + ')'; return "Quest(" + quest + ')';
} }
/**
* Parses the Barbarian Assault high gamble reward dialog text into a shortened string for filename usage.
*
* @param text The {@link Widget#getText() text} of the {@link WidgetInfo#DIALOG_SPRITE_TEXT} widget.
* @return Shortened string in the format "High Gamble(100)"
*/
@VisibleForTesting
static String parseBAHighGambleWidget(final String text)
{
final Matcher highGambleMatch = BA_HIGH_GAMBLE_REWARD_PATTERN.matcher(text);
if (highGambleMatch.find())
{
String gambleCount = highGambleMatch.group("gambleCount");
return String.format("High Gamble(%s)", gambleCount);
}
return "High Gamble(count not found)";
}
/** /**
* Saves a screenshot of the client window to the screenshot folder as a PNG, * Saves a screenshot of the client window to the screenshot folder as a PNG,
* and optionally uploads it to an image-hosting service. * and optionally uploads it to an image-hosting service.
* *
* @param fileName Filename to use, without file extension. * @param fileName Filename to use, without file extension.
* @param subDir Subdirectory to store the captured screenshot in. * @param subDir Subdirectory to store the captured screenshot in.
*/ */
private void takeScreenshot(String fileName, String subDir) private void takeScreenshot(String fileName, String subDir)
{ {

View File

@@ -66,6 +66,7 @@ public class ScreenshotPluginTest
private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: <col=ff0000>73</col>."; private static final String THEATRE_OF_BLOOD_CHEST = "Your completed Theatre of Blood count is: <col=ff0000>73</col>.";
private static final String VALUABLE_DROP = "<col=ef1020>Valuable drop: 6 x Bronze arrow (42 coins)</col>"; private static final String VALUABLE_DROP = "<col=ef1020>Valuable drop: 6 x Bronze arrow (42 coins)</col>";
private static final String UNTRADEABLE_DROP = "<col=ef1020>Untradeable drop: Rusty sword"; private static final String UNTRADEABLE_DROP = "<col=ef1020>Untradeable drop: Rusty sword";
private static final String BA_HIGH_GAMBLE_REWARD = "Raw shark (x 300)!<br>High level gamble count: <col=7f0000>100</col>";
@Mock @Mock
@Bind @Bind
@@ -258,4 +259,10 @@ public class ScreenshotPluginTest
assertEquals("Quest(Doric's Quest)", ScreenshotPlugin.parseQuestCompletedWidget("You have completed Doric's Quest!")); assertEquals("Quest(Doric's Quest)", ScreenshotPlugin.parseQuestCompletedWidget("You have completed Doric's Quest!"));
assertEquals("Quest(quest not found)", ScreenshotPlugin.parseQuestCompletedWidget("Sins of the Father forgiven!")); assertEquals("Quest(quest not found)", ScreenshotPlugin.parseQuestCompletedWidget("Sins of the Father forgiven!"));
} }
@Test
public void testBAHighGambleRewardParsing()
{
assertEquals("High Gamble(100)", ScreenshotPlugin.parseBAHighGambleWidget(BA_HIGH_GAMBLE_REWARD));
}
} }