diff --git a/timelines/src/main/java/gg/xp/xivsupport/timelines/EventSyncController.java b/timelines/src/main/java/gg/xp/xivsupport/timelines/EventSyncController.java index 3a9f6b8794cc..033e1937eabe 100644 --- a/timelines/src/main/java/gg/xp/xivsupport/timelines/EventSyncController.java +++ b/timelines/src/main/java/gg/xp/xivsupport/timelines/EventSyncController.java @@ -1,6 +1,7 @@ package gg.xp.xivsupport.timelines; import gg.xp.reevent.events.Event; +import gg.xp.xivsupport.timelines.intl.LanguageReplacements; public interface EventSyncController { boolean shouldSync(Event event); @@ -10,4 +11,8 @@ public interface EventSyncController { default boolean isEditable() { return false; }; + + EventSyncController translateWith(LanguageReplacements replacements); + + String toTextFormat(); } diff --git a/timelines/src/main/java/gg/xp/xivsupport/timelines/FileEventSyncController.java b/timelines/src/main/java/gg/xp/xivsupport/timelines/FileEventSyncController.java index ccf76908f261..b1cfb72219f3 100644 --- a/timelines/src/main/java/gg/xp/xivsupport/timelines/FileEventSyncController.java +++ b/timelines/src/main/java/gg/xp/xivsupport/timelines/FileEventSyncController.java @@ -1,6 +1,8 @@ package gg.xp.xivsupport.timelines; import gg.xp.reevent.events.Event; +import gg.xp.xivsupport.timelines.cbevents.CbEventFmt; +import gg.xp.xivsupport.timelines.intl.LanguageReplacements; import java.util.HashMap; import java.util.Map; @@ -10,11 +12,13 @@ public class FileEventSyncController implements EventSyncController { private final Class eventType; private final Predicate predicate; + private final String originalType; private final Map original; - public FileEventSyncController(Class eventType, Predicate predicate, Map original) { + public FileEventSyncController(Class eventType, Predicate predicate, String originalType, Map original) { this.eventType = eventType; this.predicate = predicate; + this.originalType = originalType; this.original = new HashMap<>(original); } @@ -28,6 +32,26 @@ public Class eventType() { return eventType; } + @Override + public EventSyncController translateWith(LanguageReplacements replacements) { + Map modified = new HashMap<>(original); + modified.replaceAll((key, val) -> { + for (var syncReplacement : replacements.replaceSync().entrySet()) { + val = syncReplacement.getKey().matcher(val).replaceAll(syncReplacement.getValue()); + } + return val; + }); + if (modified.equals(original)) { + return this; + } + return CbEventFmt.parse(originalType, modified); + } + + @Override + public String toTextFormat() { + return CbEventFmt.format(this.originalType, this.original); + } + @Override public String toString() { return eventType.getSimpleName() + original; diff --git a/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineEntry.java b/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineEntry.java index 1c0c8d63a341..9d44d843a32e 100644 --- a/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineEntry.java +++ b/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineEntry.java @@ -313,6 +313,9 @@ default String toTextFormat() { if (sync() != null) { sb.append("sync /").append(sync().pattern()).append('/').append(' '); } + if (eventSyncController() != null) { + sb.append(eventSyncController().toTextFormat()).append(' '); + } TimelineWindow window = timelineWindow(); if (!TimelineWindow.DEFAULT.equals(window)) { sb.append("window ").append(fmtDouble(window.start())).append(',').append(fmtDouble(window.end())).append(' '); diff --git a/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineParser.java b/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineParser.java index 17c81d619ce9..9a9cd3fd3d02 100644 --- a/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineParser.java +++ b/timelines/src/main/java/gg/xp/xivsupport/timelines/TimelineParser.java @@ -1,12 +1,6 @@ package gg.xp.xivsupport.timelines; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.json.JsonReadFeature; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.json.JsonMapper; -import gg.xp.reevent.events.Event; -import gg.xp.xivsupport.timelines.cbevents.CbEventTypes; +import gg.xp.xivsupport.timelines.cbevents.CbEventFmt; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -14,9 +8,7 @@ import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -38,16 +30,6 @@ public final class TimelineParser { ); private static final Pattern timelineLabelPattern = Pattern.compile("^(?