Added ReflectionUtils helper class to find Fields with @Interpolate annotation in superclasses (Interpolators didn't account for Fields in AdvancedPosition inherited by Position)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package eu.crushedpixel.replaymod.interpolation;
|
||||
|
||||
import eu.crushedpixel.replaymod.utils.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,12 +22,7 @@ public class GenericLinearInterpolation<T extends KeyframeValue> implements Inte
|
||||
public void addPoint(T point) {
|
||||
points.add(point);
|
||||
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
for(Field f : point.getClass().getDeclaredFields()) {
|
||||
if(f.isAnnotationPresent(Interpolate.class)) {
|
||||
fields.add(f);
|
||||
}
|
||||
}
|
||||
List<Field> fields = ReflectionUtils.getFieldsToInterpolate(point.getClass());
|
||||
this.fields = fields.toArray(new Field[fields.size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package eu.crushedpixel.replaymod.interpolation;
|
||||
|
||||
import eu.crushedpixel.replaymod.utils.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -19,12 +20,7 @@ public class GenericSplineInterpolation<T extends KeyframeValue> extends BasicSp
|
||||
public void addPoint(T point) {
|
||||
this.points.add(point);
|
||||
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
for(Field f : point.getClass().getDeclaredFields()) {
|
||||
if(f.isAnnotationPresent(Interpolate.class)) {
|
||||
fields.add(f);
|
||||
}
|
||||
}
|
||||
List<Field> fields = ReflectionUtils.getFieldsToInterpolate(point.getClass());
|
||||
this.fields = fields.toArray(new Field[fields.size()]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.crushedpixel.replaymod.utils;
|
||||
|
||||
import eu.crushedpixel.replaymod.interpolation.Interpolate;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReflectionUtils {
|
||||
|
||||
public static List<Field> getFieldsToInterpolate(Class clazz) {
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
for(Field f : clazz.getDeclaredFields()) {
|
||||
if(f.isAnnotationPresent(Interpolate.class)) fields.add(f);
|
||||
}
|
||||
|
||||
if(clazz.getSuperclass() != Object.class) {
|
||||
fields.addAll(getFieldsToInterpolate(clazz.getSuperclass()));
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user