-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathConfig.java
More file actions
66 lines (54 loc) · 1.73 KB
/
Config.java
File metadata and controls
66 lines (54 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package net.vulkanmod.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
public class Config {
public int frameQueueSize = 2;
public VideoResolution resolution = VideoResolution.getFirstAvailable();
public boolean windowedFullscreen = false;
public boolean guiOptimizations = false;
public int advCulling = 2;
public boolean indirectDraw = false;
public boolean uniqueOpaqueLayer = true;
public boolean entityCulling = true;
private static Path path;
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithModifiers(Modifier.PRIVATE)
.create();
public static Config load(Path path) {
Config config;
Config.path = path;
if (Files.exists(path)) {
try (FileReader fileReader = new FileReader(path.toFile())) {
config = GSON.fromJson(fileReader, Config.class);
}
catch (IOException exception) {
throw new RuntimeException(exception.getMessage());
}
}
else {
config = null;
}
return config;
}
public void write() {
if(!Files.exists(path.getParent())) {
try {
Files.createDirectories(path);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Files.write(path, Collections.singleton(GSON.toJson(this)));
} catch (IOException e) {
e.printStackTrace();
}
}
}