aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
blob: c48cd6e9eef99629668b128c8934e88ec2a08fc0 (plain)
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
package dev.mayaqq.ygasi.registry;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;

import java.io.*;

public class ConfigRegistry {

    public static Config CONFIG = new Config();

    static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi");
    private static final File configFile = new File(modConfFolder,"config.json");
    private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();

    public static void load() {
        //we do bunch of checking here mainly if the file exists
        if (!modConfFolder.exists()) {
            modConfFolder.mkdir();
        }
        if (!configFile.exists()) {
            try {
                configFile.createNewFile();
                save();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } else {
            try {
                CONFIG = gson.fromJson(new FileReader(configFile), Config.class);
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void save() {
        try {
            FileWriter writer = new FileWriter(configFile);
            gson.toJson(CONFIG, writer);
            writer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static class Config {
        //the thing to write in the config file
        public int pointsRewarded = 1;
        public int branchCost = 16;
        public Boolean enableSkillBook = true;
        public int resetCost = 10;
        public int T1Cost = 5;
        public int T2Cost = 10;
        public int T3Cost = 15;
        public int offence1DefIncrease = 3;

        public Config() {}
    }
}