Skip to content

Commit

Permalink
chore: simplify QuestManager startUpQuest public API (#1863)
Browse files Browse the repository at this point in the history
* chore: simplify QuestManager's public `startUpQuest` API

We now only expose one function with both parameters (QuestHelper + whether the sidepanel should open)

This function handles the thread dispatching, if needed. This means the single function can be called from both the AWT
thread & the client thread without having to wait an extra tick in some scenarios.

* unrelated: Add Lightbearer as a requirement to the sidepanel of Bikeshedder
  • Loading branch information
pajlada authored Nov 24, 2024
1 parent c296cfb commit 0222ffd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
48 changes: 16 additions & 32 deletions src/main/java/com/questhelper/managers/QuestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.steps.QuestStep;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
Expand Down Expand Up @@ -86,9 +85,6 @@ public class QuestManager
@Named("developerMode")
private boolean developerMode;

@Setter
private QuestHelper sidebarSelectedQuest;

@Getter
private QuestHelper selectedQuest;
private boolean loadQuestList = false;
Expand Down Expand Up @@ -128,24 +124,10 @@ public void setupOnLogin()
*/
public void updateQuestState()
{
handleSidebarQuest();
handleSelectedQuest();
handleQuestListUpdate();
}

/**
* Handles the quest selected in the sidebar.
* Starts up the sidebar quest and resets it to null.
*/
private void handleSidebarQuest()
{
if (sidebarSelectedQuest != null)
{
startUpQuest(sidebarSelectedQuest);
sidebarSelectedQuest = null;
}
}

/**
* Handles the currently selected quest.
* Updates steps, highlights, and item requirements.
Expand Down Expand Up @@ -251,33 +233,35 @@ public void updateQuestList()
}
}

/**
* Starts up a quest.
* Shuts down any active quest and initializes the new quest.
*
* @param questHelper The quest to be started.
*/
public void startUpQuest(QuestHelper questHelper)
private void doStartUpQuest(QuestHelper questHelper, boolean shouldOpenSidebarIfConfig)
{
startUpQuest(questHelper, true);
if (!(client.getGameState() == GameState.LOGGED_IN))
{
return;
}

shutDownPreviousQuest();
initializeNewQuest(questHelper, shouldOpenSidebarIfConfig);
}

/**
* Starts up a quest.
* Shuts down any active quest and initializes the new quest.
* <p>
* This can be called from any thread
*
* @param questHelper The quest to be started.
* @param shouldOpenSidebarIfConfig Flag to open the sidebar if configured.
*/
public void startUpQuest(QuestHelper questHelper, boolean shouldOpenSidebarIfConfig)
{
if (!(client.getGameState() == GameState.LOGGED_IN))
{
return;
if (client.isClientThread()) {
this.doStartUpQuest(questHelper, shouldOpenSidebarIfConfig);
} else {
clientThread.invokeLater(() -> {
this.doStartUpQuest(questHelper, shouldOpenSidebarIfConfig);
});
}

shutDownPreviousQuest();
initializeNewQuest(questHelper, shouldOpenSidebarIfConfig);
}

private void initializeNewQuest(QuestHelper questHelper, boolean shouldOpenSidebarIfConfig)
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/questhelper/managers/QuestMenuHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ private void handleShieldOfArrav()
QuestHelperQuest.SHIELD_OF_ARRAV_PHOENIX_GANG :
QuestHelperQuest.SHIELD_OF_ARRAV_BLACK_ARM_GANG;

questManager.startUpQuest(QuestHelperQuest.getByName(questToStart.getName()));
questManager.startUpQuest(QuestHelperQuest.getByName(questToStart.getName()), true);
}

/**
* Handles the special case for starting up the "Recipe for Disaster" quest.
*/
private void handleRecipeForDisaster()
{
questManager.startUpQuest(QuestHelperQuest.getByName(QuestHelperQuest.RECIPE_FOR_DISASTER_START.getName()));
questManager.startUpQuest(QuestHelperQuest.getByName(QuestHelperQuest.RECIPE_FOR_DISASTER_START.getName()), true);
}

/**
Expand All @@ -160,7 +160,7 @@ private void handleGenericQuest(String questName)
QuestHelper questHelper = QuestHelperQuest.getByName(questName);
if (questHelper != null)
{
questManager.startUpQuest(questHelper);
questManager.startUpQuest(questHelper, true);
}
}

Expand Down Expand Up @@ -356,7 +356,7 @@ private void handleMenuEntryClick(String newEntry, String target)
if (newEntry.startsWith("Start"))
{
String quest = Text.removeTags(target);
questManager.startUpQuest(QuestHelperQuest.getByName(quest));
questManager.startUpQuest(QuestHelperQuest.getByName(quest), true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/questhelper/panel/QuestHelperPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public void setSelectedQuest(QuestHelper questHelper)
if ("true".equals(configManager.getConfiguration(QuestHelperConfig.QUEST_BACKGROUND_GROUP, "selected-assist-level")))
{
searchQuestsPanel.setVisible(true);
questManager.setSidebarSelectedQuest(questHelper);
questManager.startUpQuest(questHelper, true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void actionPerformed(ActionEvent e)
@Override
public void actionPerformed(ActionEvent e)
{
questManager.setSidebarSelectedQuest(finalQuest1);
questManager.startUpQuest(finalQuest1, true);
}
});

Expand All @@ -198,7 +198,7 @@ public void mouseClicked(MouseEvent e)
{
if (SwingUtilities.isLeftMouseButton(e))
{
questManager.setSidebarSelectedQuest(finalQuest);
questManager.startUpQuest(finalQuest, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class BikeShedder extends BasicQuestHelper
private WidgetTextRequirement lookAtCooksAssistantTextRequirement;
private ZoneRequirement byStaircaseInSunrisePalace;
private ObjectStep goDownstairsInSunrisePalace;
private ItemRequirement lightbearer;

@Override
public Map<Integer, QuestStep> loadSteps()
Expand Down Expand Up @@ -108,7 +109,7 @@ protected void setupRequirements()
confuseHans = new NpcStep(this, NpcID.HANS, new WorldPoint(3221, 3218, 0), "Cast Confuse on Hans", normalSpellbook);
confuseHans.addSpellHighlight(NormalSpells.CONFUSE);

var lightbearer = new ItemRequirement("Lightbearer", ItemID.LIGHTBEARER).highlighted();
lightbearer = new ItemRequirement("Lightbearer", ItemID.LIGHTBEARER).highlighted();
equipLightbearer = new DetailedQuestStep(this, "Equip a Lightbearer", lightbearer.equipped());

anyLog = new ItemRequirement("Any log", ItemCollections.LOGS_FOR_FIRE).highlighted();
Expand Down Expand Up @@ -160,7 +161,7 @@ public List<PanelDetails> getPanels()

panels.add(new PanelDetails("Move to Lumbridge", List.of(moveToLumbridge)));
panels.add(new PanelDetails("Normal Spellbook", List.of(confuseHans)));
panels.add(new PanelDetails("Equip Lightbearer", List.of(equipLightbearer)));
panels.add(new PanelDetails("Equip Lightbearer", List.of(equipLightbearer), List.of(lightbearer)));
panels.add(new PanelDetails("Use log on mysterious bush", List.of(useLogOnBush), List.of(anyLog)));
panels.add(new PanelDetails("Use coins on mysterious bush", List.of(useCoinOnBush, useManyCoinsOnBush), List.of(oneCoin, manyCoins)));
panels.add(new PanelDetails("Conditional requirement", List.of(conditionalRequirementLookAtCoins), List.of(conditionalRequirementCoins, conditionalRequirementGoldBar)));
Expand Down

0 comments on commit 0222ffd

Please sign in to comment.