71 lines
1.9 KiB
Java
71 lines
1.9 KiB
Java
package de.fullrisk.citrusDev;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
|
|
import java.io.IOException;
|
|
import java.io.Reader;
|
|
import java.io.Writer;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
public class Config {
|
|
|
|
public int fpsSize = 16;
|
|
public int fpsX = 1;
|
|
public int fpsY = 1;
|
|
public boolean fpsEnabled = true;
|
|
public String lastModule = "FPS";
|
|
|
|
public int keyX = 1;
|
|
public int keyY = 1;
|
|
public int keySize = 16;
|
|
public boolean keyEnabled = true;
|
|
|
|
public int coordsX = 1;
|
|
public int coordsY = 1;
|
|
public int coordsP = 4;
|
|
public boolean coordsEnabled = true;
|
|
|
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
|
private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("citrus-dev.json");
|
|
|
|
private static Config instance;
|
|
public int fpsP = 4;
|
|
|
|
public static Config get() {
|
|
if (instance == null) {
|
|
instance = load();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
private static Config load() {
|
|
if (Files.exists(PATH)) {
|
|
try (Reader reader = Files.newBufferedReader(PATH, StandardCharsets.UTF_8)) {
|
|
Config loaded = GSON.fromJson(reader, Config.class);
|
|
if (loaded != null) {
|
|
return loaded;
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
Config fresh = new Config();
|
|
fresh.save();
|
|
return fresh;
|
|
}
|
|
|
|
public void save() {
|
|
try {
|
|
Files.createDirectories(PATH.getParent());
|
|
try (Writer writer = Files.newBufferedWriter(PATH, StandardCharsets.UTF_8)) {
|
|
GSON.toJson(this, writer);
|
|
}
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |