Added recalculate() method to KeyframeList to recalc the underlying Interpolation
Recalculate Keyframe Lists in ReplayHandler upon firing a KeyframesModifyEvent
This commit is contained in:
@@ -30,8 +30,13 @@ public class GenericLinearInterpolation<T extends KeyframeValue> implements Inte
|
||||
|
||||
@Override
|
||||
public void applyPoint(float position, T toEdit) {
|
||||
if(points.isEmpty()) {
|
||||
throw new IllegalStateException("At least one Value needs to be added for this operation");
|
||||
if(fields == null) {
|
||||
throw new IllegalStateException("At least one Keyframe has to be added before preparing");
|
||||
}
|
||||
|
||||
if(fields.length <= 0) {
|
||||
throw new IllegalStateException("The passed KeyframeValue class" +
|
||||
" has to contain at least one Field");
|
||||
}
|
||||
|
||||
//first, get previous and next T for given position
|
||||
|
||||
@@ -30,10 +30,15 @@ public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSp
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
if(fields == null) {
|
||||
throw new IllegalStateException("At least one Keyframe has to be added before preparing");
|
||||
}
|
||||
|
||||
if(fields.length <= 0) {
|
||||
throw new IllegalStateException("The passed KeyframeValue class" +
|
||||
" has to contain at least one Field");
|
||||
}
|
||||
|
||||
if(!points.isEmpty()) {
|
||||
cubics = new ArrayList<Vector<Cubic>>(fields.length);
|
||||
for (Field field : fields) {
|
||||
|
||||
@@ -153,15 +153,7 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
|
||||
K toApply = (K) first().getValue().newInstance();
|
||||
|
||||
if(previousCallLinear != (Boolean)linear) {
|
||||
previousCallLinear = linear;
|
||||
|
||||
interpolation = linear ? new GenericLinearInterpolation<K>() : new GenericSplineInterpolation<K>();
|
||||
|
||||
for(Keyframe<K> keyframe : this) {
|
||||
interpolation.addPoint(keyframe.getValue());
|
||||
}
|
||||
|
||||
interpolation.prepare();
|
||||
recalculate(linear);
|
||||
}
|
||||
|
||||
interpolation.applyPoint(pathPosition, toApply);
|
||||
@@ -169,6 +161,24 @@ public class KeyframeList<K extends KeyframeValue> extends ArrayList<Keyframe<K>
|
||||
return toApply;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the underlying Interpolation instances.
|
||||
* @param linear Whether to prepare linear or cubic interpolation
|
||||
*/
|
||||
public void recalculate(boolean linear) {
|
||||
previousCallLinear = linear;
|
||||
|
||||
if(isEmpty()) return;
|
||||
|
||||
interpolation = linear ? new GenericLinearInterpolation<K>() : new GenericSplineInterpolation<K>();
|
||||
|
||||
for(Keyframe<K> keyframe : this) {
|
||||
interpolation.addPoint(keyframe.getValue());
|
||||
}
|
||||
|
||||
interpolation.prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value between 0 and 1, representing the number that should be passed
|
||||
* to Interpolation#getValue() calls on this list of Keyframes.
|
||||
|
||||
@@ -579,6 +579,7 @@ public class ReplayHandler {
|
||||
|
||||
public static void fireKeyframesModifyEvent() {
|
||||
FMLCommonHandler.instance().bus().post(new KeyframesModifyEvent(positionKeyframes, timeKeyframes));
|
||||
|
||||
positionKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement());
|
||||
timeKeyframes.recalculate(ReplayMod.replaySettings.isLinearMovement());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user