Skip to content

Commit

Permalink
Merge pull request #216 from lushen124/bugfix/0165-fix-palettes-again
Browse files Browse the repository at this point in the history
[Issue #165] Fixing palettes. Again.
  • Loading branch information
lushen124 committed Mar 17, 2020
2 parents 203883e + 600a023 commit 63c73eb
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 116 deletions.
6 changes: 3 additions & 3 deletions Universal FE Randomizer/src/fedata/gba/fe8/FE8Data.java
Expand Up @@ -2114,13 +2114,13 @@ private Palette(int paletteID, int charID, int classID, long offset) {
this.info = new PaletteInfo(classID, charID, offset, new int[] {6, 7, 8}, new int[] {9, 10, 11}, new int[] {12, 13, 14});
break;
case EIRIKA_MASTER_LORD:
this.info = new PaletteInfo(classID, charID, offset, new int[] {5, 6, 7, 8}, new int[] {9, 10, 11}, new int[] {12, 13, 14});
this.info = new PaletteInfo(classID, charID, offset, new int[] {5, 6, 7}, new int[] {9, 10, 11}, new int[] {12, 13, 14});
break;
case EPHRAIM_LORD:
this.info = new PaletteInfo(classID, charID, offset, new int[] {6, 7, 8}, new int[] {}, new int[] {9, 10}, new int[] {12, 13, 14});
break;
case EPHRAIM_MASTER_LORD:
this.info = new PaletteInfo(classID, charID, offset, new int[] {5, 6, 7}, new int[] {}, new int[] {8, 9}, new int[] {13, 14});
this.info = new PaletteInfo(classID, charID, offset, new int[] {5, 6, 7}, new int[] {}, new int[] {9, 10}, new int[] {});
break;
case TRAINEE:
case TRAINEE_2:
Expand Down Expand Up @@ -2220,7 +2220,7 @@ private Palette(int paletteID, int charID, int classID, long offset) {
this.info = new PaletteInfo(classID, charID, offset, new int[] {6, 7}, new int[] {8, 3, 9, 5, 10, 11}, new int[] {});
break;
case PALADIN:
this.info = new PaletteInfo(classID, charID, offset, new int[] {}, new int[] {8, 9, 10, 11}, new int[] {7}, new int[] {5, 3, 4}); // Secondary is shield (which is blended with white). Tertiary is mane + shield crest.
this.info = new PaletteInfo(classID, charID, offset, new int[] {}, new int[] {8, 9, 10, 11}, new int[] {6, 7}, new int[] {5, 3, 4}); // Secondary is shield (which is blended with white). Tertiary is mane + shield crest.
break;
case PALADIN_F:
this.info = new PaletteInfo(classID, charID, offset, new int[] {6, 7}, new int[] {8, 9, 10}, new int[] {5, 3, 4}); // Hair also affects shield. Secondary is mane + shield crest.
Expand Down
35 changes: 18 additions & 17 deletions Universal FE Randomizer/src/fedata/gba/general/PaletteColor.java
Expand Up @@ -73,34 +73,35 @@ public String toHexString() {

public static PaletteColor[] coerceColors(PaletteColor[] colors, int numberOfColors) {
if (numberOfColors == 0) { return new PaletteColor[] {}; }
if (colors.length == numberOfColors) { return colors; }
else if (colors.length > numberOfColors) {
// Remove dupes first, if any.
List<PaletteColor> colorsArray = new ArrayList<PaletteColor>();
Set<String> uniqueColors = new HashSet<String>();
for (PaletteColor color : colors) {
if (uniqueColors.contains(color.toHexString())) { continue; }
uniqueColors.add(color.toHexString());
colorsArray.add(color);
}


// Remove dupes first, if any.
List<PaletteColor> colorsArray = new ArrayList<PaletteColor>();
Set<String> uniqueColors = new HashSet<String>();
for (PaletteColor color : colors) {
if (uniqueColors.contains(color.toHexString())) { continue; }
uniqueColors.add(color.toHexString());
colorsArray.add(color);
}

if (colorsArray.size() == numberOfColors) { return colorsArray.toArray(new PaletteColor[colorsArray.size()]); }
else if (colorsArray.size() > numberOfColors) {
PaletteColor[] uniqueColorArray = colorsArray.toArray(new PaletteColor[colorsArray.size()]);
if (colorsArray.size() == numberOfColors) { return uniqueColorArray; }
else if (colorsArray.size() > numberOfColors) { return reduceColors(uniqueColorArray, numberOfColors); }
else {
if (colorsArray.isEmpty()) { return new PaletteColor[] {}; }
else if (colorsArray.size() == 1) {
if (colors[0].brightness > 0.5) { return interpolateColors(new PaletteColor[] {colors[0], darkerColor(colors[0])}, numberOfColors); }
else { return interpolateColors(new PaletteColor[] {lighterColor(colors[0]), colors[0]}, numberOfColors); }
if (colorsArray.get(0).brightness > 0.5) { return interpolateColors(new PaletteColor[] {colorsArray.get(0), darkerColor(colorsArray.get(0))}, numberOfColors); }
else { return interpolateColors(new PaletteColor[] {lighterColor(colorsArray.get(0)), colorsArray.get(0)}, numberOfColors); }
} else { return interpolateColors(uniqueColorArray, numberOfColors); }
}
}
else { // (colors.length < numberOfColors)
if (colors.length == 1) {
if (colors[0].brightness > 0.5) { return interpolateColors(new PaletteColor[] {colors[0], darkerColor(colors[0])}, numberOfColors); }
else { return interpolateColors(new PaletteColor[] {lighterColor(colors[0]), colors[0]}, numberOfColors); }
if (colorsArray.size() == 1) {
if (colorsArray.get(0).brightness > 0.5) { return interpolateColors(new PaletteColor[] {colorsArray.get(0), darkerColor(colorsArray.get(0))}, numberOfColors); }
else { return interpolateColors(new PaletteColor[] {lighterColor(colorsArray.get(0)), colorsArray.get(0)}, numberOfColors); }
}
else { return interpolateColors(colors, numberOfColors); }
else { return interpolateColors(colorsArray.toArray(new PaletteColor[colorsArray.size()]), numberOfColors); }
}
}

Expand Down
12 changes: 12 additions & 0 deletions Universal FE Randomizer/src/fedata/gba/general/PaletteV2.java
Expand Up @@ -103,6 +103,18 @@ public PaletteV2(PaletteV2 other) {
identifier = other.identifier;
}

public int getNumColors() {
return 16;
}

public PaletteColor colorAtIndex(int index, PaletteType type) {
return colorArray[index].getColor(type);
}

public int getClassID() {
return info.classID;
}

public void overrideOffset(long newOffset) {
destinationOffset = newOffset;
}
Expand Down

0 comments on commit 63c73eb

Please sign in to comment.