-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement ultra game mode (#10)
* refactor: use KVPs for horizontal picker component; add ultra to mode picker * refactor: move subcommands * refactor: move shared code * refactor: rename marathon package to single * docs(readme): amend docs to use new play subcommand * fix: update play subcommand game modes * chore: duplicate marathon tui code for ultra * refactor: rename to gameStopwatch * feat: implement ultra game mode * feat: combine ultra & marathon models into 'single' model * chore: fix lint * fix: scoring * refactor: move from uint to int I was using uint to enforce values being positive, but this is not a good use case for the type. It also overcomplicates things due to so much casting between uint and int. Instead I will validate the Scoring type, which is the container of the strictly positive integers. * feat: validate scoring type on creation * chore: fix lint * test: fix scoring test
- Loading branch information
1 parent
d99f482
commit 0b78a5a
Showing
25 changed files
with
598 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Broderick-Westrope/tetrigo/internal/config" | ||
"github.com/Broderick-Westrope/tetrigo/internal/data" | ||
"github.com/Broderick-Westrope/tetrigo/internal/tui/common" | ||
"github.com/Broderick-Westrope/tetrigo/internal/tui/starter" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
type MenuCmd struct{} | ||
|
||
func (c *MenuCmd) Run(globals *GlobalVars) error { | ||
return launchStarter(globals, common.ModeMenu, common.NewMenuInput()) | ||
} | ||
|
||
type PlayCmd struct { | ||
GameMode string `arg:"" help:"Game mode to play" default:"marathon"` | ||
Level int `help:"Level to start at" short:"l" default:"1"` | ||
Name string `help:"Name of the player" short:"n" default:"Anonymous"` | ||
} | ||
|
||
func (c *PlayCmd) Run(globals *GlobalVars) error { | ||
switch c.GameMode { | ||
case "marathon": | ||
return launchStarter(globals, common.ModeUltra, common.NewSingleInput(common.ModeMarathon, c.Level, c.Name)) | ||
case "ultra": | ||
return launchStarter(globals, common.ModeUltra, common.NewSingleInput(common.ModeUltra, c.Level, c.Name)) | ||
default: | ||
return fmt.Errorf("invalid game mode: %s", c.GameMode) | ||
} | ||
} | ||
|
||
type LeaderboardCmd struct { | ||
GameMode string `arg:"" help:"Game mode to display" default:"marathon"` | ||
} | ||
|
||
func (c *LeaderboardCmd) Run(globals *GlobalVars) error { | ||
return launchStarter(globals, common.ModeLeaderboard, common.NewLeaderboardInput(c.GameMode)) | ||
} | ||
|
||
func launchStarter(globals *GlobalVars, starterMode common.Mode, switchIn common.SwitchModeInput) error { | ||
db, err := data.NewDB(globals.DB) | ||
if err != nil { | ||
return fmt.Errorf("error opening database: %w", err) | ||
} | ||
|
||
cfg, err := config.GetConfig(globals.Config) | ||
if err != nil { | ||
return fmt.Errorf("error getting config: %w", err) | ||
} | ||
|
||
model, err := starter.NewModel( | ||
starter.NewInput(starterMode, switchIn, db, cfg), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error creating starter model: %w", err) | ||
} | ||
|
||
if _, err = tea.NewProgram(model, tea.WithAltScreen()).Run(); err != nil { | ||
return fmt.Errorf("error running tea program: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.