55 lines
1.4 KiB
Java
55 lines
1.4 KiB
Java
package su.a71.new_soviet;
|
|
|
|
import java.io.*;
|
|
|
|
public class Config {
|
|
private boolean invert_lamps = false;
|
|
|
|
public static Config INSTANCE;
|
|
|
|
public Config() {
|
|
INSTANCE = this;
|
|
}
|
|
|
|
public boolean shouldInvertLamps() {
|
|
return invert_lamps;
|
|
}
|
|
|
|
|
|
private static void generateDefault() {
|
|
File file = new File("config/new_soviet.json");
|
|
if(!file.getParentFile().exists()) {
|
|
file.getParentFile().mkdirs();
|
|
}
|
|
INSTANCE = new Config();
|
|
try {
|
|
FileWriter writer = new FileWriter(file);
|
|
writer.write(NewSoviet.GSON.toJson(INSTANCE));
|
|
writer.close();
|
|
} catch (Exception e) {
|
|
INSTANCE = new Config();
|
|
}
|
|
|
|
}
|
|
|
|
public static void load() {
|
|
// Generate config if it doesn't exist
|
|
File file = new File("config/new_soviet.json");
|
|
if(!file.exists()) {
|
|
generateDefault();
|
|
}
|
|
|
|
try {
|
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
StringBuilder sb = new StringBuilder();
|
|
String s;
|
|
while((s = reader.readLine()) != null)
|
|
sb.append(s);
|
|
reader.close();
|
|
|
|
INSTANCE = NewSoviet.GSON.fromJson(sb.toString(), Config.class);
|
|
} catch(Exception e) {
|
|
INSTANCE = new Config();
|
|
}
|
|
}
|
|
}
|