From 6ef745e5e42a972dcc5bc64a58223c0d09ea4f44 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 15 Jul 2024 00:05:25 -0500 Subject: [PATCH] chore(game): Add `WithConfig` opt --- cmd/cmd.go | 7 +------ internal/game/game.go | 2 ++ internal/game/opts.go | 9 +++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index bb75291..0f5a85e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -55,12 +55,7 @@ func run(cmd *cobra.Command, _ []string) error { } } - g := game.New( - game.WithPattern(pat), - game.WithDimensions(conf.Width, conf.Height), - game.WithPlay(conf.Play), - ) - + g := game.New(game.WithPattern(pat), game.WithConfig(conf)) _, err := tea.NewProgram(g, tea.WithAltScreen(), tea.WithMouseAllMotion()).Run() return err } diff --git a/internal/game/game.go b/internal/game/game.go index a8f6b5e..a182fe4 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -11,6 +11,7 @@ import ( "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" + "github.com/gabe565/cli-of-life/internal/config" "github.com/gabe565/cli-of-life/internal/pattern" ) @@ -52,6 +53,7 @@ func New(opts ...Option) *Game { } type Game struct { + conf *config.Config viewW, viewH int x, y int pattern pattern.Pattern diff --git a/internal/game/opts.go b/internal/game/opts.go index f5f3700..d0c3271 100644 --- a/internal/game/opts.go +++ b/internal/game/opts.go @@ -4,6 +4,7 @@ import ( "context" "image" + "github.com/gabe565/cli-of-life/internal/config" "github.com/gabe565/cli-of-life/internal/pattern" ) @@ -35,3 +36,11 @@ func WithPlay(play bool) Option { } } } + +func WithConfig(c *config.Config) Option { + return func(game *Game) { + game.conf = c + WithDimensions(c.Width, c.Height)(game) + WithPlay(c.Play)(game) + } +}