-
Notifications
You must be signed in to change notification settings - Fork 1
/
Deserialize.elm
50 lines (42 loc) · 1.09 KB
/
Deserialize.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Deserialize where
import Dict
import Json.Decode exposing (..)
import Helpers exposing (..)
import GameTypes exposing (..)
import Player
action : Decoder Action
action =
("action" := string) `andThen` actionInfo
actionInfo : String -> Decoder Action
actionInfo actionType =
case actionType of
"PickUpPiece" ->
object2 PickUpPiece
("player" := player)
("idx" := int)
"PlacePiece" ->
object2 PlacePiece
("mousePos" := mousePos)
("dims" := windowDims)
"StartGame" ->
object4 GameStarted
("deck" := deck)
("player" := player)
("color" := player)
("opponentName" := string)
"Pass" ->
succeed Pass
"OpponentDisconnected" ->
succeed OpponentDisconnected
"NoAction" ->
succeed NoAction
_ ->
fail (actionType ++ " is not a recognized type of action")
deck : Decoder Deck
deck = list string
player : Decoder Player
player = map Player.fromString string
mousePos : Decoder MousePos
mousePos = tuple2 (,) int int
windowDims : Decoder WindowDims
windowDims = tuple2 (,) int int