2016-11-17 05:45:04 +01:00
|
|
|
package com.minelittlepony;
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-16 07:41:36 +02:00
|
|
|
import com.google.common.base.MoreObjects;
|
2016-11-25 05:40:19 +01:00
|
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
|
|
|
2015-12-09 04:14:42 +01:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.util.Map;
|
2017-06-16 07:41:36 +02:00
|
|
|
import javax.annotation.concurrent.Immutable;
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-16 07:41:36 +02:00
|
|
|
@Immutable
|
2016-11-24 08:01:23 +01:00
|
|
|
public class PonyData implements IPonyData {
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2016-11-25 05:40:19 +01:00
|
|
|
private static final Map<Integer, PonyRace> RACE_COLORS = ImmutableBiMap.<Integer, PonyRace>builder()
|
2015-12-12 05:17:04 +01:00
|
|
|
.put(0xf9b131, PonyRace.EARTH)
|
|
|
|
.put(0xd19fe4, PonyRace.UNICORN)
|
|
|
|
.put(0x88caf0, PonyRace.PEGASUS)
|
|
|
|
.put(0xfef9fc, PonyRace.ALICORN)
|
|
|
|
.put(0xd0cccf, PonyRace.ZEBRA)
|
|
|
|
.put(0x282b29, PonyRace.CHANGELING)
|
2017-11-28 05:28:48 +01:00
|
|
|
.put(0xcaed5a, PonyRace.REFORMED_CHANGELING)
|
|
|
|
.put(0xae9145, PonyRace.GRIFFIN)
|
|
|
|
.put(0xd6ddac, PonyRace.HIPPOGRIFF)
|
2015-12-09 04:14:42 +01:00
|
|
|
.build();
|
2016-11-25 05:40:19 +01:00
|
|
|
private static final Map<Integer, TailLengths> TAIL_COLORS = ImmutableBiMap.<Integer, TailLengths>builder()
|
2015-12-12 05:17:04 +01:00
|
|
|
.put(0x425844, TailLengths.STUB)
|
|
|
|
.put(0xd19fe4, TailLengths.QUARTER)
|
|
|
|
.put(0x534b76, TailLengths.HALF)
|
|
|
|
.put(0x8a6b7f, TailLengths.THREE_QUARTERS).build();
|
2016-11-25 05:40:19 +01:00
|
|
|
private static final Map<Integer, PonySize> SIZE_COLORS = ImmutableBiMap.<Integer, PonySize>builder()
|
2015-12-12 05:17:04 +01:00
|
|
|
.put(0xffbe53, PonySize.FOAL)
|
|
|
|
.put(0xce3254, PonySize.LARGE)
|
2015-12-16 05:29:47 +01:00
|
|
|
.put(0x534b76, PonySize.TALL)
|
2015-12-09 04:14:42 +01:00
|
|
|
.build();
|
|
|
|
|
2017-06-16 07:41:36 +02:00
|
|
|
private final PonyRace race;
|
|
|
|
private final TailLengths tailSize;
|
|
|
|
private final PonyGender gender;
|
|
|
|
private final PonySize size;
|
|
|
|
private final int glowColor;
|
2017-06-13 05:55:50 +02:00
|
|
|
|
|
|
|
public PonyData() {
|
|
|
|
this(PonyRace.HUMAN, TailLengths.FULL, PonyGender.MARE, PonySize.NORMAL, 0x4444aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
private PonyData(PonyRace race, TailLengths tailSize, PonyGender gender, PonySize size, int glowColor) {
|
|
|
|
this.race = race;
|
|
|
|
this.tailSize = tailSize;
|
|
|
|
this.gender = gender;
|
|
|
|
this.size = size;
|
|
|
|
this.glowColor = glowColor;
|
|
|
|
}
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2015-12-09 04:14:42 +01:00
|
|
|
public PonyRace getRace() {
|
|
|
|
return race;
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2015-12-09 04:14:42 +01:00
|
|
|
public TailLengths getTail() {
|
|
|
|
return tailSize;
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2015-12-09 04:14:42 +01:00
|
|
|
public PonyGender getGender() {
|
|
|
|
return gender;
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2015-12-09 04:14:42 +01:00
|
|
|
public PonySize getSize() {
|
2016-01-26 09:16:11 +01:00
|
|
|
return MineLittlePony.getConfig().sizes ? size : PonySize.NORMAL;
|
2015-12-09 04:14:42 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2015-12-09 04:14:42 +01:00
|
|
|
public int getGlowColor() {
|
|
|
|
return glowColor;
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
@Override
|
2016-05-22 05:56:50 +02:00
|
|
|
public boolean hasMagic() {
|
|
|
|
return this.race != null && this.race.hasHorn() && this.glowColor != 0;
|
|
|
|
}
|
|
|
|
|
2017-06-16 07:41:36 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return MoreObjects.toStringHelper(this)
|
|
|
|
.add("race", race)
|
|
|
|
.add("tailSize", tailSize)
|
|
|
|
.add("gender", gender)
|
|
|
|
.add("size", size)
|
|
|
|
.add("glowColor", "#" + Integer.toHexString(glowColor))
|
|
|
|
.toString();
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:55:32 +02:00
|
|
|
static IPonyData parse(BufferedImage image) {
|
2017-06-13 05:55:50 +02:00
|
|
|
int racePx = TriggerPixels.RACE.readColor(image);
|
|
|
|
PonyRace race = RACE_COLORS.getOrDefault(racePx, PonyRace.HUMAN);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
int tailPx = TriggerPixels.TAIL.readColor(image);
|
|
|
|
TailLengths tail = TAIL_COLORS.getOrDefault(tailPx, TailLengths.FULL);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
int sizePx = TriggerPixels.SIZE.readColor(image);
|
|
|
|
PonySize size = SIZE_COLORS.getOrDefault(sizePx, PonySize.NORMAL);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
int genderPx = TriggerPixels.GENDER.readColor(image);
|
|
|
|
PonyGender gender = genderPx == 0xffffff ? PonyGender.STALLION : PonyGender.MARE;
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
int glowColor = TriggerPixels.GLOW.readColor(image, -1);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
2017-06-13 05:55:50 +02:00
|
|
|
return new PonyData(race, tail, gender, size, glowColor);
|
2015-12-09 04:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private enum TriggerPixels {
|
|
|
|
RACE(0, 0),
|
2015-12-12 05:17:04 +01:00
|
|
|
TAIL(1, 0),
|
|
|
|
GENDER(2, 0),
|
|
|
|
SIZE(3, 0),
|
|
|
|
GLOW(0, 1);
|
2015-12-09 04:14:42 +01:00
|
|
|
|
|
|
|
private int x, y;
|
|
|
|
|
2016-11-24 08:01:23 +01:00
|
|
|
TriggerPixels(int x, int y) {
|
2015-12-09 04:14:42 +01:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int readColor(BufferedImage image) {
|
2017-06-13 05:55:50 +02:00
|
|
|
return readColor(image, 0xffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int readColor(BufferedImage image, int mask) {
|
|
|
|
return image.getRGB(x, y) & mask;
|
2015-12-09 04:14:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|