diff --git a/client/src/MassiveDecks/Scenes/Lobby.elm b/client/src/MassiveDecks/Scenes/Lobby.elm index 7869502..c3d5563 100644 --- a/client/src/MassiveDecks/Scenes/Lobby.elm +++ b/client/src/MassiveDecks/Scenes/Lobby.elm @@ -52,7 +52,7 @@ subscriptions model = let delegated = case model.lobby.round of Nothing -> Config.subscriptions model.config |> Sub.map ConfigMessage - Just round -> Sub.none + Just round -> Playing.subscriptions |> Sub.map PlayingMessage websocket = WebSocket.listen (webSocketUrl model.init.url model.lobby.gameCode) webSocketResponseDecoder in @@ -90,7 +90,7 @@ webSocketResponseDecoder response = else case Json.decodeString lobbyDecoder response of Ok lobby -> - LobbyUpdated lobby |> LocalMessage + UpdateLobby lobby |> LocalMessage Err message -> let @@ -138,11 +138,11 @@ update message model = in ({ model | playing = playing }, Cmd.map (LocalMessage << PlayingMessage) cmd) - LobbyUpdated lobby -> + UpdateLobby lobby -> model |> updateLobbyAndHand { lobby = lobby, hand = model.hand } :> updateHandIfRoundStarted - HandUpdated hand -> + UpdateHand hand -> model |> updateLobbyAndHand { lobby = model.lobby, hand = hand } Identify -> @@ -195,19 +195,25 @@ type alias Update = Model -> (Model, Cmd ConsumerMessage) updateLobbyAndHand : Game.LobbyAndHand -> Update updateLobbyAndHand lobbyAndHand model = let - events = Event.events model.lobby lobbyAndHand.lobby |> List.map (GameEvent >> LocalMessage >> Util.cmd) + events + = Event.events model.lobby lobbyAndHand.lobby + |> List.map (GameEvent >> LocalMessage >> Util.cmd) + commands = [ Util.cmd (Playing.LobbyAndHandUpdated |> Playing.LocalMessage |> PlayingMessage |> LocalMessage) ] ++ events in { model | lobby = lobbyAndHand.lobby - , hand = lobbyAndHand.hand} ! events + , hand = lobbyAndHand.hand} ! commands +{-| If the player didn't make the call the start the game, they will only recieve a notification about it, which won't +give them their hand. We check if we have started a new round, and don't have a hand - if so we go get it. +-} updateHandIfRoundStarted : Update updateHandIfRoundStarted model = let cmd = case model.lobby.round of Just value -> if (List.isEmpty model.hand.hand) then - Request.send' (API.getHand model.lobby.gameCode model.secret) ErrorMessage (LocalMessage << HandUpdated) + Request.send' (API.getHand model.lobby.gameCode model.secret) ErrorMessage (LocalMessage << UpdateHand) else Cmd.none diff --git a/client/src/MassiveDecks/Scenes/Lobby/Messages.elm b/client/src/MassiveDecks/Scenes/Lobby/Messages.elm index 25f07a0..339e05f 100644 --- a/client/src/MassiveDecks/Scenes/Lobby/Messages.elm +++ b/client/src/MassiveDecks/Scenes/Lobby/Messages.elm @@ -21,8 +21,8 @@ type ConsumerMessage -} type Message = DismissNotification Notification - | LobbyUpdated Game.Lobby - | HandUpdated Card.Hand + | UpdateLobby Game.Lobby + | UpdateHand Card.Hand | Identify | NoOp | GameEvent Event diff --git a/client/src/MassiveDecks/Scenes/Playing.elm b/client/src/MassiveDecks/Scenes/Playing.elm index c6e2fd4..14464ce 100644 --- a/client/src/MassiveDecks/Scenes/Playing.elm +++ b/client/src/MassiveDecks/Scenes/Playing.elm @@ -14,10 +14,9 @@ import MassiveDecks.API.Request as Request import MassiveDecks.Models exposing (Init) import MassiveDecks.Components.Errors as Errors import MassiveDecks.Models.Card as Card -import MassiveDecks.Models.Game as Game import MassiveDecks.Scenes.Lobby.Models as Lobby import MassiveDecks.Scenes.Playing.UI as UI -import MassiveDecks.Scenes.Playing.Models exposing (Model, ShownPlayedCards) +import MassiveDecks.Scenes.Playing.Models exposing (Model, ShownPlayedCards, ShownCard) import MassiveDecks.Scenes.Playing.Messages exposing (ConsumerMessage(..), Message(..)) import MassiveDecks.Scenes.Playing.HouseRule as HouseRule exposing (HouseRule) import MassiveDecks.Scenes.Playing.HouseRule.Id as HouseRule @@ -52,8 +51,8 @@ hack seed = String.toInt seed |> Result.withDefault 0 {-| Subscriptions for the playing scene. -} -subscriptions : Model -> Sub ConsumerMessage -subscriptions model = AnimationFrame.diffs (\_ -> LocalMessage CheckForPlayedCardsToAnimate) +subscriptions : Sub ConsumerMessage +subscriptions = AnimationFrame.diffs (\_ -> LocalMessage CheckForPlayedCardsToAnimate) {-| Render the playing scene. @@ -96,7 +95,7 @@ update message lobbyModel = Play -> ( { model | picked = [] } - , Request.send (API.play gameCode secret model.picked) playErrorHandler ErrorMessage (UpdateLobbyAndHand >> LocalMessage) + , Request.send (API.play gameCode secret model.picked) playErrorHandler ErrorMessage LobbyUpdate ) Consider potentialWinnerIndex -> @@ -106,7 +105,7 @@ update message lobbyModel = Choose winnerIndex -> ( { model | considering = Nothing } - , Request.send (API.choose gameCode secret winnerIndex) chooseErrorHandler ErrorMessage (UpdateLobbyAndHand >> LocalMessage) + , Request.send (API.choose gameCode secret winnerIndex) chooseErrorHandler ErrorMessage LobbyUpdate ) NextRound -> @@ -117,9 +116,9 @@ update message lobbyModel = ) CheckForPlayedCardsToAnimate -> - ( model - , if List.isEmpty model.shownPlayed.toAnimate then Cmd.none else Util.cmd (LocalMessage AnimatePlayedCards) - ) + ( model + , if List.isEmpty model.shownPlayed.toAnimate then Cmd.none else Util.cmd (LocalMessage AnimatePlayedCards) + ) AnimatePlayedCards -> let @@ -132,25 +131,25 @@ update message lobbyModel = ) Skip playerIds -> - (model, Request.send (API.skip gameCode secret playerIds) skipErrorHandler ErrorMessage (UpdateLobbyAndHand >> LocalMessage)) + (model, Request.send (API.skip gameCode secret playerIds) skipErrorHandler ErrorMessage LobbyUpdate) Back -> - (model, Request.send' (API.back gameCode secret) ErrorMessage (UpdateLobbyAndHand >> LocalMessage)) + (model, Request.send' (API.back gameCode secret) ErrorMessage LobbyUpdate) - UpdateLobbyAndHand lobbyAndHand -> - updateLobbyAndHand lobbyAndHand lobbyModel + LobbyAndHandUpdated -> + lobbyAndHandUpdated lobbyModel Redraw -> - (model, Request.send (API.redraw lobbyModel.lobby.gameCode lobbyModel.secret) redrawErrorHandler ErrorMessage (UpdateLobbyAndHand >> LocalMessage)) + (model, Request.send (API.redraw lobbyModel.lobby.gameCode lobbyModel.secret) redrawErrorHandler ErrorMessage LobbyUpdate) NoOp -> (model, Cmd.none) -updateLobbyAndHand : Game.LobbyAndHand -> Lobby.Model -> (Model, Cmd ConsumerMessage) -updateLobbyAndHand lobbyAndHand lobbyModel = +lobbyAndHandUpdated : Lobby.Model -> (Model, Cmd ConsumerMessage) +lobbyAndHandUpdated lobbyModel = let - lobby = lobbyAndHand.lobby + lobby = lobbyModel.lobby model = lobbyModel.playing shownPlayed = model.shownPlayed playedCards = lobby.round `Maybe.andThen` (\round -> @@ -171,7 +170,7 @@ updateLobbyAndHand lobbyAndHand lobbyModel = newModel = { model | shownPlayed = newShownPlayed , seed = seed} in - (newModel, Util.cmd (LobbyUpdate lobbyAndHand)) + (newModel, Cmd.none) redrawErrorHandler : API.RedrawError -> ConsumerMessage @@ -212,7 +211,7 @@ skipErrorHandler error = ErrorMessage <| Errors.New "The players can't be skipped as they are not inactive." False -addShownPlayed : Int -> Random.Seed -> (List (Html.Attribute msg), Random.Seed) +addShownPlayed : Int -> Random.Seed -> (List ShownCard, Random.Seed) addShownPlayed new seed = Random.step (Random.list new initialRandomPositioning) seed @@ -224,21 +223,9 @@ updatePositioning shownPlayed seed = (ShownPlayedCards (shownPlayed.animated ++ newAnimated) [], newSeed) -randomPositioning : Random.Generator (Html.Attribute msg) -randomPositioning = Random.map4 positioning (Random.int -75 75) (Random.int 0 50) Random.bool (Random.int -5 1) +randomPositioning : Random.Generator ShownCard +randomPositioning = Random.map4 ShownCard (Random.int -90 90) (Random.int 0 50) Random.bool (Random.int -5 1) -initialRandomPositioning : Random.Generator (Html.Attribute msg) -initialRandomPositioning = Random.map3 (\r h l -> positioning r h l -100) (Random.int -75 75) (Random.int 0 50) Random.bool - - -positioning : Int -> Int -> Bool -> Int -> Html.Attribute msg -positioning rotation horizontalPos left verticalPos = - let - horizontalDirection = if left then "left" else "right" - in - Html.style - [ ("transform", "rotate(" ++ (toString rotation) ++ "deg)") - , (horizontalDirection, (toString horizontalPos) ++ "%") - , ("top", (toString verticalPos) ++ "%") - ] +initialRandomPositioning : Random.Generator ShownCard +initialRandomPositioning = Random.map3 (\r h l -> ShownCard r h l -100) (Random.int -75 75) (Random.int 0 50) Random.bool diff --git a/client/src/MassiveDecks/Scenes/Playing/Messages.elm b/client/src/MassiveDecks/Scenes/Playing/Messages.elm index 4474824..33eda90 100644 --- a/client/src/MassiveDecks/Scenes/Playing/Messages.elm +++ b/client/src/MassiveDecks/Scenes/Playing/Messages.elm @@ -16,7 +16,8 @@ type ConsumerMessage {-| The messages used in the start screen. -} type Message - = Pick String + = LobbyAndHandUpdated + | Pick String | Withdraw String | Play | Consider Int @@ -27,5 +28,4 @@ type Message | Skip (List Player.Id) | Back | Redraw - | UpdateLobbyAndHand Game.LobbyAndHand | NoOp diff --git a/client/src/MassiveDecks/Scenes/Playing/Models.elm b/client/src/MassiveDecks/Scenes/Playing/Models.elm index bac76a1..daa8455 100644 --- a/client/src/MassiveDecks/Scenes/Playing/Models.elm +++ b/client/src/MassiveDecks/Scenes/Playing/Models.elm @@ -1,10 +1,7 @@ -module MassiveDecks.Scenes.Playing.Models exposing (Model, ShownPlayedCards) +module MassiveDecks.Scenes.Playing.Models exposing (Model, ShownPlayedCards, ShownCard) import Random -import Html exposing (Attribute) - -import MassiveDecks.Scenes.Playing.Messages exposing (Message) import MassiveDecks.Models.Game as Game @@ -20,6 +17,14 @@ type alias Model = type alias ShownPlayedCards = - { animated : List (Attribute Message) - , toAnimate : List (Attribute Message) + { animated : List (ShownCard) + , toAnimate : List (ShownCard) + } + + +type alias ShownCard = + { rotation : Int + , horizontalPos : Int + , isLeft : Bool + , verticalPos : Int } diff --git a/client/src/MassiveDecks/Scenes/Playing/UI.elm b/client/src/MassiveDecks/Scenes/Playing/UI.elm index 25c5d57..24a8430 100644 --- a/client/src/MassiveDecks/Scenes/Playing/UI.elm +++ b/client/src/MassiveDecks/Scenes/Playing/UI.elm @@ -9,6 +9,7 @@ import MassiveDecks.Models.Game as Game import MassiveDecks.Models.Player as Player exposing (Player) import MassiveDecks.Models.Card as Card import MassiveDecks.Scenes.Lobby.Models as Lobby +import MassiveDecks.Scenes.Playing.Models exposing (ShownCard) import MassiveDecks.Scenes.Playing.Messages exposing (Message(..)) import MassiveDecks.Scenes.Playing.HouseRule as HouseRule exposing (HouseRule) import MassiveDecks.Scenes.Playing.HouseRule.Available exposing (houseRules) @@ -201,8 +202,20 @@ response picked disabled response = [ div [ class "response-text" ] [ text (Util.firstLetterToUpper response.text), text "." ] ] -blankResponse : Attribute Message -> Html Message -blankResponse positioning = div [ class "card mui-panel", positioning ] [] +blankResponse : ShownCard -> Html Message +blankResponse shownCard = div [ class "card mui-panel", positioning shownCard ] [] + + +positioning : ShownCard -> Html.Attribute msg +positioning shownCard = + let + horizontalDirection = if shownCard.isLeft then "left" else "right" + in + style + [ ("transform", "rotate(" ++ (toString shownCard.rotation) ++ "deg)") + , (horizontalDirection, (toString shownCard.horizontalPos) ++ "%") + , ("top", (toString shownCard.verticalPos) ++ "%") + ] handRender : Bool -> List (Html Message) -> Html Message @@ -229,7 +242,7 @@ pickedResponse response = ] ] -pickedView : List Card.Response -> Int -> List (Attribute Message) -> List (Html Message) +pickedView : List Card.Response -> Int -> List (ShownCard) -> List (Html Message) pickedView picked slots shownPlayed = let numberPicked = List.length picked diff --git a/client/src/MassiveDecks/Scenes/Start.elm b/client/src/MassiveDecks/Scenes/Start.elm index 45aa0ee..55d2383 100644 --- a/client/src/MassiveDecks/Scenes/Start.elm +++ b/client/src/MassiveDecks/Scenes/Start.elm @@ -103,7 +103,7 @@ update message model = let (lobby, cmd) = Lobby.init model.init lobbyAndHand secret in - ({ model | lobby = Just lobby}, cmd |> Cmd.map LobbyMessage) + ({ model | lobby = Just lobby }, cmd |> Cmd.map LobbyMessage) InputMessage message -> let