Search in sources :

Example 1 with KeybindSetting

use of dev.hypnotic.settings.settingtypes.KeybindSetting 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 KeybindSetting

use of dev.hypnotic.settings.settingtypes.KeybindSetting 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)

Aggregations

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