Refactored player integration, using go:build tag

pull/34/head
マリウス 2 years ago
parent 81ea9afa7c
commit 5059616e32
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

@ -0,0 +1,17 @@
//go:build !poolsuite
package common
type Player struct {
}
func NewPlayer() (*Player) {
player := new(Player)
return player
}
func (p *Player) Play() {
return
}

@ -0,0 +1,47 @@
//go:build poolsuite
package common
import(
"github.com/mrusme/go-poolsuite"
)
type Player struct {
Poolsuite *poolsuite.Poolsuite
poolsuiteLoaded bool
poolsuitePlaying bool
}
func NewPlayer() (*Player) {
player := new(Player)
player.Poolsuite = poolsuite.NewPoolsuite()
player.poolsuiteLoaded = false
player.poolsuitePlaying = false
return player
}
func (p *Player) poolsuitePlay() {
p.Poolsuite.Play(
p.Poolsuite.GetRandomTrackFromPlaylist(
p.Poolsuite.GetRandomPlaylist(),
),
func() { p.poolsuitePlay() },
)
}
func (p *Player) Play() {
if p.poolsuiteLoaded == false {
p.poolsuiteLoaded = true
p.Poolsuite.Load()
}
if p.poolsuitePlaying == false {
p.poolsuitePlay()
p.poolsuitePlaying = true
} else {
p.Poolsuite.PauseResume()
p.poolsuitePlaying = false
}
}

@ -7,8 +7,8 @@ import (
"unicode"
"github.com/gdamore/tcell/v2"
"github.com/mrusme/go-poolsuite"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/common"
"github.com/mrusme/superhighway84/config"
"github.com/mrusme/superhighway84/models"
"github.com/rivo/tview"
@ -40,9 +40,7 @@ type TUI struct {
VersionLatest string
// The fun starts here
Poolsuite *poolsuite.Poolsuite
poolsuiteLoaded bool
poolsuitePlaying bool
Player *common.Player
}
type View interface {
@ -97,21 +95,10 @@ func Init(embedfs *embed.FS, cfg *config.Config, cch *cache.Cache, logger *zap.L
t.initInput()
// The fun stuff
t.Poolsuite = poolsuite.NewPoolsuite()
t.poolsuiteLoaded = false
t.poolsuitePlaying = false
t.Player = common.NewPlayer()
return t
}
func (t *TUI) poolsuitePlay() {
t.Poolsuite.Play(
t.Poolsuite.GetRandomTrackFromPlaylist(
t.Poolsuite.GetRandomPlaylist(),
),
func() { t.poolsuitePlay() },
)
}
func (t *TUI) initInput() {
t.App.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
@ -123,18 +110,7 @@ func (t *TUI) initInput() {
t.App.Stop()
return nil
case tcell.KeyF8:
if t.poolsuiteLoaded == false {
t.poolsuiteLoaded = true
t.Poolsuite.Load()
}
if t.poolsuitePlaying == false {
t.poolsuitePlay()
t.poolsuitePlaying = true
} else {
t.Poolsuite.PauseResume()
t.poolsuitePlaying = false
}
t.Player.Play()
return nil
default:
if t.ModalVisible == true {

Loading…
Cancel
Save