Skip to content

Commit

Permalink
Correct input types
Browse files Browse the repository at this point in the history
  • Loading branch information
ezemtsov committed Jul 5, 2019
1 parent 6a626da commit 68f8ea4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/Game.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ type GameAction = MVar GameState -> IO ()
-- Function that encapsulates message processing logic
gameLogic :: Client -> I.Message -> GameAction
gameLogic client msg state = case msg of
I.PostMove (I.Cell cell) -> postMoveAction client cell state
I.PostMove cell -> postMoveAction client cell state
I.UpdatePlayer player -> updatePlayerAction client player state
I.CleanHistory -> cleanHistoryAction state
I.UpdatePlayer (I.Player player) -> updatePlayerAction client player state
_ -> print $ "Handler is not implemented: " <> show msg

updatePlayerAction :: Client -> G.Player -> GameAction
Expand Down
24 changes: 10 additions & 14 deletions src/TypesGameInput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ noTagOptions = defaultOptions
{ sumEncoding = ObjectWithSingleField }

data Message =
Connect Data
| PostMove Data
| UpdatePlayer Data
Connect ConnectionData
| PostMove G.Cell
| UpdatePlayer G.Player
| GetHistory
| CleanHistory
deriving (Generic, Eq, Show)
Expand All @@ -30,17 +30,13 @@ instance FromJSON Message where
instance ToJSON Message where
toJSON = genericToJSON messageOptions

data Data =
ConnectionData { playerName :: G.PlayerName
, mode :: ConnectionMode
, session :: Maybe G.SessionId }
| Player G.Player
| Cell G.Cell
deriving (Generic, Eq, Show)
instance FromJSON Data where
parseJSON = genericParseJSON noTagOptions
instance ToJSON Data where
toJSON = genericToJSON noTagOptions
data ConnectionData = ConnectionData
{ playerName :: G.PlayerName
, mode :: ConnectionMode
, session :: Maybe G.SessionId
} deriving (Generic, Eq, Show)
instance FromJSON ConnectionData
instance ToJSON ConnectionData

data ConnectionMode =
NewGame
Expand Down
24 changes: 9 additions & 15 deletions web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ function msgMove(row, col, token) {
return {
method: 'PostMove',
resource: {
Cell: {
coord: {
x: row,
y: col
},
value: token
}
coord: {
x: row,
y: col
},
value: token
}
};
}
Expand All @@ -161,11 +159,9 @@ function msgConnect(name, mode, session) {
return {
method: 'Connect',
resource: {
ConnectionData: {
playerName: name,
mode: mode,
session: session
}
playerName: name,
mode: mode,
session: session
}
};
}
Expand All @@ -177,9 +173,7 @@ function msgCleanHistory() {
function msgUpdatePlayer(player) {
return {
method: "UpdatePlayer",
resource: {
Player: player
}
resource: player
};
}

Expand Down

0 comments on commit 68f8ea4

Please sign in to comment.