Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
(#232) fixed help subcommands for no-role-knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwylde committed Jun 12, 2016
1 parent 2c707b2 commit b93da36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ Post v1 a change is further considered breaking if the state file format is inco
*Revisions*

* Fixed help subcommands from causing an error when a game doesn't exist. ([#230](https://github.com/hjwylde/werewolf/issues/230))
* Fixed help subcommands for no-role-knowledge variant. ([#232](https://github.com/hjwylde/werewolf/issues/232))

### v1.2.0.2

Expand Down
23 changes: 11 additions & 12 deletions app/Werewolf/Command/Help.hs
Expand Up @@ -52,20 +52,24 @@ handle callerName tag (Options (Just (Commands optAll))) = do
{ messages = commandsMessages callerName mGame
}
handle callerName tag (Options (Just (Roles optAll))) = do
mGame <- getGame tag optAll
mGame <- getGame tag optAll
let mGame' = mGame >>= \game -> case game ^. variant of
NoRoleKnowledge -> Nothing
_ -> Just game

let roles' = sortBy (compare `on` humanise) . nub $ case mGame of
Just game -> game ^.. players . roles
Nothing -> allRoles
let roles' = sortBy (compare `on` humanise) . nub $ maybe allRoles (toListOf $ players . roles) mGame'

exitWith success
{ messages = map (roleMessage callerName) roles'
}
handle callerName tag (Options (Just (Rules optAll))) = do
mGame <- getGame tag optAll
mGame <- getGame tag optAll
let mGame' = mGame >>= \game -> case game ^. variant of
NoRoleKnowledge -> Nothing
_ -> Just game

exitWith success
{ messages = rulesMessages callerName mGame
{ messages = rulesMessages callerName mGame'
}
handle callerName _ (Options Nothing) = exitWith success
{ messages = helpMessages callerName
Expand Down Expand Up @@ -106,9 +110,4 @@ helpMessages callerName =

getGame :: MonadIO m => Text -> Bool -> m (Maybe Game)
getGame _ True = return Nothing
getGame tag _ = ifM (not <$> doesGameExist tag) (return Nothing) $ do
game <- readGame tag

return $ case game ^. variant of
NoRoleKnowledge -> Nothing
_ -> Just game
getGame tag _ = ifM (doesGameExist tag) (Just <$> readGame tag) (return Nothing)

0 comments on commit b93da36

Please sign in to comment.