Store your Minecraft configs with your other dotfiles, and load it automatically.

feat: options loading poc using reflection

Changed files
+52 -2
config
minecraft
+5
config.toml
··· 1 + [options] 2 + main_hand = "left" 3 + ao = false 4 + fov = 1 5 + 1 6 [mods] 2 7 sodium = "AANobbMI" 3 8 fabric-api = "P7dR8mSH"
+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 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
··· 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 + }