Made loading of audio samples more graceful (game will play without them).
This commit is contained in:
parent
3c99e5881b
commit
0d49482036
1
TODO.md
1
TODO.md
@ -12,3 +12,4 @@
|
||||
- [ ] Add exploding animation of monsters.
|
||||
- [ ] Add audio settings (music & sound volume).
|
||||
- [X] Hearts must be saved as well for resume.
|
||||
- [ ] Add demo mode.
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"opslag.de/schobers/tins2021"
|
||||
"opslag.de/schobers/zntg/play"
|
||||
"opslag.de/schobers/zntg/ui"
|
||||
@ -73,7 +75,7 @@ func (a *app) Init(ctx ui.Context) error {
|
||||
"player_move.mp3",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("failed to load samples; %v\n", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"github.com/faiface/beep/effects"
|
||||
"github.com/faiface/beep/mp3"
|
||||
"github.com/faiface/beep/speaker"
|
||||
"github.com/pkg/errors"
|
||||
"opslag.de/schobers/ut"
|
||||
"opslag.de/schobers/zntg/ui"
|
||||
)
|
||||
|
||||
@ -39,12 +41,16 @@ func NewAudioPlayer(resources ui.Resources, prefix string) *AudioPlayer {
|
||||
}
|
||||
|
||||
func (p *AudioPlayer) LoadSample(name ...string) error {
|
||||
var all error
|
||||
for _, name := range name {
|
||||
if _, err := p.openSample(name); err != nil {
|
||||
return err
|
||||
all = ut.ErrCombine(all, errors.Wrap(err, "failed to open sample"))
|
||||
}
|
||||
}
|
||||
if all == nil {
|
||||
return nil
|
||||
}
|
||||
return errors.WithMessage(all, "failed to open one or more samples")
|
||||
}
|
||||
|
||||
func (p *AudioPlayer) openSample(name string) (Sample, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user