rewrite using IoC and DI

This commit is contained in:
Aynakeya
2022-12-23 05:06:57 -08:00
parent 0498d2dbf3
commit c47d338a9e
88 changed files with 2295 additions and 1856 deletions

56
controller/core/lyric.go Normal file
View File

@@ -0,0 +1,56 @@
package core
import (
"AynaLivePlayer/common/event"
"AynaLivePlayer/model"
)
type LyricLoader struct {
Lyric *model.Lyric
Handler *event.Manager
prev float64
}
func NewLyricLoader() *LyricLoader {
return &LyricLoader{
Lyric: model.LoadLyric(""),
Handler: event.MainManager.NewChildManager(),
prev: -1,
}
}
func (l *LyricLoader) EventManager() *event.Manager {
return l.Handler
}
func (l *LyricLoader) Get() *model.Lyric {
return l.Lyric
}
func (l *LyricLoader) Reload(lyric string) {
l.Lyric = model.LoadLyric(lyric)
l.Handler.CallA(
model.EventLyricReload,
model.LyricReloadEvent{
Lyrics: l.Lyric,
})
}
func (l *LyricLoader) Update(time float64) {
lrc := l.Lyric.Find(time)
if lrc == nil {
return
}
if l.prev == lrc.Time {
return
}
l.prev = lrc.Time
l.Handler.CallA(
model.EventLyricUpdate,
model.LyricUpdateEvent{
Lyrics: l.Lyric,
Time: time,
Lyric: lrc,
})
return
}