From 00e25e81aa75776ed7b7426d6b9855e45434ea58 Mon Sep 17 00:00:00 2001 From: 413x Date: Mon, 11 Jan 2021 14:55:15 +0200 Subject: [PATCH] fix: stop 'strokes' field from increasing after finishing typing the quote --- package.yaml | 1 + src/UI/Offline.hs | 6 +++++- src/UI/Online.hs | 7 ++++++- thock.cabal | 12 ++++++------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/package.yaml b/package.yaml index 6cd3954..a188347 100644 --- a/package.yaml +++ b/package.yaml @@ -37,6 +37,7 @@ dependencies: - websockets >= 0.12.7.1 && < 0.13 default-extensions: + FlexibleContexts OverloadedStrings library: diff --git a/src/UI/Offline.hs b/src/UI/Offline.hs index 777755c..6a58220 100644 --- a/src/UI/Offline.hs +++ b/src/UI/Offline.hs @@ -212,11 +212,15 @@ handleKeyPractice g (VtyEvent ev) = V.EvKey V.KEsc [] -> M.continue initialGame V.EvKey (V.KChar 'r') [V.MCtrl] -> M.continue (startPracticeGame (g ^. quote)) V.EvKey (V.KChar 'n') [V.MCtrl] -> liftIO generateQuote >>= M.continue . startPracticeGame - V.EvKey (V.KChar _) [] -> nextState (g & strokes +~ 1) + V.EvKey (V.KChar _) [] -> nextState $ numStrokes g _ -> nextState g where nextState g' = if isDone g' then M.continue (Practice g') else updateGameState g' ev >>= M.continue . Practice + numStrokes g' = + if isDone g' + then g' + else g' & strokes +~ 1 handleKeyPractice g _ = M.continue (Practice g) diff --git a/src/UI/Online.hs b/src/UI/Online.hs index 77120e2..89f74e8 100644 --- a/src/UI/Online.hs +++ b/src/UI/Online.hs @@ -141,9 +141,14 @@ handleKeyOnlineState o (AppEvent (ConnectionTick csReceived)) = handleKeyOnlineState o (VtyEvent ev) = case ev of V.EvKey V.KEsc [] -> liftIO (sendJsonData (o ^. connection) (BackToLobby $ o ^. username)) >> M.continue (OnlineGame o) - V.EvKey (V.KChar _) [] -> nextState (o & (localGame . strokes) +~ 1) + V.EvKey (V.KChar _) [] -> nextState $ numStrokes o _ -> nextState o where + numStrokes o' = + if isDone (o' ^. localGame) + then o' + else o' & (localGame . strokes) +~ 1 + nextState o' = if isDone (o' ^. localGame) then M.continue (OnlineGame o') diff --git a/thock.cabal b/thock.cabal index 8d0603d..bd833f6 100644 --- a/thock.cabal +++ b/thock.cabal @@ -1,10 +1,10 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0. +-- This file has been generated from package.yaml by hpack version 0.34.3. -- -- see: https://github.com/sol/hpack -- --- hash: 81d1d1005d8eba4dd8ebed3ea7e1b1d47dcf5e6f7e900095e95e3dfe9d375547 +-- hash: 4cb56a8445ae87f75e52fc3e426e253f9f55059ea6901de28753a46d0defd449 name: thock version: 0.2.0.0 @@ -42,7 +42,7 @@ library Paths_thock hs-source-dirs: src - default-extensions: OverloadedStrings + default-extensions: FlexibleContexts OverloadedStrings build-depends: aeson >=1.4.7.1 && <1.5 , base >=4.7 && <5 @@ -67,7 +67,7 @@ executable server Paths_thock hs-source-dirs: app - default-extensions: OverloadedStrings + default-extensions: FlexibleContexts OverloadedStrings ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: aeson >=1.4.7.1 && <1.5 @@ -94,7 +94,7 @@ executable thock Paths_thock hs-source-dirs: app - default-extensions: OverloadedStrings + default-extensions: FlexibleContexts OverloadedStrings ghc-options: -O3 -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: aeson >=1.4.7.1 && <1.5 @@ -122,7 +122,7 @@ test-suite thock-test Paths_thock hs-source-dirs: test - default-extensions: OverloadedStrings + default-extensions: FlexibleContexts OverloadedStrings ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: aeson >=1.4.7.1 && <1.5