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..9448b6f 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) + WithPlay(c.Play) + } +}