2018-04-25 13:00:18 +02:00
|
|
|
package com.minelittlepony.pony.data;
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Interface for enums that can be parsed from an image trigger pixel value.
|
|
|
|
* @author Chris Albers
|
|
|
|
*
|
|
|
|
* @param <T>
|
|
|
|
*/
|
2018-04-25 13:00:18 +02:00
|
|
|
public interface ITriggerPixelMapped<T extends Enum<T> & ITriggerPixelMapped<T>> {
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Gets the pixel colour matching this enum value.
|
|
|
|
*/
|
2018-04-25 13:00:18 +02:00
|
|
|
int getTriggerPixel();
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Gets the enum value corresponding to the given enum type and pixel value.
|
|
|
|
* If none are found, the first parameter is returned as the default.
|
2018-04-27 13:49:33 +02:00
|
|
|
*
|
2018-04-25 21:29:49 +02:00
|
|
|
* @param type Return type and default value.
|
|
|
|
* @param pixelValue The pixel colour to search for.
|
|
|
|
*/
|
2018-04-25 13:00:18 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static <T extends Enum<T> & ITriggerPixelMapped<T>> T getByTriggerPixel(T type, int pixelValue) {
|
|
|
|
for (T i : (T[])type.getClass().getEnumConstants()) {
|
|
|
|
if (i.getTriggerPixel() == pixelValue) return i;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|