Add monseq.txt loader (#664)

This commit is contained in:
AndrejMijic 2020-08-01 23:55:34 +02:00 committed by GitHub
parent 39ab8d19f5
commit 6514fd15de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 0 deletions

View File

@ -268,6 +268,7 @@ func (a *App) loadDataDict() error {
{d2resource.UniqueAppellation, d2datadict.LoadUniqueAppellations},
{d2resource.MonsterLevel, d2datadict.LoadMonsterLevels},
{d2resource.MonsterSound, d2datadict.LoadMonsterSounds},
{d2resource.MonsterSequence, d2datadict.LoadMonsterSequences},
}
d2datadict.InitObjectRecords()

View File

@ -0,0 +1,67 @@
package d2datadict
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
//MonsterSequenceRecord contains a record for a monster sequence
//Composed of multiple lines from monseq.txt with the same name in the first column.
//Information gathered from [https://d2mods.info/forum/kb/viewarticle?a=395]
type MonsterSequenceRecord struct {
//The sequence name, refered to by monstats.txt
Name string
//The frames of this sequence
Frames []*MonsterSequenceFrame
}
//MonsterSequenceFrame represents a single frame of a monster sequence
type MonsterSequenceFrame struct {
//The animation mode for this frame (refers to MonMode.txt)
Mode string
//The frame of the animation mode used for this frame of the sequence
Frame int
//The direction of the frame, enumerated by d2enum.AnimationFrameDirection
Direction int
//Event trigerred by this frame
Event int
}
//MonsterSequences contains the MonsterSequenceRecords
var MonsterSequences map[string]*MonsterSequenceRecord
//LoadMonsterSequences loads the MonsterSequenceRecords into MonsterSequences
func LoadMonsterSequences(file []byte) {
MonsterSequences = make(map[string]*MonsterSequenceRecord)
d := d2common.LoadDataDictionary(file)
for d.Next() {
name := d.String("sequence")
if _, ok := MonsterSequences[name]; !ok {
record := &MonsterSequenceRecord{
Name: name,
Frames: make([]*MonsterSequenceFrame, 0),
}
MonsterSequences[name] = record
}
MonsterSequences[name].Frames = append(MonsterSequences[name].Frames, &MonsterSequenceFrame{
Mode: d.String("mode"),
Frame: d.Number("frame"),
Direction: d.Number("dir"),
Event: d.Number("event"),
})
}
if d.Err != nil {
panic(d.Err)
}
log.Printf("Loaded %d MonsterSequence records", len(MonsterSequences))
}

View File

@ -0,0 +1,15 @@
package d2enum
// AnimationFrameDirection enumerates animation frame directions used in d2datadict.MonsterSequenceFrame
type AnimationFrameDirection int
const (
SouthWest AnimationFrameDirection = iota
NorthWest
NorthEast
SouthEast
South
West
North
East
)

View File

@ -0,0 +1,12 @@
package d2enum
// AnimationFrameEvent enumerates events used in d2datadict.MonsterSequenceFrame
type AnimationFrameEvent int
const (
NoEvent AnimationFrameEvent = iota
MeleeAttack
MissileAttack
PlaySound
LaunchSpell
)

View File

@ -212,6 +212,7 @@ const (
UniqueAppellation = "/data/global/excel/UniqueAppellation.txt"
MonsterLevel = "/data/global/excel/monlvl.txt"
MonsterSound = "/data/global/excel/monsounds.txt"
MonsterSequence = "/data/global/excel/monseq.txt"
// --- Animations ---