1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-05 08:07:51 -05:00

Added loaders for compcodes.txt, events.txt and monai.txt (#665)

* added loaders for compcodes.txt, events.txt and monai.txt

* fixes in response to PR comments

Co-authored-by: BojanoN <bojan.novkovic@kset.org>
This commit is contained in:
Bojan Novković 2020-08-03 03:27:33 +02:00 committed by GitHub
parent efb554c42b
commit 0e1b30b91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package d2datadict
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
type ComponentCodeRecord struct {
Component string
Code string
}
var ComponentCodes map[string]*ComponentCodeRecord
func LoadComponentCodes(file []byte) {
ComponentCodes = make(map[string]*ComponentCodeRecord)
d := d2common.LoadDataDictionary(file)
for d.Next() {
record := &ComponentCodeRecord{
Component: d.String("component"),
Code: d.String("code"),
}
ComponentCodes[record.Component] = record
}
if d.Err != nil {
panic(d.Err)
}
log.Printf("Loaded %d ComponentCode records", len(ComponentCodes))
}

View File

@ -0,0 +1,32 @@
package d2datadict
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
type EventRecord struct {
Event string
}
var Events map[string]*EventRecord
func LoadEvents(file []byte) {
Events = make(map[string]*EventRecord)
d := d2common.LoadDataDictionary(file)
for d.Next() {
record := &EventRecord{
Event: d.String("event"),
}
Events[record.Event] = record
}
if d.Err != nil {
panic(d.Err)
}
log.Printf("Loaded %d Event records", len(Events))
}

View File

@ -0,0 +1,33 @@
package d2datadict
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// The monai.txt file is a lookup table for unit AI codes
type MonsterAIRecord struct {
AI string
}
var MonsterAI map[string]*MonsterAIRecord
func LoadMonsterAI(file []byte) {
MonsterAI = make(map[string]*MonsterAIRecord)
d := d2common.LoadDataDictionary(file)
for d.Next() {
record := &MonsterAIRecord{
AI: d.String("AI"),
}
MonsterAI[record.AI] = record
}
if d.Err != nil {
panic(d.Err)
}
log.Printf("Loaded %d MonsterAI records", len(MonsterAI))
}