2020-01-26 00:39:13 -05:00
|
|
|
package d2datadict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2020-06-22 11:53:44 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-01-26 00:39:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// SoundEntry represents a sound entry
|
|
|
|
type SoundEntry struct {
|
|
|
|
Handle string
|
|
|
|
Index int
|
|
|
|
FileName string
|
|
|
|
Volume byte
|
|
|
|
GroupSize uint8
|
|
|
|
Loop bool
|
|
|
|
FadeIn uint8
|
|
|
|
FadeOut uint8
|
|
|
|
DeferInst uint8
|
|
|
|
StopInst uint8
|
|
|
|
Duration uint8
|
|
|
|
Compound int8
|
|
|
|
Reverb bool
|
|
|
|
Falloff uint8
|
|
|
|
Cache uint8
|
|
|
|
AsyncOnly bool
|
|
|
|
Priority uint8
|
|
|
|
Stream uint8
|
|
|
|
Stereo uint8
|
|
|
|
Tracking uint8
|
|
|
|
Solo uint8
|
|
|
|
MusicVol uint8
|
|
|
|
Block1 int
|
|
|
|
Block2 int
|
|
|
|
Block3 int
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSoundEntry creates a sound entry based on a sound row on sounds.txt
|
|
|
|
func createSoundEntry(soundLine string) SoundEntry {
|
|
|
|
props := strings.Split(soundLine, "\t")
|
|
|
|
i := -1
|
|
|
|
inc := func() int {
|
|
|
|
i++
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
result := SoundEntry{
|
|
|
|
Handle: props[inc()],
|
2020-06-22 11:53:44 -04:00
|
|
|
Index: d2common.StringToInt(props[inc()]),
|
2020-01-26 00:39:13 -05:00
|
|
|
FileName: props[inc()],
|
2020-06-22 11:53:44 -04:00
|
|
|
Volume: d2common.StringToUint8(props[inc()]),
|
|
|
|
GroupSize: d2common.StringToUint8(props[inc()]),
|
|
|
|
Loop: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
FadeIn: d2common.StringToUint8(props[inc()]),
|
|
|
|
FadeOut: d2common.StringToUint8(props[inc()]),
|
|
|
|
DeferInst: d2common.StringToUint8(props[inc()]),
|
|
|
|
StopInst: d2common.StringToUint8(props[inc()]),
|
|
|
|
Duration: d2common.StringToUint8(props[inc()]),
|
|
|
|
Compound: d2common.StringToInt8(props[inc()]),
|
|
|
|
Reverb: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Falloff: d2common.StringToUint8(props[inc()]),
|
|
|
|
Cache: d2common.StringToUint8(props[inc()]),
|
|
|
|
AsyncOnly: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Priority: d2common.StringToUint8(props[inc()]),
|
|
|
|
Stream: d2common.StringToUint8(props[inc()]),
|
|
|
|
Stereo: d2common.StringToUint8(props[inc()]),
|
|
|
|
Tracking: d2common.StringToUint8(props[inc()]),
|
|
|
|
Solo: d2common.StringToUint8(props[inc()]),
|
|
|
|
MusicVol: d2common.StringToUint8(props[inc()]),
|
|
|
|
Block1: d2common.StringToInt(props[inc()]),
|
|
|
|
Block2: d2common.StringToInt(props[inc()]),
|
|
|
|
Block3: d2common.StringToInt(props[inc()]),
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
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-01-26 00:39:13 -05:00
|
|
|
var Sounds map[string]SoundEntry
|
|
|
|
|
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-01-26 00:39:13 -05:00
|
|
|
Sounds = make(map[string]SoundEntry)
|
2020-01-31 23:18:11 -05:00
|
|
|
soundData := strings.Split(string(file), "\r\n")[1:]
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
for _, line := range soundData {
|
2020-06-29 12:37:11 -04:00
|
|
|
if line == "" {
|
2020-01-26 00:39:13 -05:00
|
|
|
continue
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
soundEntry := createSoundEntry(line)
|
|
|
|
soundEntry.FileName = "/data/global/sfx/" + strings.ReplaceAll(soundEntry.FileName, `\`, "/")
|
|
|
|
Sounds[soundEntry.Handle] = soundEntry
|
2020-06-29 12:37:11 -04:00
|
|
|
|
|
|
|
//nolint:gocritic // Debug util code
|
2020-01-26 00:39:13 -05:00
|
|
|
/*
|
|
|
|
// Use the following code to write out the values
|
|
|
|
f, err := os.OpenFile(`C:\Users\lunat\Desktop\D2\sounds.txt`,
|
|
|
|
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
if _, err := f.WriteString("\n[" + soundEntry.Handle + "] " + soundEntry.FileName); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
*/
|
2020-06-29 12:37:11 -04:00
|
|
|
} //nolint:wsl // Debug util code
|
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
log.Printf("Loaded %d sound definitions", len(Sounds))
|
|
|
|
}
|