Skip to content

Commit

Permalink
Merge pull request #9 from dedifferentiator/accuracy-patch
Browse files Browse the repository at this point in the history
Stop 'strokes' field from increasing after the finish of typing
  • Loading branch information
rmehri01 authored Jan 11, 2021
2 parents a9c1623 + 00e25e8 commit 86a119c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
- websockets >= 0.12.7.1 && < 0.13

default-extensions:
FlexibleContexts
OverloadedStrings

library:
Expand Down
6 changes: 5 additions & 1 deletion src/UI/Offline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 6 additions & 1 deletion src/UI/Online.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions thock.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86a119c

Please sign in to comment.