summaryrefslogtreecommitdiff
blob: 5fb3243558b5953d0d3e5040b241001a87ac0d9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Comm.SetBattles exposing (decoder)

-- Elm -------------------------------------------------------------------------
import Json.Decode

-- Extension -------------------------------------------------------------------
import Struct.BattleSummary
import Struct.ServerReply

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type alias Battles =
   {
      campaigns : (List Struct.BattleSummary.Type),
      invasions : (List Struct.BattleSummary.Type),
      events : (List Struct.BattleSummary.Type)
   }

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
internal_decoder : (Json.Decode.Decoder Battles)
internal_decoder =
   (Json.Decode.map3
      Battles
      (Json.Decode.field
         "cmps"
         (Json.Decode.list (Struct.BattleSummary.decoder))
      )
      (Json.Decode.field
         "invs"
         (Json.Decode.list (Struct.BattleSummary.decoder))
      )
      (Json.Decode.field
         "evts"
         (Json.Decode.list (Struct.BattleSummary.decoder))
      )
   )

to_server_reply : Battles -> Struct.ServerReply.Type
to_server_reply t =
   (Struct.ServerReply.SetBattles (t.campaigns, t.invasions, t.events))

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
decoder : (Json.Decode.Decoder Struct.ServerReply.Type)
decoder =
   (Json.Decode.map (to_server_reply) (internal_decoder))