moves last server API logic inside its own module

This commit is contained in:
2019-11-05 23:31:38 +01:00
parent 21650c4011
commit 7ee8c2e87c
3 changed files with 190 additions and 186 deletions

View File

@@ -205,8 +205,18 @@ update msg model =
case model.state.activeMode of
Nothing ->
update (ModeSwitched Nothing) model
Just mode ->
(model, Cmd.map ApiMsg <| Api.sendRequest mode (String.fromInt model.player.id) (buildPayload mode model))
let items = targetItemsFor mode model
|> List.filter (itemInSelection model.state.selection)
in
( model
, Cmd.map ApiMsg
<| Api.sendRequest
mode
(String.fromInt model.player.id)
items
)
UndoLastAction ->
(model, Cmd.map ApiMsg <| Api.undoLastAction model.player.id)
@@ -226,30 +236,6 @@ targetItemsFor mode model =
Modes.Sell ->Maybe.withDefault [] model.loot
Modes.Grab -> Maybe.withDefault [] model.groupLoot
buildPayload : ViewMode -> Model -> E.Value
buildPayload mode model =
let
items = targetItemsFor mode model
|> List.filter (itemInSelection model.state.selection)
in
case mode of
Modes.Buy -> E.object
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
, ("global_mod", E.null )
]
Modes.Sell -> E.object
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
, ("global_mod", E.null )
]
Modes.Grab -> E.object
[ ( "items", items |> E.list (\i -> E.int i.id))
, ("global_mod", E.null )
]
Modes.Add -> E.object
[ ( "items", items |> E.list (\i -> E.int i.id))
, ("global_mod", E.null )
]
-- DbUpdates always refer to the active player's loot
applyUpdate : Api.Update -> Model -> Model
applyUpdate u model =