Update Database

Database is more usable now.
All pages have been updated to use the database, and share an application configuration.
Page Stack has been removed, no more pages hanging around in memory. Replaced with a 'Router' which uses an Enum to determine which page should be displayed, destroys the old page and initializes the new page all in one go. No more push, pop, rollback, etc. No more holding instances of pages.
Logger has been updated with proper timestamps and sorting now works as expected."
This commit is contained in:
NeilClack
2026-03-23 15:02:07 -05:00
parent f8fbfb721d
commit 17c088cc2f
28 changed files with 537 additions and 2276 deletions
+13 -42
View File
@@ -60,7 +60,6 @@ import (
"fmt"
"math"
"path/filepath"
"strconv"
"strings"
"github.com/go-gl/gl/v3.3-core/gl"
@@ -194,7 +193,7 @@ type ScrollerPage struct {
hold float32
}
func (p *ScrollerPage) Init(app ApplicationInterface) error {
func (p *ScrollerPage) Init(ctx *PageCtx) error {
p.increment = 100.0
p.velocity = 800.0
p.SetAutoVelocity(true, -4000.0, 4000.0, 100.0, 2.5, 6.0)
@@ -209,7 +208,7 @@ func (p *ScrollerPage) Init(app ApplicationInterface) error {
}
p.font = font
p.Base.Init(app)
p.Base.Init(ctx)
// Get text shader
textShader, ok := sm.Get("text")
@@ -226,10 +225,8 @@ func (p *ScrollerPage) Init(app ApplicationInterface) error {
p.wordIndex = 0
// Get line pattern from database
linePatternName, err := db.GetConfigValue("line_pattern")
if err != nil {
return fmt.Errorf("retrieving line_pattern from db: %w", err)
}
var err error
linePatternName := p.Base.Context.CfgPtr.LinePattern
p.activePattern, err = linePattern.Get(linePatternName)
if err != nil {
@@ -249,23 +246,8 @@ func (p *ScrollerPage) Init(app ApplicationInterface) error {
p.colorPattern = colorPattern.NewColorPattern(baseColors)
// Get font sizes from database (optimize: load once, cache as int32)
standardFontSizeStr, err := db.GetConfigValue("standard_font_size")
if err != nil {
return fmt.Errorf("retrieving standard_font_size from db: %w", err)
}
standardFontSize, err := strconv.Atoi(standardFontSizeStr)
if err != nil {
return fmt.Errorf("parsing standard_font_size: %w", err)
}
baseFontSizeStr, err := db.GetConfigValue("init_font_size")
if err != nil {
return fmt.Errorf("retrieving init_font_size from db: %w", err)
}
baseFontSize, err := strconv.Atoi(baseFontSizeStr)
if err != nil {
return fmt.Errorf("parsing init_font_size: %w", err)
}
standardFontSize := p.Base.Context.CfgPtr.StandardFontSize
baseFontSize := p.Base.Context.CfgPtr.StandardFontSize
// Font setup (optimized: calculate once, reuse)
p.fontScale = float32(standardFontSize) / float32(baseFontSize)
@@ -302,10 +284,7 @@ func (p *ScrollerPage) Init(app ApplicationInterface) error {
}
// Audio setup
audioDeviceName, err := db.GetConfigValue("audio_device_name")
if err != nil {
return fmt.Errorf("retrieving audio_device_name from db: %w", err)
}
audioDeviceName := p.Base.Context.CfgPtr.SelectedAudioDevice
// Switch audio devices if needed
if mixer.CurrentDevice() != audioDeviceName {
@@ -315,19 +294,13 @@ func (p *ScrollerPage) Init(app ApplicationInterface) error {
}
// Start audio playback
selectedAudio, err := db.GetConfigValue("selected_audio")
if err != nil {
return fmt.Errorf("retrieving selected_audio from db: %w", err)
}
selectedAudio := p.Base.Context.CfgPtr.SelectedAudio
assetsDir, err := db.GetConfigValue("assets_dir")
if err != nil {
return fmt.Errorf("retrieving assets_dir from db: %w", err)
}
assetsDir := p.Base.Context.CfgPtr.AssetsDir
if selectedAudio == "" {
} else {
if err := mixer.Play(filepath.Join(assetsDir, selectedAudio), true); err != nil {
if err := mixer.Play(filepath.Join(assetsDir, selectedAudio), true, p.Base.Context.CfgPtr); err != nil {
}
}
@@ -344,10 +317,8 @@ func (p *ScrollerPage) loadProclamations() error {
p.words = []string{}
// Get all selected proclamations from database
proclamations, err := db.GetProclamations()
if err != nil {
return fmt.Errorf("retrieving proclamations from db: %w", err)
}
var proclamations []db.Proclamation
p.Base.Context.DbPtr.Find(&proclamations)
// Build word list from selected, available proclamations
for _, proclamation := range proclamations {
@@ -614,7 +585,7 @@ func (p *ScrollerPage) Destroy() error {
return nil
}
mixer.Stop(1000)
mixer.Stop(1000, p.Context.CfgPtr)
// GL cleanup — delete all text textures
for i := 0; i < p.lines.Len(); i++ {