From 6514fd15def21bba3ac5dbf3a74fd4151339273c Mon Sep 17 00:00:00 2001 From: AndrejMijic <44673317+AndrejMijic@users.noreply.github.com> Date: Sat, 1 Aug 2020 23:55:34 +0200 Subject: [PATCH] Add monseq.txt loader (#664) --- d2app/app.go | 1 + .../d2data/d2datadict/monster_sequence.go | 67 +++++++++++++++++++ d2common/d2enum/animation_frame_direction.go | 15 +++++ d2common/d2enum/animation_frame_event.go | 12 ++++ d2common/d2resource/resource_paths.go | 1 + 5 files changed, 96 insertions(+) create mode 100644 d2common/d2data/d2datadict/monster_sequence.go create mode 100644 d2common/d2enum/animation_frame_direction.go create mode 100644 d2common/d2enum/animation_frame_event.go diff --git a/d2app/app.go b/d2app/app.go index 43a8c0d3..f839a3be 100644 --- a/d2app/app.go +++ b/d2app/app.go @@ -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() diff --git a/d2common/d2data/d2datadict/monster_sequence.go b/d2common/d2data/d2datadict/monster_sequence.go new file mode 100644 index 00000000..4763a770 --- /dev/null +++ b/d2common/d2data/d2datadict/monster_sequence.go @@ -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)) +} diff --git a/d2common/d2enum/animation_frame_direction.go b/d2common/d2enum/animation_frame_direction.go new file mode 100644 index 00000000..753a106b --- /dev/null +++ b/d2common/d2enum/animation_frame_direction.go @@ -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 +) diff --git a/d2common/d2enum/animation_frame_event.go b/d2common/d2enum/animation_frame_event.go new file mode 100644 index 00000000..d7de09c6 --- /dev/null +++ b/d2common/d2enum/animation_frame_event.go @@ -0,0 +1,12 @@ +package d2enum + +// AnimationFrameEvent enumerates events used in d2datadict.MonsterSequenceFrame +type AnimationFrameEvent int + +const ( + NoEvent AnimationFrameEvent = iota + MeleeAttack + MissileAttack + PlaySound + LaunchSpell +) diff --git a/d2common/d2resource/resource_paths.go b/d2common/d2resource/resource_paths.go index 13a6dfd9..b79b8031 100644 --- a/d2common/d2resource/resource_paths.go +++ b/d2common/d2resource/resource_paths.go @@ -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 ---