Added Module Settings and removed test screen
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
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 fpsX = 1;
|
||||
public int fpsY = 1;
|
||||
public String lastModule = "FPS";
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user