Skip to content

Commit

Permalink
Merge pull request #511 from xpdota/easy-trigger-tracking
Browse files Browse the repository at this point in the history
Traceability for easy triggers
  • Loading branch information
xpdota authored Jul 5, 2024
2 parents 05c9283 + fe934d5 commit 8f5f45f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gg.xp.reevent.events.Event;
import gg.xp.reevent.scan.ScanMe;
import gg.xp.xivsupport.callouts.RawModifiedCallout;
import gg.xp.xivsupport.events.ACTLogLineEvent;
import gg.xp.xivsupport.events.triggers.easytriggers.ActLegacyTriggerImport;
import gg.xp.xivsupport.events.triggers.easytriggers.EasyTriggers;
Expand Down Expand Up @@ -42,6 +43,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static gg.xp.xivsupport.events.triggers.easytriggers.model.EasyTriggerContext.SOURCE_EASY_TRIGGER_KEY;

@ScanMe
public class EasyTriggersTab implements PluginTab {

Expand All @@ -66,6 +69,12 @@ public EasyTriggersTab(EasyTriggers backend, RightClickOptionRepo rightClicks, G
"Make Easy Trigger",
Event.class,
this::makeTriggerFromEvent));
rightClicks.addOption(CustomRightClickOption.forRow(
"Go To Easy Trigger",
Event.class,
this::trySelectTriggerFromCallout,
EasyTriggersTab::canSelectTriggerFromCallout
));
// TODO: good candidate for sub-menus
// .addRightClickOption(CustomRightClickOption.forRowWithConverter("Make Easy Trigger", Event.class, Function.identity(), e -> {
// container.getComponent(EasyTrig)
Expand Down Expand Up @@ -507,4 +516,31 @@ private void makeTriggerFromEvent(Event event) {
public void bringToFront() {
tabReg.activateItem(this);
}

private static boolean canSelectTriggerFromCallout(Event event) {
return getEasyTriggerFromCallout(event) != null;
}

private void trySelectTriggerFromCallout(Event event) {
EasyTrigger<?> et = getEasyTriggerFromCallout(event);
if (et != null) {
bringToFront();
this.selectTrigger(et);
}
}

private static @Nullable EasyTrigger<?> getEasyTriggerFromCallout(Event event) {
RawModifiedCallout<?> rawModified = event.getThisOrParentOfType(RawModifiedCallout.class);
if (rawModified == null) {
return null;
}
Object source = rawModified.getArguments().get(SOURCE_EASY_TRIGGER_KEY);
if (source instanceof EasyTrigger<?> et) {
return et;
}
else {
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class EasyTriggerContext {

private static final Logger log = LoggerFactory.getLogger(EasyTriggerContext.class);
public static final String SOURCE_EASY_TRIGGER_KEY = "sourceEasyTrigger";

private final EventContext context;
// for logging
Expand Down Expand Up @@ -47,6 +48,7 @@ public EasyTriggerContext(EventContext context) {

public EasyTriggerContext(EventContext context, EasyTrigger<?> trigger) {
this(context, trigger.getName());
addVariable(SOURCE_EASY_TRIGGER_KEY, trigger);
}

public <X extends BaseEvent> void runActions(List<Action<? super X>> actions, SequentialTriggerController<X> s, X e1) {
Expand Down

0 comments on commit 8f5f45f

Please sign in to comment.