mirror of
https://github.com/packwiz/packwiz.git
synced 2025-11-19 01:24:32 +01:00
Mod loading, disgusting struct parsing
This commit is contained in:
30
core/mod.go
30
core/mod.go
@@ -1,5 +1,9 @@
|
||||
package core
|
||||
import "github.com/BurntSushi/toml"
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
|
||||
type Mod struct {
|
||||
@@ -13,7 +17,7 @@ type Mod struct {
|
||||
HashFormat string `toml:"hash-format"`
|
||||
Hash string `toml:"hash"`
|
||||
} `toml:"download"`
|
||||
Update map[string]toml.Primitive `toml:"update"`
|
||||
Update map[string]interface{} `toml:"update"`
|
||||
}
|
||||
|
||||
// The three possible values of Side (the side that the mod is on) are "server", "client", and "both".
|
||||
@@ -23,6 +27,28 @@ const (
|
||||
UniversalSide = "both"
|
||||
)
|
||||
|
||||
// LoadMod attempts to load a mod file from a path
|
||||
func LoadMod(modFile string) (Mod, error) {
|
||||
var mod Mod
|
||||
if _, err := toml.DecodeFile(modFile, &mod); err != nil {
|
||||
return Mod{}, err
|
||||
}
|
||||
// Horrible reflection library to convert to Updaters
|
||||
for k, v := range mod.Update {
|
||||
updateParser, ok := UpdateParsers[k]
|
||||
if ok {
|
||||
updater, err := updateParser.ParseUpdate(v)
|
||||
if err != nil {
|
||||
return mod, err
|
||||
}
|
||||
mod.Update[k] = updater
|
||||
} else {
|
||||
return mod, errors.New("Update plugin " + k + " not found!")
|
||||
}
|
||||
}
|
||||
return mod, nil
|
||||
}
|
||||
|
||||
func (m Mod) Write() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user