Added catch-up events to mitigate missing events from before the client joined.

This commit is contained in:
Gareth Latty
2015-12-12 18:37:24 +00:00
parent c801495a9f
commit fb5977dfd5
4 changed files with 33 additions and 5 deletions
+13 -3
View File
@@ -6,7 +6,7 @@ import Effects
import MassiveDecks.Models.State exposing (InitialState)
import MassiveDecks.Models.Game exposing (Lobby, LobbyAndHand)
import MassiveDecks.Models.Player as Player
import MassiveDecks.Actions.Event exposing (Event, events)
import MassiveDecks.Actions.Event exposing (Event, events, catchUpEvents)
type APICall a
@@ -37,8 +37,18 @@ type Action
eventEffects : Lobby -> Lobby -> Effects.Effects Action
eventEffects oldLobby newLobby
= events oldLobby newLobby
eventEffects oldLobby newLobby =
events oldLobby newLobby |> eventsToEffects
catchUpEffects : Lobby -> Effects.Effects Action
catchUpEffects lobby =
catchUpEvents lobby |> eventsToEffects
eventsToEffects : List Event -> Effects.Effects Action
eventsToEffects events
= events
|> List.map GameEvent
|> List.map Task.succeed
|> List.map Effects.task
+15
View File
@@ -23,6 +23,18 @@ events oldLobby newLobby = List.concat
]
{-| Generate events when joining an in-progress lobby to catch up. -}
catchUpEvents : Lobby -> List Event
catchUpEvents lobby =
case lobby.round of
Just round ->
case round.responses of
Hidden count -> [ roundPlayed count ]
Revealed _ -> []
Nothing ->
[]
diffPlayers : List Player -> List Player -> List Event
diffPlayers oldPlayers newPlayers =
List.concatMap (diffPlayer oldPlayers) newPlayers
@@ -53,6 +65,9 @@ diffRound oldRound newRound =
List.filterMap identity
[ Maybe.map roundEnd oldRound
, Maybe.map roundStart newRound
, newRound `Maybe.andThen` (\newRound -> case newRound.responses of
Hidden count -> Just (roundPlayed count)
Revealed _ -> Nothing)
]
else
Maybe.map2 changedRound oldRound newRound |> Maybe.withDefault []
@@ -68,6 +68,7 @@ roundContents address data round =
]
]
consideringView : Signal.Address Action -> Int -> List Response -> Bool -> Html
consideringView address considering consideringCards isCzar =
let
@@ -76,6 +77,7 @@ consideringView address considering consideringCards isCzar =
ol [ class "considering" ]
(List.append (List.map (\card -> li [] [ (playedResponse card) ]) consideringCards) extra)
winnerContentsAndHeader : Signal.Address Action -> FinishedRound -> List Player -> (List Html, List Html)
winnerContentsAndHeader address round players =
let
+3 -2
View File
@@ -7,7 +7,7 @@ import Html exposing (Html)
import MassiveDecks.API as API
import MassiveDecks.Models.State exposing (Model, State(..))
import MassiveDecks.Actions.Action exposing (Action(..), APICall(..))
import MassiveDecks.Actions.Action exposing (Action(..), APICall(..), catchUpEffects)
import MassiveDecks.Models.State exposing (State(..), StartData, PlayingData, Error, Global)
import MassiveDecks.States.Start.UI as UI
import MassiveDecks.States.Config as Config
@@ -47,7 +47,8 @@ update action global data = case action of
case lobbyAndHand.lobby.round of
Just _ ->
(Playing.modelSub global lobbyId secret
(PlayingData lobbyAndHand.lobby lobbyAndHand.hand secret [] Nothing Nothing []), Effects.none)
(PlayingData lobbyAndHand.lobby lobbyAndHand.hand secret [] Nothing Nothing []),
catchUpEffects lobbyAndHand.lobby)
Nothing ->
(Config.modelSub global lobbyId secret