36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type CurrencyWarsNodeDrop struct {
|
|
Rolls uint32 `json:"rolls"`
|
|
Weights map[string]uint32 `json:"weights"`
|
|
}
|
|
|
|
type CurrencyWarsNodeDropsCatalog struct {
|
|
FormatVersion uint32 `json:"format_version"`
|
|
TargetClientVersion string `json:"target_client_version"`
|
|
TargetAssemblySHA256 string `json:"target_assembly_sha256"`
|
|
NodeDrops map[string]CurrencyWarsNodeDrop `json:"node_drops"`
|
|
}
|
|
|
|
func LoadCurrencyWarsNodeDrops(catalog *CurrencyWarsCatalog) (*CurrencyWarsNodeDropsCatalog, error) {
|
|
raw, err := ReadResourceFile("resources/CurrencyWarsNodeDrops.json")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var out CurrencyWarsNodeDropsCatalog
|
|
if err = json.Unmarshal(raw, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if catalog != nil {
|
|
if out.FormatVersion != 1 || out.TargetClientVersion != catalog.ClientVersion || out.TargetAssemblySHA256 != catalog.Provenance.GameAssemblySHA256 {
|
|
return nil, fmt.Errorf("CW node drops revision differs from catalog")
|
|
}
|
|
}
|
|
return &out, nil
|
|
}
|