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