summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-09-14 18:57:42 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-09-14 18:57:42 +0200
commit2aa0c12b6a193d16681a0179a067664390af7aee (patch)
treeca2e2533c3a9947ba5ef9d5e1d646b964ba82eb6 /src/Comm/SetBattles.elm
parentac5b50e4a622ee0885678a96c69af7f49290bcee (diff)
...
Diffstat (limited to 'src/Comm/SetBattles.elm')
-rw-r--r--src/Comm/SetBattles.elm51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Comm/SetBattles.elm b/src/Comm/SetBattles.elm
new file mode 100644
index 0000000..0add112
--- /dev/null
+++ b/src/Comm/SetBattles.elm
@@ -0,0 +1,51 @@
+module Comm.SetBattles exposing (decoder)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Extension -------------------------------------------------------------------
+import Struct.BattleSummary
+import Struct.Player
+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))