Fix loading and storing of default interpolator with settings
This commit is contained in:
@@ -5,7 +5,6 @@ import com.google.common.collect.Iterables;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import com.replaymod.pathing.properties.CameraProperties;
|
import com.replaymod.pathing.properties.CameraProperties;
|
||||||
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
|
||||||
import com.replaymod.pathing.properties.SpectatorProperty;
|
import com.replaymod.pathing.properties.SpectatorProperty;
|
||||||
import com.replaymod.pathing.properties.TimestampProperty;
|
import com.replaymod.pathing.properties.TimestampProperty;
|
||||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||||
@@ -25,6 +24,7 @@ import com.replaymod.replaystudio.pathing.path.Timeline;
|
|||||||
import com.replaymod.replaystudio.pathing.property.Property;
|
import com.replaymod.replaystudio.pathing.property.Property;
|
||||||
import com.replaymod.replaystudio.util.EntityPositionTracker;
|
import com.replaymod.replaystudio.util.EntityPositionTracker;
|
||||||
import com.replaymod.replaystudio.util.Location;
|
import com.replaymod.replaystudio.util.Location;
|
||||||
|
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.crash.CrashReport;
|
import net.minecraft.crash.CrashReport;
|
||||||
import net.minecraft.crash.CrashReportCategory;
|
import net.minecraft.crash.CrashReportCategory;
|
||||||
@@ -108,6 +108,26 @@ public class SPTimeline implements PathingRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Change setDefaultInterpolator(Interpolator interpolator) {
|
||||||
|
Preconditions.checkState(defaultInterpolatorType != null, "Default interpolator type not set.");
|
||||||
|
Validate.isInstanceOf(defaultInterpolatorType.getInterpolatorClass(), interpolator);
|
||||||
|
|
||||||
|
registerPositionInterpolatorProperties(interpolator);
|
||||||
|
|
||||||
|
Change change = CombinedChange.create(
|
||||||
|
positionPath.getSegments().stream()
|
||||||
|
// Ignore explicitly set segments
|
||||||
|
.filter(s -> !s.getStartKeyframe().getValue(ExplicitInterpolationProperty.PROPERTY).isPresent())
|
||||||
|
// Ignore spectator segments
|
||||||
|
.filter(s -> !isSpectatorSegment(s))
|
||||||
|
// Update interpolator for every remaining segment
|
||||||
|
// This will create a fragmented interpolator which is split by the updateInterpolators call
|
||||||
|
.map(s -> SetInterpolator.create(s, interpolator)).toArray(Change[]::new)
|
||||||
|
);
|
||||||
|
change.apply(timeline);
|
||||||
|
return CombinedChange.createFromApplied(change, updateInterpolators());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTimeKeyframe(long time) {
|
public boolean isTimeKeyframe(long time) {
|
||||||
return timePath.getKeyframe(time) != null;
|
return timePath.getKeyframe(time) != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.replaymod.simplepathing.gui;
|
package com.replaymod.simplepathing.gui;
|
||||||
|
|
||||||
import com.replaymod.pathing.properties.CameraProperties;
|
import com.replaymod.pathing.properties.CameraProperties;
|
||||||
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
|
||||||
import com.replaymod.pathing.properties.TimestampProperty;
|
import com.replaymod.pathing.properties.TimestampProperty;
|
||||||
import com.replaymod.replay.ReplayModReplay;
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
import com.replaymod.replaystudio.pathing.change.Change;
|
import com.replaymod.replaystudio.pathing.change.Change;
|
||||||
@@ -16,6 +15,7 @@ import com.replaymod.simplepathing.InterpolatorType;
|
|||||||
import com.replaymod.simplepathing.SPTimeline;
|
import com.replaymod.simplepathing.SPTimeline;
|
||||||
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
import com.replaymod.simplepathing.SPTimeline.SPPath;
|
||||||
import com.replaymod.simplepathing.Setting;
|
import com.replaymod.simplepathing.Setting;
|
||||||
|
import com.replaymod.simplepathing.properties.ExplicitInterpolationProperty;
|
||||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||||
@@ -251,10 +251,11 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
|||||||
xField.getDouble(), yField.getDouble(), zField.getDouble(),
|
xField.getDouble(), yField.getDouble(), zField.getDouble(),
|
||||||
yawField.getFloat(), pitchField.getFloat(), rollField.getFloat()
|
yawField.getFloat(), pitchField.getFloat(), rollField.getFloat()
|
||||||
);
|
);
|
||||||
if (interpolationPanel.getInterpolatorType() == InterpolatorType.DEFAULT) {
|
|
||||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolatorToDefault(time));
|
|
||||||
} else {
|
|
||||||
Interpolator interpolator = interpolationPanel.getSettingsPanel().createInterpolator();
|
Interpolator interpolator = interpolationPanel.getSettingsPanel().createInterpolator();
|
||||||
|
if (interpolationPanel.getInterpolatorType() == InterpolatorType.DEFAULT) {
|
||||||
|
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolatorToDefault(time),
|
||||||
|
timeline.setDefaultInterpolator(interpolator));
|
||||||
|
} else {
|
||||||
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolator(time, interpolator));
|
return CombinedChange.createFromApplied(positionChange, timeline.setInterpolator(time, interpolator));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,13 +296,17 @@ public abstract class GuiEditKeyframe<T extends GuiEditKeyframe<T>> extends Abst
|
|||||||
Optional<PathSegment> segment = path.getSegments().stream()
|
Optional<PathSegment> segment = path.getSegments().stream()
|
||||||
.filter(s -> s.getStartKeyframe() == keyframe).findFirst();
|
.filter(s -> s.getStartKeyframe() == keyframe).findFirst();
|
||||||
if (segment.isPresent()) {
|
if (segment.isPresent()) {
|
||||||
if (keyframe.getValue(ExplicitInterpolationProperty.PROPERTY).isPresent()) {
|
|
||||||
Interpolator interpolator = segment.get().getInterpolator();
|
Interpolator interpolator = segment.get().getInterpolator();
|
||||||
InterpolatorType type = InterpolatorType.fromClass(interpolator.getClass());
|
InterpolatorType type = InterpolatorType.fromClass(interpolator.getClass());
|
||||||
|
if (keyframe.getValue(ExplicitInterpolationProperty.PROPERTY).isPresent()) {
|
||||||
dropdown.setSelected(type); // trigger the callback once to display settings panel
|
dropdown.setSelected(type); // trigger the callback once to display settings panel
|
||||||
} else {
|
} else {
|
||||||
setSettingsPanel(InterpolatorType.DEFAULT);
|
setSettingsPanel(InterpolatorType.DEFAULT);
|
||||||
}
|
}
|
||||||
|
if (getInterpolatorTypeNoDefault(type).getInterpolatorClass().isInstance(interpolator)) {
|
||||||
|
//noinspection unchecked
|
||||||
|
settingsPanel.loadSettings(interpolator);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Disable dropdown if this is the last keyframe
|
// Disable dropdown if this is the last keyframe
|
||||||
dropdown.setDisabled();
|
dropdown.setDisabled();
|
||||||
|
|||||||
Reference in New Issue
Block a user