From a1ea22c81fcb887403269c4a1c530171474e84e5 Mon Sep 17 00:00:00 2001 From: AndrejMijic <44673317+AndrejMijic@users.noreply.github.com> Date: Thu, 30 Jul 2020 08:41:19 +0200 Subject: [PATCH] Add reading of ElemTypes.txt (#644) --- d2app/app.go | 1 + d2common/d2data/d2datadict/elemtype.go | 39 ++++++++++++++++++++++++++ d2common/d2resource/resource_paths.go | 1 + 3 files changed, 41 insertions(+) create mode 100644 d2common/d2data/d2datadict/elemtype.go diff --git a/d2app/app.go b/d2app/app.go index 0a00f9ff..11f350cb 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -255,6 +255,7 @@ func (a *App) loadDataDict() error { {d2resource.States, d2datadict.LoadStates}, {d2resource.SoundEnvirons, d2datadict.LoadSoundEnvirons}, {d2resource.Shrines, d2datadict.LoadShrines}, + {d2resource.ElemType, d2datadict.LoadElemTypes}, } d2datadict.InitObjectRecords() diff --git a/d2common/d2data/d2datadict/elemtype.go b/d2common/d2data/d2datadict/elemtype.go new file mode 100644 index 00000000..02297dea --- /dev/null +++ b/d2common/d2data/d2datadict/elemtype.go @@ -0,0 +1,39 @@ +package d2datadict + +import ( + "log" + + "github.com/OpenDiablo2/OpenDiablo2/d2common" +) + +//ElemTypeRecord represents a single line in ElemType.txt +type ElemTypeRecord struct { + //Elemental damage type name + ElemType string + + //Elemental damage type code + Code string +} + +//ElemTypes stores the ElemTypeRecords +var ElemTypes map[string]*ElemTypeRecord //nolint:gochecknoglobals // Currently global by design + +//LoadElemTypes loads ElemTypeRecords into ElemTypes +func LoadElemTypes(file []byte) { + ElemTypes = make(map[string]*ElemTypeRecord) + + d := d2common.LoadDataDictionary(file) + for d.Next() { + record := &ElemTypeRecord{ + ElemType: d.String("Elemental Type"), + Code: d.String("Code"), + } + ElemTypes[record.ElemType] = record + } + + if d.Err != nil { + panic(d.Err) + } + + log.Printf("Loaded %d ElemType records", len(ElemTypes)) +} diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index db9691c2..0373f267 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -199,6 +199,7 @@ const ( SoundEnvirons = "/data/global/excel/soundenviron.txt" Shrines = "/data/global/excel/shrines.txt" MonProp = "/data/global/excel/Monprop.txt" + ElemType = "/data/global/excel/ElemTypes.txt" // --- Animations ---