Created CameraPathValidator to validate Camera Paths before playing them and uses its static validateCameraPath() method whenever a Camera Path is to be started
Camera Paths can't start if negative movement through time would be required
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package eu.crushedpixel.replaymod.utils;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeList;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public class CameraPathValidator {
|
||||
|
||||
public static class InvalidCameraPathException extends Exception {
|
||||
public InvalidCameraPathException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return I18n.format(getMessage());
|
||||
}
|
||||
|
||||
public void printToChat() {
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage(getMessage(), ChatMessageHandler.ChatMessageType.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateCameraPath(KeyframeList<AdvancedPosition> positionKeyframes, KeyframeList<TimestampValue> timeKeyframes)
|
||||
throws InvalidCameraPathException {
|
||||
|
||||
if(positionKeyframes.size() < 2 || timeKeyframes.size() < 2) {
|
||||
throw new InvalidCameraPathException("replaymod.chat.morekeyframes");
|
||||
}
|
||||
|
||||
int previousTimestamp = -1;
|
||||
for(Keyframe<TimestampValue> timeKeyframe : timeKeyframes) {
|
||||
if(timeKeyframe.getValue().asInt() < previousTimestamp) throw new InvalidCameraPathException("replaymod.chat.negativetime");
|
||||
previousTimestamp = timeKeyframe.getValue().asInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user