From 78470431d67f2c2235c99e3deb74e876ea3ff315 Mon Sep 17 00:00:00 2001 From: Huw Griffiths Date: Wed, 29 Jul 2020 06:34:01 +1000 Subject: [PATCH] d2datadict: Add Montype.txt loader (#637) --- d2app/app.go | 1 + d2common/d2data/d2datadict/montype.go | 48 +++++++++++++++++++++++++++ d2common/d2resource/resource_paths.go | 1 + 3 files changed, 50 insertions(+) create mode 100644 d2common/d2data/d2datadict/montype.go diff --git a/d2app/app.go b/d2app/app.go index 80a5325a..ca5b4eb1 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -223,6 +223,7 @@ func (a *App) loadDataDict() error { {d2resource.MonStats2, d2datadict.LoadMonStats2}, {d2resource.MonPreset, d2datadict.LoadMonPresets}, {d2resource.MonProp, d2datadict.LoadMonProps}, + {d2resource.MonType, d2datadict.LoadMonTypes}, {d2resource.MagicPrefix, d2datadict.LoadMagicPrefix}, {d2resource.MagicSuffix, d2datadict.LoadMagicSuffix}, {d2resource.ItemStatCost, d2datadict.LoadItemStatCosts}, diff --git a/d2common/d2data/d2datadict/montype.go b/d2common/d2data/d2datadict/montype.go new file mode 100644 index 00000000..e007f2fb --- /dev/null +++ b/d2common/d2data/d2datadict/montype.go @@ -0,0 +1,48 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +// MonTypeRecord is a representation of a single row of MonType.txt. +type MonTypeRecord struct { + Type string + Equiv1 string + Equiv2 string + Equiv3 string + // StrSing is the string displayed for the singular form (Skeleton), note + // that this is unused in the original engine, since the only modifier + // display code that accesses MonType uses StrPlur. + StrSing string + StrPlural string + // EOL int // unused +} + +// MonTypes stores all of the MonTypeRecords +var MonTypes map[string]*MonTypeRecord //nolint:gochecknoglobals // Currently global by design, only written once + +// LoadMonTypes loads MonType records into a map[string]*MonTypeRecord +func LoadMonTypes(file []byte) { + MonTypes = make(map[string]*MonTypeRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &MonTypeRecord{ + Type: d.String("type"), + Equiv1: d.String("equiv1"), + Equiv2: d.String("equiv2"), + Equiv3: d.String("equiv3"), + StrSing: d.String("strsing"), + StrPlural: d.String("strplur"), + } + MonTypes[record.Type] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d MonType records", len(MonTypes)) +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 69318201..76187e7d 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -301,6 +301,7 @@ const ( MonStats = "/data/global/excel/monstats.txt" MonStats2 = "/data/global/excel/monstats2.txt" MonPreset = "/data/global/excel/monpreset.txt" + MonType = "/data/global/excel/Montype.txt" SuperUniques = "/data/global/excel/SuperUniques.txt" // --- Skill Data ---