2018-04-25 13:00:18 +02:00
|
|
|
package com.minelittlepony.pony.data;
|
|
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Individual trigger pixels for a pony skin.
|
|
|
|
*
|
|
|
|
*/
|
2018-04-29 14:20:13 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2018-04-25 13:00:18 +02:00
|
|
|
public enum TriggerPixels {
|
2018-04-29 14:37:51 +02:00
|
|
|
RACE(PonyRace.HUMAN, Channel.ALL, 0, 0),
|
|
|
|
TAIL(TailLengths.FULL, Channel.ALL, 1, 0),
|
|
|
|
GENDER(PonyGender.MARE, Channel.ALL, 2, 0),
|
|
|
|
SIZE(PonySize.NORMAL, Channel.ALL, 3, 0),
|
|
|
|
GLOW(null, Channel.RAW, 0, 1);
|
2018-04-25 13:00:18 +02:00
|
|
|
|
2018-04-26 23:53:03 +02:00
|
|
|
private int x;
|
|
|
|
private int y;
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-29 14:37:51 +02:00
|
|
|
private Channel channel;
|
|
|
|
|
2018-04-25 13:00:18 +02:00
|
|
|
ITriggerPixelMapped<?> def;
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-29 14:37:51 +02:00
|
|
|
TriggerPixels(ITriggerPixelMapped<?> def, Channel channel, int x, int y) {
|
2018-04-25 13:00:18 +02:00
|
|
|
this.def = def;
|
2018-04-29 14:37:51 +02:00
|
|
|
this.channel = channel;
|
2018-04-25 13:00:18 +02:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
2018-04-27 13:49:33 +02:00
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
2018-04-29 14:20:13 +02:00
|
|
|
* Reads this trigger pixel's value and returns the raw colour.
|
|
|
|
*
|
2018-04-25 21:29:49 +02:00
|
|
|
* @param image Image to read
|
|
|
|
*/
|
2018-04-29 14:37:51 +02:00
|
|
|
public int readColor(BufferedImage image) {
|
|
|
|
return channel.readValue(x, y, image);
|
2018-04-25 13:00:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Reads this trigger pixel's value and parses it to an Enum instance.
|
2018-04-27 13:49:33 +02:00
|
|
|
*
|
2018-04-25 21:29:49 +02:00
|
|
|
* @param image Image to read
|
|
|
|
*/
|
2018-04-25 13:00:18 +02:00
|
|
|
public <T extends Enum<T> & ITriggerPixelMapped<T>> T readValue(BufferedImage image) {
|
2018-04-29 14:37:51 +02:00
|
|
|
return ITriggerPixelMapped.getByTriggerPixel((T)def, readColor(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Channel {
|
|
|
|
RAW(-1, 0),
|
|
|
|
ALL(0xffffff, 0),
|
|
|
|
RED(0xff0000, 16),
|
|
|
|
GREEN(0x00ff00, 8),
|
|
|
|
BLUE(0x0000ff, 0);
|
|
|
|
|
|
|
|
private int mask;
|
|
|
|
private int offset;
|
|
|
|
|
|
|
|
Channel(int mask, int offset) {
|
|
|
|
this.mask = mask;
|
|
|
|
this.offset = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int readValue(int x, int y, BufferedImage image) {
|
|
|
|
return (image.getRGB(x, y) & mask) >> offset;
|
|
|
|
}
|
2018-04-25 13:00:18 +02:00
|
|
|
}
|
|
|
|
}
|