Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #165] Fixing palettes. Again. #216

Merged
merged 1 commit into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Universal FE Randomizer/src/fedata/gba/fe8/FE8Data.java
Expand Up @@ -2106,13 +2106,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 @@ -2212,7 +2212,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