Skip to content

Commit

Permalink
Merge pull request #471 from xpdota/timeline-import
Browse files Browse the repository at this point in the history
Support for putting cooldowns on a timeline via a replay
  • Loading branch information
xpdota authored Dec 29, 2023
2 parents b7f81e5 + 5b37dbb commit c9dea5e
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 27 deletions.
1 change: 1 addition & 0 deletions reevent/src/main/java/gg/xp/reevent/scan/AutoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.stream.Collectors;

@Deprecated
public class AutoHandler implements TypedEventHandler<Event> {

private static final Logger log = LoggerFactory.getLogger(AutoHandler.class);
Expand Down
3 changes: 2 additions & 1 deletion reevent/src/main/java/gg/xp/reevent/scan/AutoScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void doScan() {

Map<Class<?>, List<Method>> classMethodMap = new LinkedHashMap<>();
for (Class<?> annotatedClass : annotatedClasses) {
if (isClassInstantiable(annotatedClass)) {
if (isClassInstantiable(annotatedClass) && !annotatedClass.isAnnotationPresent(NoAutoScan.class)) {
classMethodMap.computeIfAbsent(annotatedClass, unused -> new ArrayList<>());
}
else {
Expand All @@ -164,6 +164,7 @@ private void doScan() {
//noinspection SimplifyForEach
Stream.concat(Stream.of(clazz), implementingClasses.stream())
.filter(AutoScan::isClassInstantiable)
.filter(c -> !c.isAnnotationPresent(NoAutoScan.class))
.forEach(cls -> classMethodMap.computeIfAbsent(cls, unused -> new ArrayList<>()).add(method));
}
log.info("Methods: {}", methodCount);
Expand Down
12 changes: 12 additions & 0 deletions reevent/src/main/java/gg/xp/reevent/scan/NoAutoScan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gg.xp.reevent.scan;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Causes the annotated class to NOT be scanned by {@link AutoHandlerScan} even if it does have annotations
* that would otherwise cause it to be scanned.
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface NoAutoScan {
}
4 changes: 4 additions & 0 deletions reevent/src/main/java/gg/xp/reevent/scan/ScanMe.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package gg.xp.reevent.scan;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Causes the annotated class to be scanned by {@link AutoHandlerScan} even if it does not have any annotations
* that would otherwise cause it to be scanned.
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ScanMe {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CustomTimelineEntry implements CustomTimelineItem, Serializable {
public @Nullable Double windowEnd;
public @Nullable Double jump;
public @Nullable String jumpLabel;
public @Nullable String importSource;
public boolean forceJump;
// TODO: this uses the absolute path to the JAR, which means icons will break if the user moves their install location.
// Best solution is to probably make our own little class that lets you specify an ability/status ID in addition to
Expand Down Expand Up @@ -61,9 +62,10 @@ public CustomTimelineEntry(
@Nullable Boolean forceJump,
@Nullable URL icon,
@Nullable TimelineReference replaces,
boolean disabled,
boolean callout,
double calloutPreTime
boolean disabled,
boolean callout,
double calloutPreTime,
@Nullable String importSource
) {
// TODO: this wouldn't be a bad place to do the JAR url correction. Perhaps not the cleanest way,
// but it works.
Expand All @@ -82,6 +84,7 @@ public CustomTimelineEntry(
this.icon = icon;
this.replaces = replaces;
this.enabled = !disabled;
this.importSource = importSource;
}

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand All @@ -98,6 +101,7 @@ public CustomTimelineEntry(
@JsonProperty("icon") @Nullable URL icon,
@JsonProperty("replaces") @Nullable TimelineReference replaces,
@JsonProperty(value = "disabled", defaultValue = "false") boolean disabled,
@JsonProperty(value = "importSource") String importSource,
@JsonProperty(value = "callout", defaultValue = "false") boolean callout,
@JsonProperty(value = "calloutPreTime", defaultValue = "0") double calloutPreTime,
@JsonProperty("jobs") @Nullable CombatJobSelection jobs
Expand All @@ -120,6 +124,7 @@ public CustomTimelineEntry(
this.enabled = !disabled;
this.enabledJobs = jobs == null ? CombatJobSelection.all() : jobs;
this.esc = esc;
this.importSource = importSource;
}

@Override
Expand Down Expand Up @@ -270,7 +275,8 @@ public static CustomTimelineEntry overrideFor(TimelineEntry other) {
TimelineReference.of(other),
false,
false,
0
0,
null
);
newCte.enabledJobs = jobSelFor(other);
return newCte;
Expand All @@ -292,7 +298,8 @@ public static CustomTimelineEntry cloneFor(TimelineEntry other) {
null,
false,
other.callout(),
other.calloutPreTime()
other.calloutPreTime(),
null
);
newCte.enabledJobs = jobSelFor(other);
return newCte;
Expand Down Expand Up @@ -331,4 +338,9 @@ public boolean enabledForJob(Job job) {
// Don't bother serializing if every job is selected
return enabledJobs.isEnabledForAll() ? null : enabledJobs;
}

@Override
public @Nullable String getImportSource() {
return importSource;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gg.xp.xivsupport.timelines;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import gg.xp.reevent.events.Event;
import gg.xp.xivdata.data.*;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,6 +18,7 @@
/**
* Base interface for a timeline entry
*/
@JsonIgnoreProperties("imported")
public interface TimelineEntry extends Comparable<TimelineEntry> {

/**
Expand Down Expand Up @@ -399,4 +403,15 @@ private String callTextForExport() {
},
""", uniqueName, uniqueName, calloutPreTime(), callTextForExport());
}

@JsonProperty
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
default @Nullable String getImportSource() {
return null;
};

@JsonIgnore
default boolean isImported() {
return getImportSource() != null;
}
}
Loading

0 comments on commit c9dea5e

Please sign in to comment.