-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathAnimaticaConfig.java
More file actions
90 lines (71 loc) · 2.84 KB
/
AnimaticaConfig.java
File metadata and controls
90 lines (71 loc) · 2.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package io.github.foundationgames.animatica.config;
import io.github.foundationgames.animatica.Animatica;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
import net.minecraft.network.chat.Component;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
public class AnimaticaConfig {
public static String ANIMATED_TEXTURES_KEY = "animated_textures";
private static final Component GRAPHICS_TOOLTIP_ANIMATIONS = Component.translatable("options.animatica.animations.tooltip");
public static final String FILE_NAME = "animatica.properties";
private final OptionInstance<Boolean> animatedTexturesOption;
public boolean animatedTextures;
public AnimaticaConfig() {
try {
load();
} catch (IOException e) {
Animatica.LOG.error("Error loading config during initialization!", e);
}
this.animatedTexturesOption = OptionInstance.createBoolean(
"option.animatica.animated_textures",
OptionInstance.cachedConstantTooltip(GRAPHICS_TOOLTIP_ANIMATIONS),
this.animatedTextures,
value -> {
this.animatedTextures = value;
try {
this.save();
} catch (IOException e) { Animatica.LOG.error("Error saving config while changing in game!", e); }
Minecraft.getInstance().reloadResourcePacks();
}
);
}
public void writeTo(Properties properties) {
properties.put(ANIMATED_TEXTURES_KEY, Boolean.toString(animatedTextures));
}
public void readFrom(Properties properties) {
this.animatedTextures = boolFrom(properties.getProperty(ANIMATED_TEXTURES_KEY), true);
}
public Path getFile() throws IOException {
var file = FabricLoader.getInstance().getConfigDir().resolve(FILE_NAME);
if (!Files.exists(file)) {
Files.createFile(file);
}
return file;
}
public OptionInstance<Boolean> getAnimatedTexturesOption() {
return animatedTexturesOption;
}
public void save() throws IOException {
var file = getFile();
var properties = new Properties();
writeTo(properties);
try (var out = Files.newOutputStream(file)) {
properties.store(out, "Configuration file for Animatica");
}
}
public void load() throws IOException {
var file = getFile();
var properties = new Properties();
try (var in = Files.newInputStream(file)) {
properties.load(in);
}
readFrom(properties);
}
private static boolean boolFrom(String s, boolean defaultVal) {
return s == null ? defaultVal : "true".equals(s);
}
}