1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-29 14:45:58 -04:00
OpenDiablo2/d2common/d2data/d2datadict/sounds.go
Haashi 5e1725dd7d
385/lintissues (#391)
* camera offset for ui panels :

added maprenderer viewport to be aligned left or right

calling alignement on keyPress in game_controls

* check if already aligned

* fix bugs

-forgot to assign alignement
-defaultScreenRect instead of screenRect because of issue mentionned in original comment

* remove config.json and replace go.mod line

* removing duplicate import of d2common

replacing all dh to d2common

* remove useless breaks from switch statement

* better range when value unused + prettying import

* item_affix rewrite

using return values instead of pointer references in arguments

* ebiten deprecated calls

* small fixes
2020-06-22 11:53:44 -04:00

104 lines
2.8 KiB
Go

package d2datadict
import (
"log"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// 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()],
Index: d2common.StringToInt(props[inc()]),
FileName: props[inc()],
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()]),
}
return result
}
var Sounds map[string]SoundEntry
func LoadSounds(file []byte) {
Sounds = make(map[string]SoundEntry)
soundData := strings.Split(string(file), "\r\n")[1:]
for _, line := range soundData {
if len(line) == 0 {
continue
}
soundEntry := createSoundEntry(line)
soundEntry.FileName = "/data/global/sfx/" + strings.ReplaceAll(soundEntry.FileName, `\`, "/")
Sounds[soundEntry.Handle] = soundEntry
/*
// 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)
}
*/
}
log.Printf("Loaded %d sound definitions", len(Sounds))
}