| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-09-29 13:30:15 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-09-29 13:30:15 +0200 |
| commit | 80c3b7947eb0bd240d4c1f94808cb64d2fbfbf3d (patch) | |
| tree | 6b4168efd6165f0f23c70cd054416b270a39042a /src/shared/Struct/BattleSummary.elm | |
| parent | aa908fcf7072c0e27d242ecf7014174f9de16965 (diff) | |
...
Diffstat (limited to 'src/shared/Struct/BattleSummary.elm')
| -rw-r--r-- | src/shared/Struct/BattleSummary.elm | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/shared/Struct/BattleSummary.elm b/src/shared/Struct/BattleSummary.elm new file mode 100644 index 0000000..1947613 --- /dev/null +++ b/src/shared/Struct/BattleSummary.elm @@ -0,0 +1,79 @@ +module Struct.BattleSummary exposing + ( + Type, + get_id, + get_name, + get_last_edit, + is_players_turn, + decoder, + encode, + none + ) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode +import Json.Decode.Pipeline + +import Json.Encode + +-- Extension ------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + id : String, + name : String, + last_edit : String, + is_players_turn : Bool + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_id : Type -> String +get_id t = t.id + +get_name : Type -> String +get_name t = t.name + +get_last_edit : Type -> String +get_last_edit t = t.last_edit + +is_players_turn : Type -> Bool +is_players_turn t = t.is_players_turn + +decoder : (Json.Decode.Decoder Type) +decoder = + (Json.Decode.Pipeline.decode + Type + |> (Json.Decode.Pipeline.required "id" Json.Decode.string) + |> (Json.Decode.Pipeline.required "nme" Json.Decode.string) + |> (Json.Decode.Pipeline.required "ldt" Json.Decode.string) + |> (Json.Decode.Pipeline.required "ipt" Json.Decode.bool) + ) + +encode : Type -> Json.Encode.Value +encode t = + (Json.Encode.object + [ + ("id", (Json.Encode.string t.id)), + ("nme", (Json.Encode.string t.name)), + ("ldt", (Json.Encode.string t.last_edit)), + ("ipt", (Json.Encode.bool t.is_players_turn)) + ] + ) + +none : Type +none = + { + id = "", + name = "Unknown", + last_edit = "Never", + is_players_turn = False + } |


