From 74696f8580a1fab6b8ee59f3862854f2d8dc077a Mon Sep 17 00:00:00 2001 From: refactoring Date: Tue, 2 Jan 2024 01:53:27 -0500 Subject: [PATCH] (feat) saving/loading of custom crosshairs --- .../client/config/ConfigManager.java | 35 +++++++++++++++++++ .../net/silentclient/client/mods/Setting.java | 4 +++ 2 files changed, 39 insertions(+) diff --git a/src/main/java/net/silentclient/client/config/ConfigManager.java b/src/main/java/net/silentclient/client/config/ConfigManager.java index 6b66a6d..15d26d9 100644 --- a/src/main/java/net/silentclient/client/config/ConfigManager.java +++ b/src/main/java/net/silentclient/client/config/ConfigManager.java @@ -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()) { diff --git a/src/main/java/net/silentclient/client/mods/Setting.java b/src/main/java/net/silentclient/client/mods/Setting.java index 35c6a83..f5eb22b 100644 --- a/src/main/java/net/silentclient/client/mods/Setting.java +++ b/src/main/java/net/silentclient/client/mods/Setting.java @@ -159,6 +159,10 @@ public class Setting implements Comparable { 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()) {