fix config settings

This commit is contained in:
kawaiizenbo 2023-10-09 08:10:42 -07:00
parent 0982c30299
commit ce8dd2ebed
3 changed files with 42 additions and 4 deletions

View file

@ -6,17 +6,23 @@ import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import me.kawaiizenbo.moonlight.module.Category;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module_;
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
import me.kawaiizenbo.moonlight.module.settings.Setting;
import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen;
import net.minecraft.client.MinecraftClient;
public class Config
{
public static final Logger LOGGER = LoggerFactory.getLogger("mcfg");
MinecraftClient mc = MinecraftClient.getInstance();
public File configDir = new File(mc.runDirectory.getPath() + "/moonlight");
public File configFile = new File(configDir, "config.json");
@ -41,10 +47,19 @@ public class Config
{
Map<String, Object> mo = new HashMap<>();
mo.put("enabled", m.enabled);
Map<String, Object> ms = new HashMap<>();
for (Setting s : m.settings)
{
mo.put(s.name, s.value);
if (s instanceof BooleanSetting)
{
ms.put(s.name, ((BooleanSetting)s).value);
}
else if (s instanceof DoubleSetting)
{
ms.put(s.name, ((DoubleSetting)s).value);
}
}
mo.put("settings", ms);
mi.put(m.name, mo);
}
config.put("modules", mi);

View file

@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
import me.kawaiizenbo.moonlight.module.ModuleManager;
import me.kawaiizenbo.moonlight.module.Module_;
import me.kawaiizenbo.moonlight.module.settings.BooleanSetting;
import me.kawaiizenbo.moonlight.module.settings.DoubleSetting;
import me.kawaiizenbo.moonlight.module.settings.Setting;
import me.kawaiizenbo.moonlight.ui.clickgui.CategoryPane;
import me.kawaiizenbo.moonlight.ui.clickgui.ClickGUIScreen;
@ -44,9 +46,22 @@ public class Moonlight implements ModInitializer
for (Module_ m : ModuleManager.INSTANCE.modules)
{
m.enabled = (boolean)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("enabled");
if (m.enabled)
{
//m.onEnable();
/// brocken :(
}
for (Setting s : m.settings)
{
s.value = ((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get(s.name);
if (s instanceof BooleanSetting)
{
((BooleanSetting)s).value = (boolean)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("settings")).get(s.name);
}
else if (s instanceof DoubleSetting)
{
((DoubleSetting)s).value = (Double)((Map<String, Object>)((Map<String, Object>)((Map<String, Object>)CONFIG.config.get("modules")).get(m.name)).get("settings")).get(s.name);
}
}
}
}
@ -59,10 +74,19 @@ public class Moonlight implements ModInitializer
{
Map<String, Object> mo = new HashMap<>();
mo.put("enabled", m.enabled);
Map<String, Object> ms = new HashMap<>();
for (Setting s : m.settings)
{
mo.put(s.name, s.value);
if (s instanceof BooleanSetting)
{
ms.put(s.name, ((BooleanSetting)s).value);
}
else if (s instanceof DoubleSetting)
{
ms.put(s.name, ((DoubleSetting)s).value);
}
}
mo.put("settings", ms);
mi.put(m.name, mo);
}
CONFIG.config.put("modules", mi);

View file

@ -7,7 +7,6 @@ public class Setting
{
public String name;
public int height = 24;
public Object value;
int x = 0, y = 0;
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer)