From a31fb173eb76c80f3a10398acaed53bf6f25948d Mon Sep 17 00:00:00 2001 From: Huw Griffiths Date: Wed, 29 Jul 2020 22:38:34 +1000 Subject: [PATCH] d2datadict: Add Monmode.txt loader (#638) --- d2app/app.go | 1 + d2common/d2data/d2datadict/monmode.go | 38 +++++++++++++++++++++++++++ d2common/d2resource/resource_paths.go | 1 + 3 files changed, 40 insertions(+) create mode 100644 d2common/d2data/d2datadict/monmode.go diff --git a/d2app/app.go b/d2app/app.go index 5e694128..5a100683 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -224,6 +224,7 @@ func (a *App) loadDataDict() error { {d2resource.MonPreset, d2datadict.LoadMonPresets}, {d2resource.MonProp, d2datadict.LoadMonProps}, {d2resource.MonType, d2datadict.LoadMonTypes}, + {d2resource.MonMode, d2datadict.LoadMonModes}, {d2resource.MagicPrefix, d2datadict.LoadMagicPrefix}, {d2resource.MagicSuffix, d2datadict.LoadMagicSuffix}, {d2resource.ItemStatCost, d2datadict.LoadItemStatCosts}, diff --git a/d2common/d2data/d2datadict/monmode.go b/d2common/d2data/d2datadict/monmode.go new file mode 100644 index 00000000..10c3c662 --- /dev/null +++ b/d2common/d2data/d2datadict/monmode.go @@ -0,0 +1,38 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +// MonModeRecord is a representation of a single row of Monmode.txt +type MonModeRecord struct { + Name string + Token string + Code string +} + +// MonModes stores all of the GemsRecords +var MonModes map[string]*MonModeRecord //nolint:gochecknoglobals // Currently global by design, only written once + +// LoadMonModes loads gem records into a map[string]*MonModeRecord +func LoadMonModes(file []byte) { + MonModes = make(map[string]*MonModeRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &MonModeRecord{ + Name: d.String("name"), + Token: d.String("token"), + Code: d.String("code"), + } + MonModes[record.Name] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d MonMode records", len(MonModes)) +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 710781a7..134cf550 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -304,6 +304,7 @@ const ( MonPreset = "/data/global/excel/monpreset.txt" MonType = "/data/global/excel/Montype.txt" SuperUniques = "/data/global/excel/SuperUniques.txt" + MonMode = "/data/global/excel/monmode.txt" // --- Skill Data ---