Skip to content

Commit

Permalink
Fixing heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
UltraFaceguy committed Jul 11, 2021
1 parent 77e38ea commit d503904
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/main/java/land/face/strife/data/champion/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import land.face.strife.StrifePlugin;
import land.face.strife.data.CombatDetailsContainer;
import land.face.strife.managers.StatUpdateManager;
import land.face.strife.stats.StrifeStat;
import land.face.strife.stats.StrifeTrait;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

public class Champion {
Expand Down Expand Up @@ -116,10 +118,10 @@ public int getPendingLevel(StrifeAttribute stat) {
}

public void buildAttributeHeatmap() {
float red = 0;
float yellow = 0;
float green = 0;
float blue = 0;
int red = 0;
int yellow = 0;
int green = 0;
int blue = 0;
for (StrifeAttribute attribute : getLevelMap().keySet()) {
switch (attribute.getKey()) {
case "str":
Expand All @@ -136,15 +138,27 @@ public void buildAttributeHeatmap() {
break;
}
}
float total = red + yellow + green + blue;
red = red / total;
yellow = yellow / total;
green = green / total;
blue = blue / total;
attributeHeatmap = IntStream.range(0, (int) (red * 8)).mapToObj(i -> "⬤").toString() +
IntStream.range(0, (int) (yellow * 8)).mapToObj(i -> "⬤") +
IntStream.range(0, (int) (green * 8)).mapToObj(i -> "⬤") +
IntStream.range(0, (int) (blue * 8)).mapToObj(i -> "⬤");
float total = Math.max(1, red + yellow + green + blue);
int segments = 40 - player.getName().length();

int redSegments = (int) Math.ceil((float) segments * (float) red / total);
total -= red;
segments -= redSegments;

int yellowSegments = (int) Math.floor((float) segments * (float) yellow / total);
total -= yellow;
segments -= yellowSegments;

int greenSegments = (int) Math.ceil((float) segments * (float) green / total);
segments -= greenSegments;

int blueSegments = segments;

attributeHeatmap =
ChatColor.RED + IntStream.range(0, redSegments).mapToObj(i -> "▌").collect(Collectors.joining()) +
ChatColor.YELLOW + IntStream.range(0, yellowSegments).mapToObj(i -> "▌").collect(Collectors.joining()) +
ChatColor.GREEN + IntStream.range(0, greenSegments).mapToObj(i -> "▌").collect(Collectors.joining()) +
ChatColor.BLUE + IntStream.range(0, blueSegments).mapToObj(i -> "▌").collect(Collectors.joining());
}

public String getAttributeHeatmap() {
Expand Down Expand Up @@ -181,7 +195,6 @@ public int getUnusedStatPoints() {

public void setUnusedStatPoints(int unusedStatPoints) {
saveData.setUnusedStatPoints(unusedStatPoints);
buildAttributeHeatmap();
}

public int getPendingUnusedStatPoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void savePendingStats(Champion champion) {
}
}
champion.getSaveData().savePendingStats();
champion.buildAttributeHeatmap();
rebuildAttributes(champion);
}

Expand Down

0 comments on commit d503904

Please sign in to comment.