Compare commits
2 Commits
e56560bcce
...
0d31433b96
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d31433b96 | |||
| b0c9c5ec18 |
8
Go.elm
8
Go.elm
@@ -1,6 +1,6 @@
|
|||||||
import Go.Types exposing (..)
|
import Go.Types exposing (..)
|
||||||
import Go.Game exposing (verify)
|
import Go.Game exposing (verify)
|
||||||
import Go.Decoders exposing (decodeUpdatestring)
|
import Go.Decoders exposing (decodeUpdateString)
|
||||||
import Go.Ws exposing (..)
|
import Go.Ws exposing (..)
|
||||||
import Go.View exposing (..)
|
import Go.View exposing (..)
|
||||||
import WebSocket
|
import WebSocket
|
||||||
@@ -28,7 +28,7 @@ initDummy = (Model
|
|||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view m = div []
|
view m = div []
|
||||||
[ text (toString m.currentColor)
|
[ text (toString m.board)
|
||||||
, renderBoard m.sessionSize m.board
|
, renderBoard m.sessionSize m.board
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -37,13 +37,13 @@ update msg model = case msg of
|
|||||||
Place indx -> case verify (indx, model.sessionColor) model of
|
Place indx -> case verify (indx, model.sessionColor) model of
|
||||||
Nothing -> ( { model | error = Just "Can't place piece" }, Cmd.none)
|
Nothing -> ( { model | error = Just "Can't place piece" }, Cmd.none)
|
||||||
Just c -> ( { model | board = c::model.board }, sendMove model c)
|
Just c -> ( { model | board = c::model.board }, sendMove model c)
|
||||||
Update s -> case decodeUpdatestring s of
|
Update s -> case decodeUpdateString s of
|
||||||
Ok (c, xs) -> ( { model | board = xs, currentColor = Just c }, Cmd.none)
|
Ok (c, xs) -> ( { model | board = xs, currentColor = Just c }, Cmd.none)
|
||||||
Err s -> ( { model | error = Just "Can't parse server response" }, Cmd.none)
|
Err s -> ( { model | error = Just "Can't parse server response" }, Cmd.none)
|
||||||
DismissError -> ({ model | error = Nothing }, Cmd.none)
|
DismissError -> ({ model | error = Nothing }, Cmd.none)
|
||||||
|
|
||||||
subscriptions : Model -> Sub Msg
|
subscriptions : Model -> Sub Msg
|
||||||
subscriptions m =
|
subscriptions m =
|
||||||
WebSocket.listen m.sessionUrl Update
|
WebSocket.listen (wsUrl m) Update
|
||||||
|
|
||||||
main = Html.programWithFlags { init = init, update = update, subscriptions = subscriptions, view = view }
|
main = Html.programWithFlags { init = init, update = update, subscriptions = subscriptions, view = view }
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ decodeUpdate = decode pair
|
|||||||
|> required "turn" decodeColor
|
|> required "turn" decodeColor
|
||||||
|> required "board" (Decode.list decodeCell)
|
|> required "board" (Decode.list decodeCell)
|
||||||
|
|
||||||
decodeUpdatestring : String -> Result String Update
|
decodeUpdateString : String -> Result String Update
|
||||||
decodeUpdatestring = Decode.decodeString decodeUpdate
|
decodeUpdateString = Decode.decodeString decodeUpdate
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ module Go.Ws exposing (..)
|
|||||||
import Go.Types exposing (..)
|
import Go.Types exposing (..)
|
||||||
import WebSocket
|
import WebSocket
|
||||||
|
|
||||||
|
wsUrl : Model -> String
|
||||||
|
wsUrl m = (m.sessionUrl ++ "/game/" ++ (toString m.sessionId))
|
||||||
|
|
||||||
encodeCell : Cell -> String
|
encodeCell : Cell -> String
|
||||||
encodeCell ((x, y), c) = "place "
|
encodeCell ((x, y), c) = "place "
|
||||||
++ (toString x) ++ " "
|
++ (toString x) ++ " "
|
||||||
@@ -9,4 +12,4 @@ encodeCell ((x, y), c) = "place "
|
|||||||
++ (toString c)
|
++ (toString c)
|
||||||
|
|
||||||
sendMove : Model -> Cell -> Cmd Msg
|
sendMove : Model -> Cell -> Cmd Msg
|
||||||
sendMove m c = WebSocket.send m.sessionUrl (encodeCell c)
|
sendMove m c = WebSocket.send (wsUrl m) (encodeCell c)
|
||||||
|
|||||||
Reference in New Issue
Block a user