Skip to content

Commit

Permalink
holy amount work fr
Browse files Browse the repository at this point in the history
  • Loading branch information
dan28000 committed Jun 20, 2024
1 parent c8d1c0c commit 664dbf0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum Rarity {
this.modelData = modelData;
}

public NumberType getPity() {
public NumberType getNumberType() {
return switch (this) {
case LEGENDARY -> NumberType.LEGENDARY_PITY;
case EPIC -> NumberType.EPIC_PITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ public enum ResultType {
ResultType(TextColor color) {
this.color = color;
}

public String getNext() {
return switch (this) {
case LOST -> "c";
case GUARANTEED, WON -> "b";
default -> "";
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.badbones69.crazycrates.api.objects.gacha.data.PlayerProfile;
import com.badbones69.crazycrates.api.objects.gacha.data.RaritySettings;
import com.badbones69.crazycrates.api.objects.gacha.enums.Rarity;
import com.badbones69.crazycrates.api.objects.gacha.enums.ResultType;
import com.badbones69.crazycrates.api.objects.gacha.util.Pair;
import lombok.experimental.UtilityClass;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
Expand All @@ -26,9 +28,9 @@ public final class ComponentBuilder {
private static final Component SPACE_NEGATIVE = translatable("space.-1", "").font(KEY);
private static final Component SPACE_PAGE = translatable("space.223", "").font(KEY);
private static final Component SPACE_TIME = translatable("space.-335", "").font(KEY);
private static final Component SPACE_PITY = translatable("space.-40", "").font(KEY);
private static final Component SPACE_PITY = translatable("space.-71", "").font(KEY);
private static final Component SPACE_SLASH = translatable("space.9", "").font(KEY);
private static final Component SPACE_TEST = translatable("space.-41", "").font(KEY);
private static final Component SPACE_NEWLINE = translatable("space.-72", "").font(KEY);
private static final Component FILL_TOP = translatable("fill_top", "").color(COLOR).append(SPACE_NEGATIVE);
private static final Component FILL_DOWN = translatable("fill_down", "").color(COLOR).append(SPACE_NEGATIVE);
private static final Component FILL_TIME = translatable("fill_time", "").color(COLOR).append(SPACE_NEGATIVE);
Expand Down Expand Up @@ -79,7 +81,7 @@ public static Component trans(Player player, CrateSettings crateSettings) {
}

for (char c : time.toCharArray()) {
builder.append(sw(c, NumberType.TIME));
builder.append(sw(c, NumberType.TIME, true));
if (c == ' ') {
builder.append(FILL_TIME).append(FILL_TIME);
}
Expand All @@ -100,14 +102,19 @@ public static Component trans(Player player, CrateSettings crateSettings) {
}

private static void pity(TextComponent.Builder builder, PlayerProfile playerProfile, Rarity rarity, RaritySettings settings) {
int currentPity = playerProfile.getPity(rarity).first();
Pair<Integer, ResultType> result = playerProfile.getPity(rarity);
int currentPity = result.first();
String resultType = result.second().getNext();
String current = String.format("%02d", currentPity);
String pity = String.format("%02d", settings.pity());

appendChars(builder, current, rarity.getPity());
NumberType numberType = rarity.getNumberType();

appendChars(builder, resultType, numberType, false);
appendChars(builder, current, numberType);
builder.append(SPACE_SLASH);
appendChars(builder, pity, rarity.getPity());
builder.append(SPACE_TEST);
appendChars(builder, pity, numberType);
builder.append(SPACE_NEWLINE);
}

private static void down(TextComponent.Builder builder, String amount, int spaceLength, Component filler, Component space) {
Expand All @@ -121,14 +128,18 @@ private static void down(TextComponent.Builder builder, String amount, int space
appendChars(builder, amount, NumberType.DOWN);
}

private void appendChars(TextComponent.Builder builder, String str, NumberType numberType) {
private static void appendChars(TextComponent.Builder builder, String str, NumberType numberType) {
appendChars(builder, str, numberType, true);
}

private void appendChars(TextComponent.Builder builder, String str, NumberType numberType, boolean space) {
for (char c : str.toCharArray()) {
builder.append(sw(c, numberType));
builder.append(sw(c, numberType, space));
}
}

private static Component sw(char c, NumberType numberType) {
return translatable(charSwap(c, numberType), "").color(COLOR).append(SPACE_NEGATIVE);
private static Component sw(char c, NumberType numberType, boolean space) {
return translatable(charSwap(c, numberType), "").color(COLOR).append(space ? SPACE_NEGATIVE : Component.empty());
}

private static String charSwap(char c, NumberType numberType) {
Expand All @@ -147,6 +158,8 @@ private static String charSwap(char c, NumberType numberType) {
case 'h' -> "hours";
case 'm' -> "minutes";
case ' ' -> "fill";
case 'c' -> "color";
case 'b' -> "black";
default -> c + "";
} + switch (numberType) {
case TOP -> "_top";
Expand Down

0 comments on commit 664dbf0

Please sign in to comment.