Skip to content

Commit

Permalink
Merge pull request #497 from MelnCat/feat/quality-icons
Browse files Browse the repository at this point in the history
Add icons to display quality
  • Loading branch information
Sn0wStorm authored Oct 30, 2023
2 parents bb4e6d4 + 5c56554 commit 1665047
Showing 1 changed file with 65 additions and 15 deletions.
80 changes: 65 additions & 15 deletions src/com/dre/brewery/lore/BrewLore.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public void addCauldronLore(List<String> l) {
*/
public void updateIngredientLore(boolean qualityColor) {
if (qualityColor && brew.hasRecipe() && !brew.isStripped()) {
String prefix = getQualityColor(brew.getIngredients().getIngredientQuality(brew.getCurrentRecipe()));
addOrReplaceLore(Type.INGR, prefix, P.p.languageReader.get("Brew_Ingredients"));
int quality = brew.getIngredients().getIngredientQuality(brew.getCurrentRecipe());
String prefix = getQualityColor(quality);
char icon = getQualityIcon(quality);
addOrReplaceLore(Type.INGR, prefix, P.p.languageReader.get("Brew_Ingredients"), " " + icon);
} else {
removeLore(Type.INGR, P.p.languageReader.get("Brew_Ingredients"));
}
Expand All @@ -132,7 +134,7 @@ public void updateCookLore(boolean qualityColor) {
if (ingredients.getCookedTime() > 1) {
prefix = prefix + P.p.languageReader.get("Brew_MinutePluralPostfix");
}
addOrReplaceLore(Type.COOK, prefix, " " + P.p.languageReader.get("Brew_fermented"));
addOrReplaceLore(Type.COOK, prefix, " " + P.p.languageReader.get("Brew_fermented"), " " + getQualityIcon(quality));
} else {
removeLore(Type.COOK, P.p.languageReader.get("Brew_fermented"));
}
Expand All @@ -147,8 +149,9 @@ public void updateDistillLore(boolean qualityColor) {
if (brew.getDistillRuns() <= 0) return;
String prefix;
byte distillRuns = brew.getDistillRuns();
int quality = brew.getIngredients().getDistillQuality(brew.getCurrentRecipe(), distillRuns);
if (qualityColor && !brew.isUnlabeled() && brew.hasRecipe()) {
prefix = getQualityColor(brew.getIngredients().getDistillQuality(brew.getCurrentRecipe(), distillRuns));
prefix = getQualityColor(quality);
} else {
prefix = "§7";
}
Expand All @@ -158,9 +161,9 @@ public void updateDistillLore(boolean qualityColor) {
}
}
if (brew.isUnlabeled() && brew.hasRecipe() && distillRuns < brew.getCurrentRecipe().getDistillRuns()) {
addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_LessDistilled"));
addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_LessDistilled"), " " + getQualityIcon(quality));
} else {
addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_Distilled"));
addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_Distilled"), " " + getQualityIcon(quality));
}
}

Expand All @@ -173,8 +176,9 @@ public void updateAgeLore(boolean qualityColor) {
if (brew.isStripped()) return;
String prefix;
float age = brew.getAgeTime();
int quality = brew.getIngredients().getAgeQuality(brew.getCurrentRecipe(), age);
if (qualityColor && !brew.isUnlabeled() && brew.hasRecipe()) {
prefix = getQualityColor(brew.getIngredients().getAgeQuality(brew.getCurrentRecipe(), age));
prefix = getQualityColor(quality);
} else {
prefix = "§7";
}
Expand All @@ -187,7 +191,7 @@ public void updateAgeLore(boolean qualityColor) {
prefix = prefix + P.p.languageReader.get("Brew_HundredsOfYears") + " ";
}
}
addOrReplaceLore(Type.AGE, prefix, P.p.languageReader.get("Brew_BarrelRiped"));
addOrReplaceLore(Type.AGE, prefix, P.p.languageReader.get("Brew_BarrelRiped"), " " + getQualityIcon(quality));
}

/**
Expand All @@ -198,7 +202,7 @@ public void updateAgeLore(boolean qualityColor) {
public void updateWoodLore(boolean qualityColor) {
if (qualityColor && brew.hasRecipe() && !brew.isUnlabeled()) {
int quality = brew.getIngredients().getWoodQuality(brew.getCurrentRecipe(), brew.getWood());
addOrReplaceLore(Type.WOOD, getQualityColor(quality), P.p.languageReader.get("Brew_Woodtype"));
addOrReplaceLore(Type.WOOD, getQualityColor(quality), P.p.languageReader.get("Brew_Woodtype"), " " + getQualityIcon(quality));
} else {
removeLore(Type.WOOD, P.p.languageReader.get("Brew_Woodtype"));
}
Expand Down Expand Up @@ -326,11 +330,24 @@ public void convertLore(boolean toQuality) {
* @param type The Type of BrewLore to replace
* @param prefix The Prefix to add to the line of lore
* @param line The Line of Lore to add or replace
*/
*/
public int addOrReplaceLore(Type type, String prefix, String line) {
return addOrReplaceLore(type, prefix, line, "");
}

/**
* Adds or replaces a line of Lore.
* <p>Searches for type and if not found for Substring lore and replaces it
*
* @param type The Type of BrewLore to replace
* @param prefix The Prefix to add to the line of lore
* @param line The Line of Lore to add or replace
* @param suffix The Suffix to add to the line of lore
*/
public int addOrReplaceLore(Type type, String prefix, String line, String suffix) {
int index = type.findInLore(lore);
if (index > -1) {
lore.set(index, type.id + prefix + line);
lore.set(index, type.id + prefix + line + suffix);
return index;
}

Expand All @@ -339,7 +356,7 @@ public int addOrReplaceLore(Type type, String prefix, String line) {
if (index > -1) {
lore.remove(index);
}
return addLore(type, prefix, line);
return addLore(type, prefix, line, suffix);
}

/**
Expand All @@ -348,17 +365,28 @@ public int addOrReplaceLore(Type type, String prefix, String line) {
* @param type The Type of BrewLore to add
* @param prefix The Prefix to add to the line of lore
* @param line The Line of Lore to add or add
*/
*/
public int addLore(Type type, String prefix, String line) {
return addLore(type, prefix, line, "");
}
/**
* Adds a line of Lore in the correct ordering
*
* @param type The Type of BrewLore to add
* @param prefix The Prefix to add to the line of lore
* @param line The Line of Lore to add or add
* @param suffix The Suffix to add to the line of lore
*/
public int addLore(Type type, String prefix, String line, String suffix) {
lineAddedOrRem = true;
for (int i = 0; i < lore.size(); i++) {
Type existing = Type.get(lore.get(i));
if (existing != null && existing.isAfter(type)) {
lore.add(i, type.id + prefix + line);
lore.add(i, type.id + prefix + line + suffix);
return i;
}
}
lore.add(type.id + prefix + line);
lore.add(type.id + prefix + line + suffix);
return lore.size() - 1;
}

Expand Down Expand Up @@ -510,6 +538,28 @@ public static String getQualityColor(int quality) {
return P.p.color(color);
}

/**
* Gets the icon representing a quality for use in lore
*
* @param quality The quality used for the icon
* @return The icon for the given quality
*/
public static char getQualityIcon(int quality) {
char icon;
if (quality > 8) {
icon = '\u2605';
} else if (quality > 6) {
icon = '\u2BEA';
} else if (quality > 4) {
icon = '\u2606';
} else if (quality > 2) {
icon = '\u2718';
} else {
icon = '\u2620';
}
return icon;
}

/**
* Type of Lore Line
*/
Expand Down

0 comments on commit 1665047

Please sign in to comment.