+5
config.toml
+5
config.toml
+3
config/config.go
+3
config/config.go
···
4
4
"os"
5
5
6
6
"github.com/BurntSushi/toml"
7
+
"potassium.sh/dot-mining/minecraft"
7
8
)
8
9
9
10
type (
10
11
Config struct {
12
+
Options minecraft.Options `toml:options`
11
13
Fabric Loader `toml:fabric`
12
14
Mods map[string]string `toml:mods`
13
15
}
16
+
14
17
Loader struct {
15
18
Mods map[string]string `toml:mods`
16
19
}
+2
-2
main.go
+2
-2
main.go
···
2
2
3
3
import (
4
4
"potassium.sh/dot-mining/config"
5
-
"potassium.sh/dot-mining/modrinth"
5
+
"potassium.sh/dot-mining/minecraft"
6
6
)
7
7
8
8
9
9
10
10
func main() {
11
11
config := config.LoadConfig()
12
-
modrinth.LoadMods(config.Mods)
12
+
minecraft.WriteOptions(config.Options, "")
13
13
}
+42
minecraft/options.go
+42
minecraft/options.go
···
1
+
package minecraft
2
+
3
+
import (
4
+
"fmt"
5
+
"reflect"
6
+
"strconv"
7
+
)
8
+
9
+
10
+
type (
11
+
Options struct {
12
+
MainHand string `toml:"main_hand" txt:"mainHand"`
13
+
AO bool `toml:"smooth_lighting" txt:"ao"`
14
+
Fov int `toml:"fov" txt:"fov"`
15
+
}
16
+
)
17
+
18
+
func WriteOptions(options Options, path string) {
19
+
plainText := "version:9999\n"
20
+
21
+
reflectOptions := reflect.TypeOf(options)
22
+
23
+
for i := 0; i < reflectOptions.NumField(); i++ {
24
+
field := reflectOptions.Field(i)
25
+
26
+
txt := field.Tag.Get("txt")
27
+
if (txt == "") {
28
+
txt = field.Name
29
+
}
30
+
value := reflect.ValueOf(options).Field(i)
31
+
32
+
switch field.Type.Kind(){
33
+
case reflect.String:
34
+
plainText += txt + ":" + "\"" + value.String() + "\"\n"
35
+
case reflect.Int:
36
+
plainText += txt + ":" + strconv.Itoa(int(value.Int())) + "\n"
37
+
case reflect.Bool:
38
+
plainText += txt + ":" + strconv.FormatBool(value.Bool()) + "\n"
39
+
}
40
+
}
41
+
fmt.Print(plainText)
42
+
}