adds claims for group chest view

This commit is contained in:
2019-12-02 15:58:26 +01:00
parent ecb0cc59a8
commit 976fbe6b4b
10 changed files with 249 additions and 192 deletions

View File

@@ -82,8 +82,8 @@ view page =
case maybeSession page of
Just session ->
case Session.user session of
Session.Player player _ _ ->
player.name
Session.Player data ->
data.player.name
Session.Admin ->
"Administration"
@@ -95,13 +95,13 @@ view page =
case maybeSession page of
Just session ->
case Session.user session of
Session.Player player _ _ ->
Session.Player data ->
let
linkWithGem =
navLink "fas fa-gem"
in
[ navLink "fas fa-store-alt" "Marchand" "/marchand"
, if player.id /= 0 then
, if data.player.id /= 0 then
linkWithGem "Coffre de groupe" "/coffre"
else
@@ -144,12 +144,13 @@ viewSessionBar session controls =
Nothing ->
[ text "" ]
Just (Session.Player player wealth _) ->
Wealth.view player.wealth wealth
++ (if player.debt > 0 then
Just (Session.Player data) ->
-- TODO: Urgh ! When will this Wealth.Model move out of session !
Wealth.view data.player.wealth data.wealth
++ (if data.player.debt > 0 then
[ div [ class "level-item" ]
[ p [ class "heading is-size-4 has-text-danger" ]
[ text ("Dette : " ++ String.fromInt player.debt ++ "po") ]
[ text ("Dette : " ++ String.fromInt data.player.debt ++ "po") ]
]
]
@@ -222,6 +223,25 @@ map func page =
page
-- Restores the page after an action has be resolved (either success or error)
closeAction ( page, cmd ) =
case page of
Dashboard home ->
( page, cmd )
GroupChest chest ->
( GroupChest (GroupChest.refresh chest), cmd )
Shop shop ->
( page, cmd )
_ ->
( page, cmd )
update msg page =
case ( msg, page, maybeSession page ) of
-- Dashboard page
@@ -240,6 +260,7 @@ update msg page =
-- Group chest
( GotGroupChestMsg (GroupChest.Api apiMsg), GroupChest _, _ ) ->
update (ApiMsg apiMsg) page
|> closeAction
( GotGroupChestMsg subMsg, GroupChest chest, _ ) ->
GroupChest.update subMsg chest
@@ -266,16 +287,16 @@ update msg page =
Session.wealth session
in
case Session.user session of
Session.Player player aModel _ ->
Session.Player data ->
let
( newWealth, maybeEdit ) =
Wealth.update wealthMsg aModel
Wealth.update wealthMsg data.wealth
in
( map (Session.updateWealth newWealth) page
, case maybeEdit of
Just amount ->
Api.confirmAction
(String.fromInt (.id player))
(String.fromInt (.id data.player))
(Api.WealthPayload amount)
|> Cmd.map ApiMsg
@@ -346,44 +367,46 @@ applyUpdate u user =
in
{- Note: DbUpdates always refer to the active player -}
case user of
Session.Player player wealthModel loot ->
Session.Player data ->
case u of
Api.ItemRemoved item ->
Session.Player player wealthModel <|
List.filter
(\i -> i.id /= item.id)
loot
Session.Player
{ data
| loot =
List.filter
(\i -> i.id /= item.id)
data.loot
}
Api.ItemAdded item ->
Session.Player player wealthModel (item :: loot)
Session.Player { data | loot = item :: data.loot }
Api.WealthUpdated diff ->
let
player =
data.player
wealth =
player.wealth
_ =
Debug.log "updatePlayerWealth" diff
in
Session.Player
{ player
| wealth =
Api.Player.Wealth
(wealth.cp + diff.cp)
(wealth.sp + diff.sp)
(wealth.gp + diff.gp)
(wealth.pp + diff.pp)
{ data
| player =
{ player
| wealth =
Api.Player.Wealth
(wealth.cp + diff.cp)
(wealth.sp + diff.sp)
(wealth.gp + diff.gp)
(wealth.pp + diff.pp)
}
}
wealthModel
loot
Api.ClaimAdded claim ->
-- { model | claims = claim :: model.claims }
user
Session.Player { data | claims = claim :: data.claims }
Api.ClaimRemoved claim ->
-- { model | claims = List.filter (\c -> c.id /= claim.id) model.claims }
user
Session.Player { data | claims = List.filter (\c -> c.id /= claim.id) data.claims }
Session.Admin ->
user