| 34 | import dev.hypnotic.settings.settingtypes.NumberSetting; |
| 35 | |
| 36 | public class Config { |
| 37 | |
| 38 | private final String name; |
| 39 | protected File file; |
| 40 | |
| 41 | public Config(String name) { |
| 42 | this.name = name; |
| 43 | this.file = new File(Hypnotic.hypnoticDir, "/configs/" + name + ".json"); |
| 44 | } |
| 45 | |
| 46 | public String getName() { |
| 47 | return name; |
| 48 | } |
| 49 | |
| 50 | public File getFile() { |
| 51 | return file; |
| 52 | } |
| 53 | |
| 54 | public String serialize() { |
| 55 | Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); |
| 56 | for (Mod module : ModuleManager.INSTANCE.getAllModules()) { |
| 57 | List<ConfigSetting> settings = new ArrayList<>(); |
| 58 | for (Setting setting : module.getSettings()) { |
| 59 | if (setting instanceof KeybindSetting) |
| 60 | continue; |
| 61 | |
| 62 | ConfigSetting cfgSetting = new ConfigSetting(null, null); |
| 63 | cfgSetting.name = setting.name; |
| 64 | if (setting instanceof BooleanSetting) { |
| 65 | cfgSetting.value = ((BooleanSetting) setting).isEnabled(); |
| 66 | } |
| 67 | if (setting instanceof ModeSetting) { |
| 68 | cfgSetting.value = ((ModeSetting) setting).getSelected(); |
| 69 | } |
| 70 | if (setting instanceof NumberSetting) { |
| 71 | cfgSetting.value = ((NumberSetting) setting).getValue(); |
| 72 | } |
| 73 | if (setting instanceof ColorSetting) { |
| 74 | cfgSetting.value = ((ColorSetting) setting).getHex(); |
| 75 | } |
| 76 | |
| 77 | settings.add(cfgSetting); |
| 78 | } |
| 79 | module.cfgSettings = settings.toArray(new ConfigSetting[0]); |
| 80 | } |
| 81 | return gson.toJson(ModuleManager.INSTANCE.getAllModules()); |
| 82 | } |
| 83 | |
| 84 | } |
nothing calls this directly
no outgoing calls
no test coverage detected