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:
CrushedPixel
2015-07-13 15:47:57 +02:00
parent 9d2c371398
commit 3f12019288
5 changed files with 65 additions and 13 deletions

View File

@@ -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();
}
}
}