Skip to content

Commit

Permalink
chore(game): Add WithConfig opt
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jul 15, 2024
1 parent b6b1825 commit 6ef745e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -52,6 +53,7 @@ func New(opts ...Option) *Game {
}

type Game struct {
conf *config.Config
viewW, viewH int
x, y int
pattern pattern.Pattern
Expand Down
9 changes: 9 additions & 0 deletions internal/game/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"image"

"github.com/gabe565/cli-of-life/internal/config"
"github.com/gabe565/cli-of-life/internal/pattern"
)

Expand Down Expand Up @@ -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)
}
}

0 comments on commit 6ef745e

Please sign in to comment.