2020-01-26 00:39:13 -05:00
|
|
|
package d2datadict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2020-09-08 15:58:35 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
2020-01-26 00:39:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// SoundEntry represents a sound entry
|
|
|
|
type SoundEntry struct {
|
|
|
|
Handle string
|
|
|
|
FileName string
|
2020-08-04 11:16:06 -04:00
|
|
|
Index int
|
2020-07-30 16:17:26 -04:00
|
|
|
Volume int
|
|
|
|
GroupSize int
|
|
|
|
FadeIn int
|
|
|
|
FadeOut int
|
|
|
|
Duration int
|
|
|
|
Compound int
|
|
|
|
Reverb int
|
|
|
|
Falloff int
|
2020-08-04 11:16:06 -04:00
|
|
|
Priority int
|
|
|
|
Block1 int
|
|
|
|
Block2 int
|
|
|
|
Block3 int
|
|
|
|
Loop bool
|
|
|
|
DeferInst bool
|
|
|
|
StopInst bool
|
2020-07-30 16:17:26 -04:00
|
|
|
Cache bool
|
2020-01-26 00:39:13 -05:00
|
|
|
AsyncOnly bool
|
2020-07-30 16:17:26 -04:00
|
|
|
Stream bool
|
|
|
|
Stereo bool
|
|
|
|
Tracking bool
|
|
|
|
Solo bool
|
|
|
|
MusicVol bool
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
// Sounds stores all of the SoundEntries
|
2020-06-29 12:37:11 -04:00
|
|
|
//nolint:gochecknoglobals // Currently global by design, only written once
|
2020-08-04 11:16:06 -04:00
|
|
|
var Sounds map[string]*SoundEntry
|
2020-01-26 00:39:13 -05:00
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
// LoadSounds loads SoundEntries from sounds.txt
|
2020-01-31 23:18:11 -05:00
|
|
|
func LoadSounds(file []byte) {
|
2020-08-04 11:16:06 -04:00
|
|
|
Sounds = make(map[string]*SoundEntry)
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-09-08 15:58:35 -04:00
|
|
|
d := d2txt.LoadDataDictionary(file)
|
2020-07-30 16:17:26 -04:00
|
|
|
for d.Next() {
|
2020-08-04 11:16:06 -04:00
|
|
|
entry := &SoundEntry{
|
2020-07-30 16:17:26 -04:00
|
|
|
Handle: d.String("Sound"),
|
|
|
|
Index: d.Number("Index"),
|
|
|
|
FileName: d.String("FileName"),
|
|
|
|
Volume: d.Number("Volume"),
|
|
|
|
GroupSize: d.Number("Group Size"),
|
|
|
|
Loop: d.Bool("Loop"),
|
|
|
|
FadeIn: d.Number("Fade In"),
|
|
|
|
FadeOut: d.Number("Fade Out"),
|
|
|
|
DeferInst: d.Bool("Defer Inst"),
|
|
|
|
StopInst: d.Bool("Stop Inst"),
|
|
|
|
Duration: d.Number("Duration"),
|
|
|
|
Compound: d.Number("Compound"),
|
|
|
|
Reverb: d.Number("Reverb"),
|
|
|
|
Falloff: d.Number("Falloff"),
|
|
|
|
Cache: d.Bool("Cache"),
|
|
|
|
AsyncOnly: d.Bool("Async Only"),
|
|
|
|
Priority: d.Number("Priority"),
|
|
|
|
Stream: d.Bool("Stream"),
|
|
|
|
Stereo: d.Bool("Stereo"),
|
|
|
|
Tracking: d.Bool("Tracking"),
|
|
|
|
Solo: d.Bool("Solo"),
|
|
|
|
MusicVol: d.Bool("Music Vol"),
|
|
|
|
Block1: d.Number("Block 1"),
|
|
|
|
Block2: d.Number("Block 2"),
|
|
|
|
Block3: d.Number("Block 3"),
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-07-30 16:17:26 -04:00
|
|
|
Sounds[entry.Handle] = entry
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-07-30 16:17:26 -04:00
|
|
|
if d.Err != nil {
|
|
|
|
panic(d.Err)
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
log.Printf("Loaded %d sound definitions", len(Sounds))
|
|
|
|
}
|
2020-07-30 16:17:26 -04:00
|
|
|
|
|
|
|
// SelectSoundByIndex selects a sound by its ID
|
|
|
|
func SelectSoundByIndex(index int) *SoundEntry {
|
2020-08-04 11:16:06 -04:00
|
|
|
for idx := range Sounds {
|
|
|
|
if Sounds[idx].Index == index {
|
|
|
|
return Sounds[idx]
|
2020-07-30 16:17:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|