1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-16 06:25:23 +00:00
neonmodem/ui/ctx/ctx.go

70 lines
1.2 KiB
Go
Raw Normal View History

2022-12-29 03:22:36 +00:00
package ctx
import (
2023-01-07 00:41:28 +00:00
"embed"
2023-01-07 00:46:41 +00:00
"github.com/mrusme/neonmodem/config"
"github.com/mrusme/neonmodem/models/forum"
"github.com/mrusme/neonmodem/system"
"github.com/mrusme/neonmodem/ui/theme"
"go.uber.org/zap"
)
2022-12-29 03:22:36 +00:00
type Ctx struct {
Screen [2]int
Content [2]int
Config *config.Config
2023-01-07 00:41:28 +00:00
EmbedFS *embed.FS
2022-12-29 03:22:36 +00:00
Systems []*system.System
Loading bool
Logger *zap.SugaredLogger
2022-12-31 21:57:11 +00:00
Theme *theme.Theme
currentSystem int
2023-01-05 16:43:52 +00:00
currentForum forum.Forum
2022-12-29 03:22:36 +00:00
}
func New(
2023-01-07 00:41:28 +00:00
efs *embed.FS,
cfg *config.Config,
logger *zap.SugaredLogger,
) Ctx {
2022-12-29 03:22:36 +00:00
return Ctx{
Screen: [2]int{0, 0},
Content: [2]int{0, 0},
Config: cfg,
2023-01-07 00:41:28 +00:00
EmbedFS: efs,
2022-12-29 03:22:36 +00:00
Loading: false,
Logger: logger,
2022-12-31 21:57:11 +00:00
Theme: theme.New(cfg),
currentSystem: -1,
2023-01-05 16:43:52 +00:00
currentForum: forum.Forum{},
2022-12-29 03:22:36 +00:00
}
}
func (c *Ctx) AddSystem(sys *system.System) error {
c.Systems = append(c.Systems, sys)
return nil
}
func (c *Ctx) NumSystems() int {
return len(c.Systems)
}
func (c *Ctx) SetCurrentSystem(idx int) {
c.currentSystem = idx
}
func (c *Ctx) GetCurrentSystem() int {
return c.currentSystem
}
2023-01-05 16:43:52 +00:00
func (c *Ctx) SetCurrentForum(f forum.Forum) {
c.currentForum = f
}
2023-01-05 16:43:52 +00:00
func (c *Ctx) GetCurrentForum() forum.Forum {
return c.currentForum
}