diff --git a/ChangeLog.md b/ChangeLog.md index 62ecd5d..5ea4112 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ # Changelog for mtlstats +## current +- enter months by number + ## 0.15.2 - allow ties diff --git a/src/Mtlstats/Control/NewGame.hs b/src/Mtlstats/Control/NewGame.hs index dcb9922..1c284c8 100644 --- a/src/Mtlstats/Control/NewGame.hs +++ b/src/Mtlstats/Control/NewGame.hs @@ -62,7 +62,7 @@ gameYearC :: Controller gameYearC = promptControllerWith header gameYearPrompt gameMonthC :: Controller -gameMonthC = menuControllerWith header gameMonthMenu +gameMonthC = promptControllerWith monthHeader gameMonthPrompt gameDayC :: Controller gameDayC = promptControllerWith header gameDayPrompt @@ -226,6 +226,31 @@ header :: ProgState -> C.Update () header s = C.drawString $ "*** GAME " ++ padNum 2 (s^.database.dbGames) ++ " ***\n" +monthHeader :: ProgState -> C.Update () +monthHeader s = do + (_, cols) <- C.windowSize + header s + + let + table = labelTable $ zip (map show ([1..] :: [Int])) + [ "JANUARY" + , "FEBRUARY" + , "MARCH" + , "APRIL" + , "MAY" + , "JUNE" + , "JULY" + , "AUGUST" + , "SEPTEMBER" + , "OCTOBER" + , "NOVEMBER" + , "DECEMBER" + ] + + C.drawString $ unlines $ + map (centre $ fromIntegral $ pred cols) $ + ["MONTH:", ""] ++ table ++ [""] + gameGoal :: ProgState -> (Int, Int) gameGoal s = ( s^.database.dbGames diff --git a/src/Mtlstats/Format.hs b/src/Mtlstats/Format.hs index 3d0f954..8499379 100644 --- a/src/Mtlstats/Format.hs +++ b/src/Mtlstats/Format.hs @@ -129,9 +129,14 @@ month _ = "" labelTable :: [(String, String)] -> [String] labelTable xs = let labelWidth = maximum $ map (length . fst) xs + valWidth = maximum $ map (length . snd) xs + in map - (\(label, val) -> right labelWidth label ++ ": " ++ val) - xs + ( \(label, val) + -> right labelWidth label + ++ ": " + ++ left valWidth val + ) xs -- | Creates a variable column table of numbers with two axes numTable diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 336e838..d2bfe50 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -29,7 +29,6 @@ module Mtlstats.Menu ( -- * Menus mainMenu, newSeasonMenu, - gameMonthMenu, gameTypeMenu, gameGoalieMenu, editMenu @@ -130,26 +129,6 @@ newSeasonMenu = Menu "SEASON TYPE" () . startNewGame ] --- | Requests the month in which the game took place -gameMonthMenu :: Menu () -gameMonthMenu = Menu "MONTH:" () $ map - (\(ch, name, val) -> - MenuItem ch name $ - modify $ progMode.gameStateL.gameMonth ?~ val) - [ ( 'A', "JANUARY", 1 ) - , ( 'B', "FEBRUARY", 2 ) - , ( 'C', "MARCH", 3 ) - , ( 'D', "APRIL", 4 ) - , ( 'E', "MAY", 5 ) - , ( 'F', "JUNE", 6 ) - , ( 'G', "JULY", 7 ) - , ( 'H', "AUGUST", 8 ) - , ( 'I', "SEPTEMBER", 9 ) - , ( 'J', "OCTOBER", 10 ) - , ( 'K', "NOVEMBER", 11 ) - , ( 'L', "DECEMBER", 12 ) - ] - -- | The game type menu (home/away) gameTypeMenu :: Menu () gameTypeMenu = Menu "GAME TYPE:" () diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index c6c74bc..d0b5fef 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -31,6 +31,7 @@ module Mtlstats.Prompt ( ucStrPrompt, namePrompt, numPrompt, + numPromptRange, numPromptWithFallback, dbNamePrompt, selectPrompt, @@ -154,6 +155,20 @@ numPrompt -> Prompt numPrompt pStr = numPromptWithFallback pStr $ return () +-- | Builds a numberic prompt with a range +numPromptRange + :: Int + -- ^ The minimum value + -> Int + -- ^ The maximum value + -> String + -- ^ The prompt string + -> (Int -> Action ()) + -- ^ The callback function for the result + -> Prompt +numPromptRange nMin nMax pStr callback = numPrompt pStr $ \n -> + when (n >= nMin && n <= nMax) $ callback n + -- | Builds a numeric prompt with a fallback action numPromptWithFallback :: String diff --git a/src/Mtlstats/Prompt/NewGame.hs b/src/Mtlstats/Prompt/NewGame.hs index b864a91..71e6e54 100644 --- a/src/Mtlstats/Prompt/NewGame.hs +++ b/src/Mtlstats/Prompt/NewGame.hs @@ -23,6 +23,7 @@ along with this program. If not, see . module Mtlstats.Prompt.NewGame ( gameYearPrompt + , gameMonthPrompt , gameDayPrompt , otherTeamPrompt , homeScorePrompt @@ -48,6 +49,11 @@ gameYearPrompt :: Prompt gameYearPrompt = numPrompt "Game year: " $ modify . (progMode.gameStateL.gameYear ?~) +-- | Prompts for the game month +gameMonthPrompt :: Prompt +gameMonthPrompt = numPromptRange 1 12 "Game month: " $ + modify . (progMode.gameStateL.gameMonth ?~) + -- | Prompts for the day of the month the game took place gameDayPrompt :: Prompt gameDayPrompt = numPrompt "Day of month: " $ diff --git a/test/FormatSpec.hs b/test/FormatSpec.hs index 1598720..3596300 100644 --- a/test/FormatSpec.hs +++ b/test/FormatSpec.hs @@ -141,9 +141,9 @@ labelTableSpec = describe "labelTable" $ ] expected = - [ " foo: bar" + [ " foo: bar " , " baz: quux" - , "longer: x" + , "longer: x " ] in labelTable input `shouldBe` expected diff --git a/test/Helpers/GoalieSpec.hs b/test/Helpers/GoalieSpec.hs index 3046751..9b1d5f9 100644 --- a/test/Helpers/GoalieSpec.hs +++ b/test/Helpers/GoalieSpec.hs @@ -54,7 +54,7 @@ goalieDetailsSpec = describe "goalieDetails" $ let . ( gsTies .~ 15 ) expected = unlines - [ "Number: 1" + [ "Number: 1 " , " Name: Joe*" , "" , " YTD Lifetime" diff --git a/test/Helpers/PlayerSpec.hs b/test/Helpers/PlayerSpec.hs index 59f9436..50dd0ec 100644 --- a/test/Helpers/PlayerSpec.hs +++ b/test/Helpers/PlayerSpec.hs @@ -50,8 +50,8 @@ playerDetailsSpec = describe "playerDetails" $ } expected = unlines - [ " Number: 1" - , " Name: Joe*" + [ " Number: 1 " + , " Name: Joe* " , "Position: centre" , "" , " YTD Lifetime"