Downloads are working and the goroutine is reporting updates appropriately.
This commit is contained in:
+56
-12
@@ -2,12 +2,14 @@ package page
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
"github.com/go-gl/mathgl/mgl32"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"rhemawavetech.com/rhemawave/internal/colors"
|
||||
"rhemawavetech.com/rhemawave/internal/download"
|
||||
"rhemawavetech.com/rhemawave/internal/fontManager"
|
||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||
)
|
||||
@@ -16,16 +18,20 @@ var GitVersion = "1.0"
|
||||
|
||||
type Home struct {
|
||||
Base
|
||||
title StringItem
|
||||
version StringItem
|
||||
prompt StringItem
|
||||
note StringItem
|
||||
licenseInfoHeading StringItem
|
||||
emailDisplay StringItem
|
||||
licenseKeyDisplay StringItem
|
||||
hasLicenseInfo bool
|
||||
lastDisplayUpdate time.Time
|
||||
baseFontSize int // cached from db at init
|
||||
fm *fontManager.FontManager
|
||||
font *fontManager.FontEntry
|
||||
title StringItem
|
||||
version StringItem
|
||||
prompt StringItem
|
||||
note StringItem
|
||||
message StringItem
|
||||
downloadProgressChan chan download.DownloadStatus
|
||||
licenseInfoHeading StringItem
|
||||
emailDisplay StringItem
|
||||
licenseKeyDisplay StringItem
|
||||
hasLicenseInfo bool
|
||||
lastDisplayUpdate time.Time
|
||||
baseFontSize int // cached from db at init
|
||||
}
|
||||
|
||||
// Init performs basic page initialization and creation of static assets.
|
||||
@@ -40,11 +46,12 @@ func (p *Home) Init(ctx *PageCtx) error {
|
||||
}
|
||||
|
||||
// Get font
|
||||
fm := fontManager.Get()
|
||||
font, ok := fm.GetFont("Roboto-Regular")
|
||||
p.fm = fontManager.Get()
|
||||
font, ok := p.fm.GetFont("Roboto-Regular")
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to fetch font")
|
||||
}
|
||||
p.font = font
|
||||
|
||||
// Create title texture
|
||||
var err error
|
||||
@@ -72,6 +79,9 @@ func (p *Home) Init(ctx *PageCtx) error {
|
||||
return fmt.Errorf("unable to create note string texture: %w", err)
|
||||
}
|
||||
|
||||
// Create download channel and message
|
||||
p.downloadProgressChan = make(chan download.DownloadStatus)
|
||||
|
||||
// Create license info textures if data exists
|
||||
if p.Context.CfgPtr.EmailAddress != "" || p.Context.CfgPtr.LicenseKey != "" {
|
||||
p.hasLicenseInfo = true
|
||||
@@ -123,6 +133,25 @@ func (p *Home) Init(ctx *PageCtx) error {
|
||||
}
|
||||
}
|
||||
|
||||
audioFileNames := []string{
|
||||
"OriginalAudio.wav",
|
||||
"174Hz.wav",
|
||||
"396Hz.wav",
|
||||
"417Hz.wav",
|
||||
"432Hz.wav",
|
||||
"639Hz.wav",
|
||||
"741Hz.wav",
|
||||
"852Hz.wav",
|
||||
"963Hz.wav",
|
||||
"1111Hz.wav",
|
||||
"14Hz_Binaural.wav",
|
||||
"40Hz_Binaural.wav",
|
||||
"AlphaWaves.wav",
|
||||
"PinealGland.wav",
|
||||
}
|
||||
|
||||
go download.DownloadAudioFiles(p.downloadProgressChan, audioFileNames, filepath.Join(ctx.CfgPtr.AssetsDir, "audio"))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -133,6 +162,21 @@ func (p *Home) HandleEvent(event *sdl.Event) error {
|
||||
|
||||
// Update updates animations and changing textures and other changes using `dt` which represents a time delta in float32.
|
||||
func (p *Home) Update(dt float32) error {
|
||||
var err error
|
||||
|
||||
select {
|
||||
case progressUpdate := <-p.downloadProgressChan:
|
||||
if progressUpdate.Err != nil {
|
||||
p.message, err = NewStringItem(progressUpdate.Msg, p.font, colors.White)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
p.message, err = NewStringItem(progressUpdate.Err.Error(), p.font, colors.Red)
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user