Skip to content

Commit

Permalink
Merge branch 'small-fixes' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehri01 committed Jan 15, 2021
2 parents 86a119c + 1834dce commit 87dfca6
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
mv ~/.local/bin/thock .
- name: Reduce size of executable
if: matrix.os_name == 'linux'
uses: svenstaro/upx-action@v2
with:
file: thock
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: Build

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2

- name: Check formatting
uses: mrkkrp/ormolu-action@v1

- name: Haskell Linter
uses: domdere/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cache ~/.stack folder
uses: actions/cache@v2
with:
path: ~/.stack
key: stack-global-linux-${{hashFiles('**.yaml')}}
restore-keys: |
stack-global-linux
- name: Cache ~/.local/bin folder
uses: actions/cache@v2
with:
path: ~/.local/bin
key: stack-local-bin-linux-${{hashFiles('**.yaml')}}
restore-keys: |
stack-local-bin-linux
- name: Cache .stack-work folder
uses: actions/cache@v2
with:
path: .stack-work
key: stack-work-linux-${{hashFiles('**.yaml')}}
restore-keys: |
stack-work-linux
- uses: haskell/actions/setup@v1
with:
ghc-version: '8.8.4' # Exact version of ghc to use
enable-stack: true
stack-version: 'latest'

- name: Build project
run: |
stack build --test
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog for thock

## 0.2.1.0

Bug fixes:

- [#8](https://github.com/rmehri01/thock/pull/8) Fix replaced words in quotes thanks to [@dedifferentiator](https://github.com/dedifferentiator).
- [#9](https://github.com/rmehri01/thock/pull/9) Stop strokes from increasing after finished thanks to [@dedifferentiator](https://github.com/dedifferentiator).

## 0.2.0.0

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# thock

[![Hackage](https://img.shields.io/hackage/v/thock.svg)](https://hackage.haskell.org/package/thock)
![GitHub Actions Status](https://github.com/rmehri01/thock/workflows/Build/badge.svg) [![Hackage](https://img.shields.io/hackage/v/thock.svg)](https://hackage.haskell.org/package/thock)

![An example of an online game](resources/demo.gif)

Expand Down
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: thock
version: 0.2.0.0
version: 0.2.1.0
github: "rmehri01/thock"
license: MIT
author: "Ryan Mehri"
Expand Down Expand Up @@ -29,7 +29,7 @@ dependencies:
- mtl >= 2.2.2 && < 2.3
- network >= 3.1.1.1 && < 3.2
- random == 1.1.*
- text >= 1.2.4.0 && < 1.3
- text >= 1.2.3.0 && < 1.3
- text-zipper >= 0.10.1 && < 0.11
- time >= 1.9.3 && < 1.10
- vector >= 0.12.1.2 && < 0.13
Expand Down
4 changes: 2 additions & 2 deletions src/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ talk conn mState room = forever $ do
if canStart (map (^. state) $ (ss ^. rooms) Map.! room)
&& isNothing (Map.lookup room (ss ^. activeGames))
then do
newS <- modifyMVar mState $ \s -> do
newS <- modifyMVar mState $ \s ->
let s' = makeActive room s in return (s', s')
q <- generateQuote
broadcastTo id room (StartGame q) (newS ^. activeGames)
Expand Down Expand Up @@ -254,4 +254,4 @@ equalOnStateUsername user c = (c ^. (state . username)) == user

-- | Produces true if there is more than one person in the room and they are all ready
canStart :: [RoomClientState] -> Bool
canStart rs = length rs > 1 && all (^. isReady) rs
canStart rs = length rs > 1 && all (^. isReady) rs
6 changes: 4 additions & 2 deletions src/UI/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import qualified Brick.Widgets.Border.Style as BS
import qualified Brick.Widgets.Center as C
import qualified Brick.Widgets.Edit as E
import qualified Brick.Widgets.ProgressBar as P
import Control.Lens ((^.))
import Control.Lens ((&), (+~), (^.))
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.FileEmbed (embedFile)
import qualified Data.Text as T
Expand All @@ -52,6 +52,7 @@ import Thock
numIncorrectChars,
quote,
secondsElapsed,
strokes,
updateTime,
)
import UI.Attributes
Expand Down Expand Up @@ -165,6 +166,7 @@ addBorder t = withBorderStyle BS.unicodeRounded . B.borderWithLabel (txt t)
-- updating the 'GameState' accordingly
updateGameState :: GameState -> Event -> EventM ResourceName GameState
updateGameState g ev = do
gEdited <- handleEventLensed g input E.handleEditorEvent ev
let gWithStroke = g & strokes +~ 1
gEdited <- handleEventLensed gWithStroke input E.handleEditorEvent ev
currentTime <- liftIO getCurrentTime
return . updateTime currentTime $ movePromptCursor gEdited
17 changes: 5 additions & 12 deletions src/UI/Offline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import qualified Brick.Main as M
import qualified Brick.Widgets.Center as C
import qualified Brick.Widgets.List as L
import Client (runClient)
import Control.Lens ((&), (+~), (^.))
import Control.Lens ((^.))
import Control.Monad.IO.Class (MonadIO (liftIO))
import qualified Data.Text as T
import qualified Graphics.Vty as V
Expand Down Expand Up @@ -212,15 +212,8 @@ 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 $ 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
_ ->
if isDone g
then M.continue (Practice g)
else updateGameState g ev >>= M.continue . Practice
handleKeyPractice g _ = M.continue (Practice g)
20 changes: 6 additions & 14 deletions src/UI/Online.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Brick
)
import qualified Brick.Main as M
import qualified Brick.Widgets.Center as C
import Control.Lens ((%~), (&), (+~), (.~), (^.))
import Control.Lens ((%~), (&), (.~), (^.))
import Control.Monad.IO.Class (MonadIO (liftIO))
import qualified Graphics.Vty as V
import Online
Expand Down Expand Up @@ -141,24 +141,16 @@ 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 $ 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')
_ ->
if isDone (o ^. localGame)
then M.continue (OnlineGame o)
else do
updatedGame <- updateGameState (o' ^. localGame) ev
updatedGame <- updateGameState (o ^. localGame) ev
let newClientState = GameClientState (o ^. username) (calculateProgress updatedGame) (calculateWpm updatedGame)
_ <-
liftIO $
sendJsonData
(o ^. connection)
(GameClientUpdate newClientState)
M.continue (OnlineGame $ o' & localGame .~ updatedGame)
M.continue (OnlineGame $ o & localGame .~ updatedGame)
handleKeyOnlineState o _ = M.continue (OnlineGame o)
14 changes: 7 additions & 7 deletions thock.cabal
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.34.3.
-- This file has been generated from package.yaml by hpack version 0.33.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 4cb56a8445ae87f75e52fc3e426e253f9f55059ea6901de28753a46d0defd449
-- hash: d2863e78d924ba368809dd238a643f64c02632b46e3a567f2fa7f535fc58d164

name: thock
version: 0.2.0.0
version: 0.2.1.0
synopsis: A modern TUI typing game featuring online racing against friends.
description: Please see the README on GitHub at <https://github.com/rmehri01/thock#readme>
category: Game
Expand Down Expand Up @@ -53,7 +53,7 @@ library
, mtl >=2.2.2 && <2.3
, network >=3.1.1.1 && <3.2
, random ==1.1.*
, text >=1.2.4.0 && <1.3
, text >=1.2.3.0 && <1.3
, text-zipper >=0.10.1 && <0.11
, time >=1.9.3 && <1.10
, vector >=0.12.1.2 && <0.13
Expand All @@ -79,7 +79,7 @@ executable server
, mtl >=2.2.2 && <2.3
, network >=3.1.1.1 && <3.2
, random ==1.1.*
, text >=1.2.4.0 && <1.3
, text >=1.2.3.0 && <1.3
, text-zipper >=0.10.1 && <0.11
, thock
, time >=1.9.3 && <1.10
Expand All @@ -106,7 +106,7 @@ executable thock
, mtl >=2.2.2 && <2.3
, network >=3.1.1.1 && <3.2
, random ==1.1.*
, text >=1.2.4.0 && <1.3
, text >=1.2.3.0 && <1.3
, text-zipper >=0.10.1 && <0.11
, thock
, time >=1.9.3 && <1.10
Expand Down Expand Up @@ -134,7 +134,7 @@ test-suite thock-test
, mtl >=2.2.2 && <2.3
, network >=3.1.1.1 && <3.2
, random ==1.1.*
, text >=1.2.4.0 && <1.3
, text >=1.2.3.0 && <1.3
, text-zipper >=0.10.1 && <0.11
, thock
, time >=1.9.3 && <1.10
Expand Down

0 comments on commit 87dfca6

Please sign in to comment.