64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package widgets
|
|
|
|
import (
|
|
"ArinDash/util"
|
|
"ArinDash/widgets/zukitchi"
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/mum4k/termdash/cell"
|
|
"github.com/mum4k/termdash/terminal/terminalapi"
|
|
"github.com/mum4k/termdash/widgetapi"
|
|
"github.com/mum4k/termdash/widgets/text"
|
|
)
|
|
|
|
type ZukitchiOptions struct {
|
|
}
|
|
|
|
func Zukitchi() ZukitchiOptions {
|
|
widgetOptions["ZukitchiOptions"] = createZukitchi
|
|
return ZukitchiOptions{}
|
|
|
|
}
|
|
|
|
var lastFrame = time.Now()
|
|
|
|
var pet = zukitchi.New()
|
|
|
|
func createZukitchi(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
|
widget := util.PanicOnErrorWithResult(text.New())
|
|
go util.Periodic(ctx, 1*time.Minute, pet.Run())
|
|
go util.Periodic(ctx, util.RedrawInterval, func() error {
|
|
return draw(widget)
|
|
})
|
|
|
|
return widget
|
|
}
|
|
|
|
func draw(widget *text.Text) error {
|
|
if time.Since(lastFrame) < 1*time.Second {
|
|
return nil
|
|
}
|
|
widget.Reset()
|
|
if err := widget.Write(pet.NextFrame(), text.WriteCellOpts(cell.FgColor(cell.ColorBlack), cell.BgColor(cell.ColorGreen))); err != nil {
|
|
return err
|
|
}
|
|
lastFrame = time.Now()
|
|
return nil
|
|
}
|
|
|
|
func ChangeMood(mood string) {
|
|
pet.ChangeMood(mood)
|
|
go func() {
|
|
ticker := time.NewTicker(10 * time.Second)
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
pet.ChangeMood("idle")
|
|
ticker.Stop()
|
|
}
|
|
}
|
|
}()
|
|
|
|
}
|