Search in sources :

Example 1 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class BlockOverlaySettings method load.

public void load() {
    try {
        if (configFile.getParentFile().exists() && configFile.exists()) {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile));
            String stringBuilder = bufferedReader.lines().collect(Collectors.joining(""));
            BetterJsonObject json = new BetterJsonObject(stringBuilder);
            String overlayMode = json.optString("overlayMode");
            for (BlockOverlayMode mode : BlockOverlayMode.values()) {
                if (mode.getName().equals(overlayMode)) {
                    this.overlayMode = mode;
                    break;
                }
            }
            alwaysRender = json.optBoolean("alwaysRender");
            isChroma = json.optBoolean("isChroma");
            lineWidth = (float) json.optDouble("lineWidth");
            overlayRed = (float) json.optDouble("overlayRed");
            overlayGreen = (float) json.optDouble("overlayGreen");
            overlayBlue = (float) json.optDouble("overlayBlue");
            overlayAlpha = (float) json.optDouble("overlayAlpha");
            chromaSpeed = json.optInt("chromaSpeed");
            bufferedReader.close();
        }
    } catch (Exception exception) {
        Hyperium.LOGGER.error("Error occurred while loading BlockOverlay configuration!");
    }
}
Also used : BetterJsonObject(cc.hyperium.utils.BetterJsonObject) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 2 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class BlockOverlaySettings method save.

public void save() {
    try {
        if (!configFile.getParentFile().exists()) {
            configFile.getParentFile().mkdirs();
        }
        if (!configFile.exists()) {
            configFile.createNewFile();
        }
        BetterJsonObject json = new BetterJsonObject();
        json.addProperty("overlayMode", overlayMode.getName());
        json.addProperty("alwaysRender", alwaysRender);
        json.addProperty("isChroma", isChroma);
        json.addProperty("lineWidth", lineWidth);
        json.addProperty("overlayRed", overlayRed);
        json.addProperty("overlayGreen", overlayGreen);
        json.addProperty("overlayBlue", overlayBlue);
        json.addProperty("overlayAlpha", overlayAlpha);
        json.addProperty("chromaSpeed", chromaSpeed);
        json.writeToFile(configFile);
    } catch (Exception exception) {
        Hyperium.LOGGER.error("Error occurred while saving BlockOverlay configuration!");
    }
}
Also used : BetterJsonObject(cc.hyperium.utils.BetterJsonObject)

Example 3 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class KeystrokesSettings method save.

public void save() {
    try {
        if (!configFile.getParentFile().exists())
            configFile.getParentFile().mkdirs();
        if (!configFile.exists() && !configFile.createNewFile())
            return;
        BetterJsonObject object = new BetterJsonObject();
        object.addProperty("x", x);
        object.addProperty("y", y);
        object.addProperty("leftClick", leftClick);
        object.addProperty("red", red);
        object.addProperty("green", green);
        object.addProperty("blue", blue);
        object.addProperty("pressedRed", pressedRed);
        object.addProperty("pressedGreen", pressedGreen);
        object.addProperty("pressedBlue", pressedBlue);
        object.addProperty("scale", getScale());
        object.addProperty("fadeTime", getFadeTime());
        object.addProperty("enabled", enabled);
        object.addProperty("chroma", chroma);
        object.addProperty("mouseButtons", mouseButtons);
        object.addProperty("showCPS", showCPS);
        object.addProperty("showCPSOnButtons", showCPSOnButtons);
        object.addProperty("showSpacebar", showSpacebar);
        object.addProperty("showSneak", showingSneak);
        object.addProperty("showFps", showingFPS);
        object.addProperty("keyBackground", keyBackground);
        object.addProperty("showingWASD", showingWASD);
        object.addProperty("literalKeys", literalKeys);
        object.addProperty("keyBackgroundOpacity", keyBackgroundOpacity);
        object.addProperty("keyBackgroundRed", keyBackgroundRed);
        object.addProperty("keyBackgroundGreen", keyBackgroundGreen);
        object.addProperty("keyBackgroundBlue", keyBackgroundBlue);
        object.addProperty("arrowKeys", arrowKeys);
        JsonArray keys = new JsonArray();
        theMod.getRenderer().getCustomKeys().forEach(wrapper -> {
            JsonHolder holder = new JsonHolder();
            holder.put("key", wrapper.getKey().getKey());
            holder.put("type", wrapper.getKey().getType());
            holder.put("xOffset", wrapper.getxOffset());
            holder.put("yOffset", wrapper.getyOffset());
            keys.add(holder.getObject());
        });
        object.getData().add("custom", keys);
        object.writeToFile(configFile);
    } catch (Exception ex) {
        Hyperium.LOGGER.warn(String.format("Could not save config file! (\"%s\")", configFile.getName()));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonHolder(cc.hyperium.utils.JsonHolder) BetterJsonObject(cc.hyperium.utils.BetterJsonObject)

Example 4 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class KeystrokesSettings method parseSettings.

private void parseSettings(BetterJsonObject object) {
    x = object.optInt("x");
    y = object.optInt("y");
    red = object.optInt("red", 255);
    green = object.optInt("green", 255);
    blue = object.optInt("blue", 255);
    pressedRed = object.optInt("pressedRed");
    pressedGreen = object.optInt("pressedGreen");
    pressedBlue = object.optInt("pressedBlue");
    setScale(object.optDouble("scale", 1.0D));
    setFadeTime(object.optDouble("fadeTime", 1.0D));
    enabled = object.optBoolean("enabled", true);
    chroma = object.optBoolean("chroma");
    leftClick = object.optBoolean("leftClick", true);
    mouseButtons = object.optBoolean("mouseButtons");
    showCPS = object.optBoolean("showCPS");
    showCPSOnButtons = object.optBoolean("showCPSOnButtons");
    showSpacebar = object.optBoolean("showSpacebar");
    showingSneak = object.optBoolean("showSneak");
    showingFPS = object.optBoolean("showFps");
    keyBackground = object.optBoolean("keyBackground", true);
    showingWASD = object.optBoolean("showingWASD", true);
    literalKeys = object.optBoolean("literalKeys");
    keyBackgroundOpacity = object.optInt("keyBackgroundOpacity", 120);
    keyBackgroundRed = object.optInt("keyBackgroundRed");
    keyBackgroundGreen = object.optInt("keyBackgroundGreen");
    keyBackgroundBlue = object.optInt("keyBackgroundBlue");
    arrowKeys = object.optBoolean("arrowKeys");
    JsonObject data = object.getData();
    if (data.has("custom")) {
        JsonArray custom = data.getAsJsonArray("custom");
        for (JsonElement element : custom) {
            JsonHolder holder = new JsonHolder(element.getAsJsonObject());
            CustomKeyWrapper wrapper = new CustomKeyWrapper(new CustomKey(theMod, holder.optInt("key"), holder.optInt("type")), holder.optInt("xOffset"), holder.optInt("yOffset"));
            configWrappers.add(wrapper);
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonHolder(cc.hyperium.utils.JsonHolder) CustomKeyWrapper(cc.hyperium.mods.keystrokes.render.CustomKeyWrapper) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) BetterJsonObject(cc.hyperium.utils.BetterJsonObject) CustomKey(cc.hyperium.mods.keystrokes.keys.impl.CustomKey)

Example 5 with BetterJsonObject

use of cc.hyperium.utils.BetterJsonObject in project Hyperium by HyperiumClient.

the class KeystrokesSettings method load.

public void load() {
    try {
        if (!configFile.getParentFile().exists() || !configFile.exists()) {
            save();
            return;
        }
        BufferedReader f = new BufferedReader(new FileReader(configFile));
        List<String> options = f.lines().collect(Collectors.toList());
        if (options.isEmpty())
            return;
        String builder = String.join("", options);
        if (builder.trim().length() > 0)
            parseSettings(new BetterJsonObject(builder.trim()));
        f.close();
    } catch (Exception ex) {
        Hyperium.LOGGER.warn("Could not load config file! {}", configFile.getName());
        save();
    }
}
Also used : BetterJsonObject(cc.hyperium.utils.BetterJsonObject) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Aggregations

BetterJsonObject (cc.hyperium.utils.BetterJsonObject)7 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 JsonHolder (cc.hyperium.utils.JsonHolder)2 JsonArray (com.google.gson.JsonArray)2 CustomKey (cc.hyperium.mods.keystrokes.keys.impl.CustomKey)1 CustomKeyWrapper (cc.hyperium.mods.keystrokes.render.CustomKeyWrapper)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1