Search in sources :

Example 1 with NumberSetting

use of dev.hypnotic.settings.settingtypes.NumberSetting in project Hypnotic-Client by Hypnotic-Development.

the class Config method serialize.

public String serialize() {
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
    for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
        List<ConfigSetting> settings = new ArrayList<>();
        for (Setting setting : module.settings) {
            if (setting instanceof KeybindSetting)
                continue;
            ConfigSetting cfgSetting = new ConfigSetting(null, null);
            cfgSetting.name = setting.name;
            if (setting instanceof BooleanSetting) {
                cfgSetting.value = ((BooleanSetting) setting).isEnabled();
            }
            if (setting instanceof ModeSetting) {
                cfgSetting.value = ((ModeSetting) setting).getSelected();
            }
            if (setting instanceof NumberSetting) {
                cfgSetting.value = ((NumberSetting) setting).getValue();
            }
            if (setting instanceof ColorSetting) {
                cfgSetting.value = ((ColorSetting) setting).getHex();
            }
            settings.add(cfgSetting);
        }
        module.cfgSettings = settings.toArray(new ConfigSetting[0]);
    }
    return gson.toJson(ModuleManager.INSTANCE.getAllModules());
}
Also used : NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) ArrayList(java.util.ArrayList) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson)

Example 2 with NumberSetting

use of dev.hypnotic.settings.settingtypes.NumberSetting in project Hypnotic-Client by Hypnotic-Development.

the class ConfigManager method loadConfig.

public boolean loadConfig() {
    try {
        String configString = new String(Files.readAllBytes(config.toPath()));
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
        Mod[] modules = gson.fromJson(configString, Mod[].class);
        HudModule[] hudModules = gson.fromJson(configString, HudModule[].class);
        for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
            if (module instanceof HudModule) {
                HudModule hudMod = (HudModule) module;
                for (HudModule configHudModule : hudModules) {
                    if (hudMod.getName().equals(configHudModule.getName())) {
                        hudMod.setX(configHudModule.getX());
                        hudMod.setY(configHudModule.getY());
                        System.out.println(hudMod.getName() + ":" + configHudModule.getX());
                    }
                }
            }
            for (Mod configModule : modules) {
                if (module.getName().equals(configModule.getName())) {
                    try {
                        if (configModule.isEnabled() && !module.isEnabled())
                            module.setEnabled(true);
                        else if (!configModule.isEnabled() && module.isEnabled())
                            module.setEnabled(false);
                        module.setKey(configModule.getKey());
                        for (Setting setting : module.settings) {
                            for (ConfigSetting cfgSetting : configModule.cfgSettings) {
                                if (setting.name.equals(cfgSetting.name)) {
                                    if (setting instanceof BooleanSetting) {
                                        ((BooleanSetting) setting).setEnabled((boolean) cfgSetting.value);
                                    }
                                    if (setting instanceof ModeSetting) {
                                        ((ModeSetting) setting).setSelected((String) cfgSetting.value);
                                    }
                                    if (setting instanceof NumberSetting) {
                                        ((NumberSetting) setting).setValue((double) cfgSetting.value);
                                    }
                                    if (setting instanceof ColorSetting) {
                                        int[] color = ((ColorSetting) setting).hexToRgbInt((String) cfgSetting.value);
                                        ((ColorSetting) setting).setRGB(color[0], color[1], color[2], color[3]);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson) HudModule(dev.hypnotic.module.hud.HudModule) IOException(java.io.IOException) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting)

Example 3 with NumberSetting

use of dev.hypnotic.settings.settingtypes.NumberSetting in project Hypnotic-Client by Hypnotic-Development.

the class ConfigManager method serialize.

public String serialize() {
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
    for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
        List<ConfigSetting> settings = new ArrayList<>();
        for (Setting setting : module.settings) {
            if (setting instanceof KeybindSetting)
                continue;
            ConfigSetting cfgSetting = new ConfigSetting(null, null);
            cfgSetting.name = setting.name;
            if (setting instanceof BooleanSetting) {
                cfgSetting.value = ((BooleanSetting) setting).isEnabled();
            }
            if (setting instanceof ModeSetting) {
                cfgSetting.value = ((ModeSetting) setting).getSelected();
            }
            if (setting instanceof NumberSetting) {
                cfgSetting.value = ((NumberSetting) setting).getValue();
            }
            if (setting instanceof ColorSetting) {
                ColorSetting colorSet = (ColorSetting) setting;
                cfgSetting.value = colorSet.getHex();
            }
            settings.add(cfgSetting);
        }
        module.cfgSettings = settings.toArray(new ConfigSetting[0]);
    }
    return gson.toJson(ModuleManager.INSTANCE.getAllModules());
}
Also used : NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) ArrayList(java.util.ArrayList) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson)

Example 4 with NumberSetting

use of dev.hypnotic.settings.settingtypes.NumberSetting in project Hypnotic-Client by Hypnotic-Development.

the class ConfigManager method load.

public boolean load(String name) {
    Config config = new Config(name);
    try {
        String configString = new String(Files.readAllBytes(config.getFile().toPath()));
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
        Mod[] modules = gson.fromJson(configString, Mod[].class);
        HudModule[] hudModules = gson.fromJson(configString, HudModule[].class);
        for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
            for (HudModule configHudModule : hudModules) {
                HudModule hudMod = (HudModule) module;
                hudMod.setX(configHudModule.getX());
                hudMod.setY(configHudModule.getY());
            }
            for (Mod configModule : modules) {
                if (module.getName().equals(configModule.getName())) {
                    try {
                        if (configModule.isEnabled() && !module.isEnabled())
                            module.toggle();
                        else if (!configModule.isEnabled() && module.isEnabled())
                            module.setEnabled(false);
                        module.setKey(configModule.getKey());
                        if (module instanceof HudModule) {
                            HudModule hudMod = (HudModule) module;
                            HudModule configHudMod = (HudModule) configModule;
                            hudMod.setX(configHudMod.getX());
                            hudMod.setY(configHudMod.getY());
                        }
                        for (Setting setting : module.settings) {
                            for (ConfigSetting cfgSetting : configModule.cfgSettings) {
                                if (setting.name.equals(cfgSetting.name)) {
                                    if (setting instanceof BooleanSetting) {
                                        ((BooleanSetting) setting).setEnabled((boolean) cfgSetting.value);
                                    }
                                    if (setting instanceof ModeSetting) {
                                        ((ModeSetting) setting).setSelected((String) cfgSetting.value);
                                    }
                                    if (setting instanceof NumberSetting) {
                                        ((NumberSetting) setting).setValue((double) cfgSetting.value);
                                    }
                                    if (setting instanceof ColorSetting) {
                                        int[] color = ((ColorSetting) setting).hexToRgbInt((String) cfgSetting.value);
                                        ((ColorSetting) setting).setRGB(color[0], color[1], color[2], color[3]);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson) HudModule(dev.hypnotic.module.hud.HudModule) IOException(java.io.IOException) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting)

Aggregations

Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 Mod (dev.hypnotic.module.Mod)4 Setting (dev.hypnotic.settings.Setting)4 BooleanSetting (dev.hypnotic.settings.settingtypes.BooleanSetting)4 ColorSetting (dev.hypnotic.settings.settingtypes.ColorSetting)4 KeybindSetting (dev.hypnotic.settings.settingtypes.KeybindSetting)4 ModeSetting (dev.hypnotic.settings.settingtypes.ModeSetting)4 NumberSetting (dev.hypnotic.settings.settingtypes.NumberSetting)4 HudModule (dev.hypnotic.module.hud.HudModule)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2