From a6efbe6a837f8238e5f491a2873363d6b3276448 Mon Sep 17 00:00:00 2001 From: johni0702 Date: Mon, 22 Aug 2016 16:15:19 +0200 Subject: [PATCH] Right clicking on timeline applies clicked path at clicked time --- .../gui/GuiKeyframeTimeline.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java b/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java index 02d294ab..3617fda0 100644 --- a/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java +++ b/src/main/java/com/replaymod/simplepathing/gui/GuiKeyframeTimeline.java @@ -168,19 +168,17 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline Math.abs(k.getTime() - time) <= tolerance) .sorted(Comparator.comparing(k -> Math.abs(k.getTime() - time))) .findFirst(); - if (keyframe.isPresent()) { - return Pair.of(path, keyframe.get()); - } + return Pair.of(path, keyframe.orElse(null)); } } - return null; + return Pair.of(null, null); } @Override public boolean mouseClick(ReadablePoint position, int button) { int time = getTimeAt(position.getX(), position.getY()); Pair pathKeyframePair = getKeyframe(position); - if (pathKeyframePair != null) { + if (pathKeyframePair.getRight() != null) { // Clicked on keyframe Keyframe keyframe = pathKeyframePair.getRight(); if (button == 0) { // Left click @@ -210,13 +208,31 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline k.getProperties().stream()).distinct().forEach( + p -> applyPropertyToGame(p, path, time)); + } + } return true; } // Missed timeline return false; } + // Helper method because generics cannot be defined on blocks + private void applyPropertyToGame(Property property, Path path, long time) { + Optional value = path.getValue(property, time); + if (value.isPresent()) { + property.applyToGame(value.get(), ReplayModReplay.instance.getReplayHandler()); + } + } + // Helper method because generics cannot be defined on blocks private void applyPropertyToGame(Property property, Keyframe keyframe) { Optional value = keyframe.getValue(property);