(feat) saving/loading of custom crosshairs

This commit is contained in:
refactoring 2024-01-02 01:53:27 -05:00
parent a87875e565
commit 74696f8580
2 changed files with 39 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import net.silentclient.client.utils.MenuBlurUtils;
import java.awt.*;
import java.io.*;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -190,6 +191,11 @@ public final class ConfigManager {
}
}
if(set.isCellGrid()) {
try {
set.setCells(stringToBooleanArray(args[3]));
} catch (Exception ignored) {}
}
if (set.isCombo()) {
try {
if(set.getOptions().contains(args[3])) {
@ -247,6 +253,32 @@ public final class ConfigManager {
}
}
public static String booleanArrayToString(boolean[][] cells) {
StringBuilder sb = new StringBuilder();
for (boolean[] row : cells) {
for (boolean cell : row) {
sb.append(cell ? '1' : '0');
}
sb.append('/');
}
return sb.toString();
}
public static boolean[][] stringToBooleanArray(String input) {
String[] rows = input.trim().split("/");
int numRows = rows.length;
int numCols = rows[0].length();
boolean[][] result = new boolean[numRows][numCols];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
result[i][j] = rows[i].charAt(j) == '1';
}
}
return result;
}
public void save() {
Client.logger.info("Saving Config: " + this.configFile.getName());
try(PrintWriter writer = new PrintWriter(this.configFile)) {
@ -277,6 +309,9 @@ public final class ConfigManager {
if(set.isKeybind()) {
writer.println("SET:" + set.getName() + ":" + set.getParentMod().getName() + ":" + set.getKeybind());
}
if(set.isCellGrid()) {
writer.println("SET:" + set.getName() + ":" + set.getParentMod().getName() + ":" + booleanArrayToString(set.getCells()));
}
}
for(AutoTextCommand command : Client.getInstance().getModInstances().getAutoText().getCommands()) {

View File

@ -159,6 +159,10 @@ public class Setting implements Comparable<Setting> {
return this.sval;
}
public void setCells(boolean[][] cells) {
this.cells = cells;
}
public void setValString(String in) {
if(onlyPremiumPlus) {
if(Client.getInstance().getAccount() != null && Client.getInstance().getAccount().isPremiumPlus()) {