Skip to content

Commit

Permalink
clues: avoid checking clue text each tick
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Jul 6, 2022
1 parent fa41eb6 commit 163fd49
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
Expand Down Expand Up @@ -174,6 +175,9 @@ public class ClueScrollPlugin extends Plugin
@Getter
private Client client;

@Inject
private ClientThread clientThread;

@Inject
private ItemManager itemManager;

Expand Down Expand Up @@ -673,34 +677,36 @@ public void onGameTick(final GameTick event)
{
resetClue(false);
}

final Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT);

if (clueScrollText != null)
{
ClueScroll clueScroll = findClueScroll(clueScrollText.getText());
if (clueScroll != null)
{
updateClue(clueScroll);
}
else
{
log.info("Unknown clue text: {}", clueScrollText.getText());
resetClue(true);
}
}
}

@Subscribe
public void onWidgetLoaded(WidgetLoaded event)
{
if (event.getGroupId() < WidgetID.BEGINNER_CLUE_MAP_CHAMPIONS_GUILD
|| event.getGroupId() > WidgetID.BEGINNER_CLUE_MAP_WIZARDS_TOWER)
if (event.getGroupId() >= WidgetID.BEGINNER_CLUE_MAP_CHAMPIONS_GUILD
&& event.getGroupId() <= WidgetID.BEGINNER_CLUE_MAP_WIZARDS_TOWER)
{
return;
updateClue(BeginnerMapClue.forWidgetID(event.getGroupId()));
}
else if (event.getGroupId() == WidgetID.CLUE_SCROLL_GROUP_ID)
{
clientThread.invokeLater(() ->
{
final Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT);
if (clueScrollText != null)
{
ClueScroll clueScroll = findClueScroll(clueScrollText.getText());
if (clueScroll != null)
{
updateClue(clueScroll);
}
else
{
log.info("Unknown clue text: {}", clueScrollText.getText());
resetClue(true);
}
}
});
}

updateClue(BeginnerMapClue.forWidgetID(event.getGroupId()));
}

@Subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.banktags.TagManager;
import net.runelite.client.plugins.cluescrolls.clues.hotcold.HotColdLocation;
Expand All @@ -61,10 +64,12 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.any;
import org.mockito.Mock;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -77,6 +82,10 @@ public class ClueScrollPluginTest
@Bind
Client client;

@Mock
@Bind
ClientThread clientThread;

@Inject
ClueScrollPlugin plugin;

Expand Down Expand Up @@ -126,7 +135,15 @@ public void testLocationHintArrowCleared()
int clueSetupHintArrowClears = 0;

// Initialize a beginner hot-cold clue (which will have an end point of LUMBRIDGE_COW_FIELD)
plugin.onGameTick(new GameTick());
WidgetLoaded widgetLoaded = new WidgetLoaded();
widgetLoaded.setGroupId(WidgetID.CLUE_SCROLL_GROUP_ID);
plugin.onWidgetLoaded(widgetLoaded);

// clientthread callback
ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(clientThread).invokeLater(captor.capture());
captor.getValue().run();

verify(client, times(++clueSetupHintArrowClears)).clearHintArrow();

// Perform the first hot-cold check in Lumbridge near sheep pen (get 2 possible points: LUMBRIDGE_COW_FIELD and DRAYNOR_WHEAT_FIELD)
Expand Down Expand Up @@ -162,7 +179,16 @@ public void testSTASHMarkerPersistence()
final Widget clueWidget = mock(Widget.class);
when(clueWidget.getText()).thenReturn("Spin in the Varrock Castle courtyard. Equip a black axe, a coif and a ruby ring.");
when(client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT)).thenReturn(clueWidget);
plugin.onGameTick(new GameTick());

// open clue
WidgetLoaded widgetLoaded = new WidgetLoaded();
widgetLoaded.setGroupId(WidgetID.CLUE_SCROLL_GROUP_ID);
plugin.onWidgetLoaded(widgetLoaded);

// clientthread callback
ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(clientThread).invokeLater(captor.capture());
captor.getValue().run();

// Simulate clicking on the STASH
MenuOptionClicked menuOptionClicked = mock(MenuOptionClicked.class);
Expand All @@ -180,7 +206,17 @@ public void testSTASHMarkerPersistence()

// Complete the step and get a new step, check that the clue is stored for rendering
when(clueWidget.getText()).thenReturn("Talk to the bartender of the Rusty Anchor in Port Sarim.");
plugin.onGameTick(new GameTick());

// open clue
reset(clientThread);
widgetLoaded.setGroupId(WidgetID.CLUE_SCROLL_GROUP_ID);
plugin.onWidgetLoaded(widgetLoaded);

// clientthread callback
captor = ArgumentCaptor.forClass(Runnable.class);
verify(clientThread).invokeLater(captor.capture());
captor.getValue().run();

assertNotNull(plugin.getActiveSTASHClue());

// Simulate depositing the emote items, make sure it's cleared the stored clue
Expand Down

0 comments on commit 163fd49

Please sign in to comment.