Skip to content

Commit

Permalink
Merge pull request #443 from xpdota/groovy-callout-enhancements
Browse files Browse the repository at this point in the history
Groovy callout enhancements
  • Loading branch information
xpdota authored Oct 1, 2023
2 parents cdc09be + 65cab71 commit 27de539
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 22 deletions.
10 changes: 10 additions & 0 deletions reevent/src/main/java/gg/xp/reevent/events/DummyEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gg.xp.reevent.events;

import java.io.Serial;

// Event that should do pretty much nothing. Mostly for testing purposes.
@SystemEvent
public class DummyEvent extends BaseEvent {
@Serial
private static final long serialVersionUID = -1422848827451666698L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ public void add(@DelegatesTo(Builder.class) Closure<?> closure) {
builder.finish();
}

private BooleanSupplier wrapBooleanSupplier(BooleanSupplier supplier) {
return () -> {
try (SandboxScope ignored = sandbox.enter()) {
return supplier.getAsBoolean();
}
};
}
private <X> Supplier<X> wrapSupplier(Supplier<X> supplier) {
return () -> {
try (SandboxScope ignored = sandbox.enter()) {
Expand Down Expand Up @@ -288,7 +295,7 @@ public CalloutEvent callout(@DelegatesTo(GroovyCalloutBuilder.class) Closure<?>
Supplier<String> text = gcb.text;
Duration timeBasis = controller.timeSinceStart();
Duration expiresAt = timeBasis.plusMillis(gcb.duration);
BooleanSupplier expired = gcb.expiry == null ? () -> controller.timeSinceStart().compareTo(expiresAt) > 0 : gcb.expiry;
BooleanSupplier expired = gcb.expired == null ? () -> controller.timeSinceStart().compareTo(expiresAt) > 0 : wrapBooleanSupplier(gcb.expired);
ProcessedCalloutEvent callout = new ProcessedCalloutEvent(
new CalloutTrackingKey(),
gcb.tts,
Expand Down Expand Up @@ -327,7 +334,7 @@ public class GroovyCalloutBuilder extends GroovyObjectSupport {
@NotNull Supplier<@Nullable String> text = () -> null;
int duration = 5000;
@Nullable HasCalloutTrackingKey replaces;
@Nullable BooleanSupplier expiry;
@Nullable BooleanSupplier expired;
@Nullable Color color;
@Nullable String soundFile;
@NotNull Supplier<@Nullable Component> guiProvider = () -> null;
Expand Down Expand Up @@ -390,6 +397,11 @@ public GroovyCalloutBuilder duration(int duration) {
return this;
}

public GroovyCalloutBuilder displayWhile(BooleanSupplier displayWhile) {
this.expired = () -> !displayWhile.getAsBoolean();
return this;
}

public GroovyCalloutBuilder replaces(CalloutTrackingKey replaces) {
this.replaces = () -> replaces;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,21 @@ public synchronized void registerHandler(EventHandler<Event> handler) {
dirty = true;
}

public void reloadIfNeeded() {
public void reloadIfNeeded(Event event) {
scanner.doScanIfNeeded();
if (!dirty) {
return;
if (dirty) {
synchronized (loadLock) {
if (dirty) {
log.info("Reloading due to {}", event);
handlers.clear();
handlers.addAll(manualHandlers);
handlers.addAll(autoHandlers);
sortHandlers();
topology = Topology.fromHandlers(new ArrayList<>(this.handlers), topoInfo);
dirty = false;
}
}
}
log.info("Reloading", new RuntimeException());
// synchronized (loadLock) {
handlers.clear();
handlers.addAll(manualHandlers);
handlers.addAll(autoHandlers);
sortHandlers();
// }
topology = Topology.fromHandlers(new ArrayList<>(this.handlers), topoInfo);
dirty = false;
}

@Override
Expand Down Expand Up @@ -114,7 +115,7 @@ public Topology getTopology() {

@Override
public void acceptEvent(Event event) {
reloadIfNeeded();
reloadIfNeeded(event);
super.acceptEvent(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.function.Function;
import java.util.function.Predicate;

// TODO: make a toString for this
@SystemEvent
public class RawModifiedCallout<X> extends BaseEvent implements HasCalloutTrackingKey, HasPrimaryValue {
private static final Logger log = LoggerFactory.getLogger(RawModifiedCallout.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public abstract class BaseCalloutEvent extends BaseEvent implements CalloutEvent
private @Nullable Color colorOverride;
private @Nullable HasCalloutTrackingKey replaces;
private @Nullable CalloutTraceInfo trace;
private boolean forceExpire;

private final CalloutTrackingKey key;

Expand Down Expand Up @@ -72,4 +73,15 @@ public CalloutTraceInfo getTrace() {
public void setTrace(CalloutTraceInfo trace) {
this.trace = trace;
}

@Override
public final boolean isExpired() {
return forceExpire || isNaturallyExpired();
}

public abstract boolean isNaturallyExpired();

public void forceExpire() {
this.forceExpire = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public BasicCalloutEvent(String callText, String visualText, long hangTime) {
}

@Override
public boolean isExpired() {
public boolean isNaturallyExpired() {
return getTimeSinceCall().compareTo(hangTime) > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DynamicCalloutEvent(CalloutTrackingKey key, String callText, Supplier<Str
}

@Override
public boolean isExpired() {
public boolean isNaturallyExpired() {
return getTimeSinceCall().compareTo(hangTime) > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ParentedCalloutEvent(X event, String callText, Supplier<String> visualTex
}

@Override
public boolean isExpired() {
public boolean isNaturallyExpired() {
return expiryCheck.test(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ProcessedCalloutEvent(CalloutTrackingKey key, String ttsText, Supplier<St
}

@Override
public boolean isExpired() {
public boolean isNaturallyExpired() {
return expired.getAsBoolean();
}

Expand All @@ -52,4 +52,5 @@ public boolean isExpired() {
public @Nullable String getSound() {
return soundFile;
}

}
10 changes: 8 additions & 2 deletions xivsupport/src/main/resources/te_changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ <h2>Beta</h2>
in a script to have it automatically request to be run on startup the first time it is run. This should
make it easier to share scripts that are intended to run on startup.
</li>
<li>Better options for managing callouts in Groovy scripted triggers: See <a
href="https://triggevent.io/pages/groovy/Groovy-Introduction/#sequential-triggers">documentation
here</a>.
</li>
<li>Concurrency control for Sequential Triggers. See the <a
href="https://triggevent.io/pages/docs/Sequential-Triggers/#concurrency-mode">the website</a> for
more info.
</li>
<li>Easy Triggers: New actions to wait for a buff/cast remaining duration to be below a certain time. Useful for having a reminder of when a buff is about to expire.</li>
<li>Easy Triggers: New actions to wait for a buff/cast remaining duration to be below a certain time. Useful
for having a reminder of when a buff is about to expire.
</li>
</ul>
<h2>Sep 3, 2023</h2>
<ul>
<li>Timelines: Support force jumps and labels.</li>
</ul>
<h2>July 7, 2023</h2>
<ul>
<li>Improved custom TTS program support, now supports quotes to allow spaces in argumentsm ".</li>
<li>Improved custom TTS program support, now supports quotes to allow spaces in arguments".</li>
<li>Minor additions to P10S.</li>
</ul>
<h2>June 29, 2023</h2>
Expand Down

0 comments on commit 27de539

Please sign in to comment.