|
1 | 1 | package dev.lazurite.hexaplex.config; |
2 | 2 |
|
3 | | -import dev.lazurite.hexaplex.graphics.ShaderManager; |
4 | | -import dev.lazurite.hexaplex.init.ClientInitializer; |
| 3 | +import dev.lazurite.hexaplex.Hexaplex; |
| 4 | +import dev.lazurite.hexaplex.rendering.Profiles; |
5 | 5 | import io.github.fablabsmc.fablabs.api.fiber.v1.annotation.AnnotatedSettings; |
6 | 6 | import io.github.fablabsmc.fablabs.api.fiber.v1.annotation.Setting; |
7 | 7 | import io.github.fablabsmc.fablabs.api.fiber.v1.annotation.Settings; |
8 | 8 | import io.github.fablabsmc.fablabs.api.fiber.v1.exception.FiberException; |
9 | 9 | import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.FiberSerialization; |
10 | 10 | import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.JanksonValueSerializer; |
11 | 11 | import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigTree; |
| 12 | +import net.fabricmc.api.EnvType; |
| 13 | +import net.fabricmc.api.Environment; |
12 | 14 | import net.fabricmc.loader.api.FabricLoader; |
13 | 15 |
|
14 | 16 | import java.io.IOException; |
15 | 17 | import java.nio.file.Files; |
| 18 | +import java.nio.file.Path; |
16 | 19 |
|
| 20 | +@Environment(EnvType.CLIENT) |
17 | 21 | @Settings(onlyAnnotated = true) |
18 | | -public class Config { |
| 22 | +public final class Config { |
19 | 23 |
|
20 | 24 | public static final Config INSTANCE = new Config(); |
21 | 25 |
|
22 | | - private boolean dirty; |
| 26 | + private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve(Hexaplex.MOD_ID + ".json"); |
23 | 27 |
|
24 | | - @Setting(name = "filterProfile") |
25 | | - private ShaderManager.Profiles profile; |
| 28 | + @Setting(name = "profile") |
| 29 | + private Profiles profile; |
26 | 30 |
|
27 | | - @Setting(name = "filterStrength") |
| 31 | + @Setting(name = "strength") |
28 | 32 | @Setting.Constrain.Range(min = 0.0, max = 1.0, step = 0.01) |
29 | 33 | private double strength; |
30 | 34 |
|
31 | | - private Config() { |
32 | | - this.profile = ShaderManager.Profiles.NORMAL; |
33 | | - this.strength = 0.0; |
34 | | - this.dirty = true; |
35 | | - } |
36 | | - |
37 | | - private void markDirty() { |
38 | | - this.dirty = true; |
39 | | - } |
| 35 | + @Setting(name = "skew") |
| 36 | + @Setting.Constrain.Range(min = 0.0, max = 1.0, step = 0.01) |
| 37 | + private double skew; |
40 | 38 |
|
41 | | - public void markClean() { |
42 | | - this.dirty = true; |
43 | | - } |
| 39 | + private boolean dirty; |
44 | 40 |
|
45 | | - public boolean isDirty() { |
46 | | - return this.dirty; |
| 41 | + private Config() { |
| 42 | + this.setProfile(Profiles.NORMAL); |
| 43 | + this.setStrength(0.0); |
| 44 | + this.setSkew(0.5); |
| 45 | + this.markDirty(); |
47 | 46 | } |
48 | 47 |
|
49 | 48 | public void save() { |
50 | 49 | try { |
51 | 50 | FiberSerialization.serialize( |
52 | | - ConfigTree.builder().applyFromPojo(INSTANCE, AnnotatedSettings.builder().collectOnlyAnnotatedMembers().build()).build(), |
53 | | - Files.newOutputStream(FabricLoader.getInstance().getConfigDir().resolve("hexaplex.json")), |
| 51 | + ConfigTree.builder() |
| 52 | + .applyFromPojo( |
| 53 | + INSTANCE, |
| 54 | + AnnotatedSettings.builder() |
| 55 | + .collectOnlyAnnotatedMembers() |
| 56 | + .build() |
| 57 | + ) |
| 58 | + .build(), |
| 59 | + Files.newOutputStream(PATH), |
54 | 60 | new JanksonValueSerializer(false) |
55 | 61 | ); |
56 | 62 | } catch (IOException e) { |
57 | | - ClientInitializer.LOGGER.error("Error saving Hexaplex config."); |
| 63 | + Hexaplex.LOGGER.error("Error saving Hexaplex config!"); |
58 | 64 | e.printStackTrace(); |
59 | 65 | } |
60 | 66 | } |
61 | 67 |
|
62 | 68 | public void load() { |
63 | | - if (Files.exists(FabricLoader.getInstance().getConfigDir().resolve("hexaplex.json"))) { |
| 69 | + if (Files.exists(PATH)) { |
64 | 70 | try { |
65 | 71 | FiberSerialization.deserialize( |
66 | | - ConfigTree.builder().applyFromPojo(INSTANCE, AnnotatedSettings.builder().collectOnlyAnnotatedMembers().build()).build(), |
67 | | - Files.newInputStream(FabricLoader.getInstance().getConfigDir().resolve("hexaplex.json")), |
| 72 | + ConfigTree.builder() |
| 73 | + .applyFromPojo( |
| 74 | + INSTANCE, |
| 75 | + AnnotatedSettings.builder() |
| 76 | + .collectOnlyAnnotatedMembers() |
| 77 | + .build() |
| 78 | + ) |
| 79 | + .build(), |
| 80 | + Files.newInputStream(PATH), |
68 | 81 | new JanksonValueSerializer(false) |
69 | 82 | ); |
70 | | - } catch (IOException | FiberException e) { |
71 | | - ClientInitializer.LOGGER.error("Error loading Hexaplex config."); |
| 83 | + } catch (FiberException | IOException e) { |
| 84 | + Hexaplex.LOGGER.error("Error loading Hexaplex config!"); |
72 | 85 | e.printStackTrace(); |
73 | 86 | } |
74 | 87 | } else { |
75 | | - ClientInitializer.LOGGER.info("Creating Hexaplex config."); |
| 88 | + Hexaplex.LOGGER.info("Creating Hexaplex config."); |
76 | 89 | this.save(); |
77 | 90 | } |
78 | 91 | } |
79 | 92 |
|
80 | | - public void setProfile(ShaderManager.Profiles profile) { |
| 93 | + public void setProfile(Profiles profile) { |
81 | 94 | this.profile = profile; |
82 | 95 | this.markDirty(); |
83 | | - this.save(); |
84 | 96 | } |
85 | 97 |
|
86 | | - public ShaderManager.Profiles getProfile() { |
| 98 | + public Profiles getProfile() { |
87 | 99 | return this.profile; |
88 | 100 | } |
89 | 101 |
|
90 | 102 | public void setStrength(double strength) { |
91 | 103 | this.strength = strength; |
92 | | - this.save(); |
| 104 | + this.markDirty(); |
93 | 105 | } |
94 | 106 |
|
95 | 107 | public double getStrength() { |
96 | 108 | return this.strength; |
97 | 109 | } |
| 110 | + |
| 111 | + public void setSkew(double skew) { |
| 112 | + this.skew = skew; |
| 113 | + this.markDirty(); |
| 114 | + } |
| 115 | + |
| 116 | + public double getSkew() { |
| 117 | + return this.skew; |
| 118 | + } |
| 119 | + |
| 120 | + private void markDirty() { |
| 121 | + this.dirty = true; |
| 122 | + } |
| 123 | + |
| 124 | + public void markClean() { |
| 125 | + this.dirty = false; |
| 126 | + } |
| 127 | + |
| 128 | + public boolean isDirty() { |
| 129 | + return this.dirty; |
| 130 | + } |
98 | 131 | } |
0 commit comments