Skip to content

Commit

Permalink
Merge pull request #41 from discordrpc/master
Browse files Browse the repository at this point in the history
feature(configurable-gui): specify item slots using "-" and ","
  • Loading branch information
hamza-cskn committed Oct 1, 2023
2 parents a19d0d2 + b475e8d commit 6811e24
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ public static void putDysfunctionalIcons(@Nonnull ConfigurableGui gui, @Nonnull

public static List<Integer> parseSlotString(String str) {
if (str == null) return new ArrayList<>();
if (str.contains("-")) {
return parseStringAsIntegerRange(str);
} else if (str.contains(",")) {
str = str.replaceAll(" ", "");
if (str.contains(",")) {
return parseStringAsIntegerList(str);
} else if (str.contains("-")) {
return parseStringAsIntegerRange(str);
}
return new ArrayList<>();
}

private static List<Integer> parseStringAsIntegerRange(String str) {
final String[] slots = str.split("-");
if (slots.length != 2) new ArrayList<>();
if (slots.length != 2) return new ArrayList<>();
int from, to;

try {
Expand All @@ -77,7 +78,11 @@ private static List<Integer> parseStringAsIntegerList(String str) {

for (final String slotText : slotStrings) {
try {
pageSlots.add(Integer.parseInt(slotText));
if (slotText.contains("-")) {
pageSlots.addAll(parseStringAsIntegerRange(slotText));
} else {
pageSlots.add(Integer.parseInt(slotText));
}
} catch (NumberFormatException ignore) {
}
}
Expand Down

0 comments on commit 6811e24

Please sign in to comment.