Skip to content

Commit

Permalink
implement endpoint for performing actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lehmacdj committed Aug 20, 2020
1 parent 45a15fe commit af28ba0
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Hanabi/Api.hs
Expand Up @@ -173,6 +173,10 @@ gameAlreadyStartedCannot :: LByteString -> ServerError
gameAlreadyStartedCannot action =
err400 {errBody = "Game has already started. Can't " <> action <> " game."}

gameMustBeInProgressTo :: LByteString -> ServerError
gameMustBeInProgressTo action =
err400 {errBody = "Game must be in progress to " <> action <> "game."}

badPlayerCount :: Int -> ServerError
badPlayerCount playerCount =
err400
Expand Down Expand Up @@ -269,6 +273,31 @@ startGame hgid = doStart <$> lookupOrThrowKV badGame hgid $> NoContent
-- HGID ->
-- _
-- subscribeToState = undefined
--

doAct ::
forall r.
Members
[ Embed IO,
KVStore UUID Player,
KVStore HGID LobbyState,
Error ServerError,
Input (Chan GError)
]
r =>
Player ->
HGID ->
RawAction ->
Sem r NoContent
doAct player hgid action = inputAction <$> lookupOrThrowKV badGame hgid $> NoContent
where
inputAction :: LobbyState -> Sem r ()
inputAction = \case
InProgress state ->
writeChan
(view #actionInput state)
(RawTurn player action)
_ -> throw (gameMustBeInProgressTo "perform an action")

hanabiGameApi ::
Members
Expand All @@ -288,5 +317,5 @@ hanabiGameApi player gameId =
playersGet = getPlayers gameId,
start = startGame gameId,
connect = undefined,
act = undefined
act = doAct player gameId
}

0 comments on commit af28ba0

Please sign in to comment.