Get view-menu to play the interface sound
This commit is contained in:
@@ -32,9 +32,10 @@ type AssetStore struct {
|
||||
entries entryMap
|
||||
|
||||
// These members are used to store things we've already loaded
|
||||
maps map[string]*Map
|
||||
objs map[string]*Object
|
||||
sets map[string]*Set
|
||||
maps map[string]*Map
|
||||
objs map[string]*Object
|
||||
sets map[string]*Set
|
||||
sounds map[string]*Sound
|
||||
}
|
||||
|
||||
// New returns a new AssetStore
|
||||
@@ -82,6 +83,7 @@ func (a *AssetStore) Refresh() error {
|
||||
a.maps = make(map[string]*Map)
|
||||
a.objs = make(map[string]*Object)
|
||||
a.sets = make(map[string]*Set)
|
||||
a.sounds = make(map[string]*Sound)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
78
internal/assetstore/sound.go
Normal file
78
internal/assetstore/sound.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package assetstore
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/audio"
|
||||
"github.com/hajimehoshi/ebiten/audio/vorbis"
|
||||
)
|
||||
|
||||
type Sound struct {
|
||||
Name string
|
||||
|
||||
filename string
|
||||
}
|
||||
|
||||
func (a *AssetStore) Sound(name string) (*Sound, error) {
|
||||
name = canonical(name)
|
||||
|
||||
if sound, ok := a.sounds[name]; ok {
|
||||
return sound, nil
|
||||
}
|
||||
|
||||
// TODO: Data/Sounds.dat + Sounds/wh40k.ds seem to operate together to allow
|
||||
// attributes and a .wav file to be attached to event names, which could be
|
||||
// what we use here instead. For now, we're just using the .wav files!
|
||||
log.Printf("Loading sound %v", name)
|
||||
|
||||
// FIXME: a preprocessing script is used to create these files from the
|
||||
// original ADPCM .wav files. Instead, use the original .wav files.
|
||||
filename, err := a.lookup(name, "wav.ogg", "Wav")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sound := &Sound{
|
||||
Name: name,
|
||||
filename: filename,
|
||||
}
|
||||
|
||||
a.sounds[name] = sound
|
||||
return sound, nil
|
||||
}
|
||||
|
||||
func (s *Sound) Player() (*audio.Player, error) {
|
||||
decoder, err := s.decoder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return audio.NewPlayer(audio.CurrentContext(), decoder)
|
||||
}
|
||||
|
||||
func (s *Sound) InfinitePlayer() (*audio.Player, error) {
|
||||
decoder, err := s.decoder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
infinite := audio.NewInfiniteLoop(decoder, decoder.Size())
|
||||
|
||||
return audio.NewPlayer(audio.CurrentContext(), infinite)
|
||||
}
|
||||
|
||||
func (s *Sound) decoder() (*vorbis.Stream, error) {
|
||||
f, err := os.Open(s.filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
decoder, err := vorbis.Decode(audio.CurrentContext(), f)
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return decoder, nil
|
||||
}
|
Reference in New Issue
Block a user