| summaryrefslogtreecommitdiff |
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-09-27 15:40:30 +0200 |
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-09-27 15:40:30 +0200 |
| commit | 2f22e667fbea56884d74ed27777f2e9f3fc9fd53 (patch) | |
| tree | 75300c58cc7b287993887f84b2d68b9d515a9ec0 /src/Comm | |
| parent | 486ee1dbe21be962e89f421e1dd5f3cbb2fd2177 (diff) | |
Starting to separate background and popup code.
Diffstat (limited to 'src/Comm')
| -rw-r--r-- | src/Comm/GetBattles.elm | 45 | ||||
| -rw-r--r-- | src/Comm/GetID.elm | 43 | ||||
| -rw-r--r-- | src/Comm/Okay.elm | 21 | ||||
| -rw-r--r-- | src/Comm/Send.elm | 66 | ||||
| -rw-r--r-- | src/Comm/SetBattles.elm | 51 |
5 files changed, 0 insertions, 226 deletions
diff --git a/src/Comm/GetBattles.elm b/src/Comm/GetBattles.elm deleted file mode 100644 index 0956972..0000000 --- a/src/Comm/GetBattles.elm +++ /dev/null @@ -1,45 +0,0 @@ -module Comm.GetBattles exposing (try) - --- Elm ------------------------------------------------------------------------- -import Json.Encode - --- Extension ------------------------------------------------------------------- -import Comm.Send - -import Struct.Event -import Struct.Model -import Struct.Player - --------------------------------------------------------------------------------- --- TYPES ------------------------------------------------------------------------ --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -try_encoding : String -> Struct.Model.Type -> (Maybe Json.Encode.Value) -try_encoding player_id model = - let - encoded_player_id = (Json.Encode.string player_id) - in - (Just - (Json.Encode.object - [ - ("id", encoded_player_id) - ] - ) - ) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -try : Struct.Model.Type -> Struct.Player.Type -> (Maybe (Cmd Struct.Event.Type)) -try model player = - (Comm.Send.try_sending - model - ( - (Struct.Player.get_query_url player) - ++ "/handler/player/plr_get_battles" - ) - (try_encoding (Struct.Player.get_id player)) - ) diff --git a/src/Comm/GetID.elm b/src/Comm/GetID.elm deleted file mode 100644 index 14d668c..0000000 --- a/src/Comm/GetID.elm +++ /dev/null @@ -1,43 +0,0 @@ -module Comm.GetID exposing (try) - --- Elm ------------------------------------------------------------------------- -import Json.Encode - --- Extension ------------------------------------------------------------------- -import Comm.Send - -import Constants.IO - -import Struct.Event -import Struct.Model - --------------------------------------------------------------------------------- --- TYPES ------------------------------------------------------------------------ --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -try_encoding : String -> Struct.Model.Type -> (Maybe Json.Encode.Value) -try_encoding player_id model = - let - encoded_player_id = (Json.Encode.string player_id) - in - (Just - (Json.Encode.object - [ - ("id", encoded_player_id) - ] - ) - ) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -try : Struct.Model.Type -> String -> (Maybe (Cmd Struct.Event.Type)) -try model = - (Comm.Send.try_sending - model - Constants.IO.get_battles_handler - (try_encoding player_id) - ) diff --git a/src/Comm/Okay.elm b/src/Comm/Okay.elm deleted file mode 100644 index 9281558..0000000 --- a/src/Comm/Okay.elm +++ /dev/null @@ -1,21 +0,0 @@ -module Comm.Okay exposing (decoder) - --- Elm ------------------------------------------------------------------------- -import Json.Decode - --- Battlemap ------------------------------------------------------------------- -import Struct.ServerReply - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -decoder : (Json.Decode.Decoder Struct.ServerReply.Type) -decoder = (Json.Decode.succeed Struct.ServerReply.Okay) diff --git a/src/Comm/Send.elm b/src/Comm/Send.elm deleted file mode 100644 index 3fc30ae..0000000 --- a/src/Comm/Send.elm +++ /dev/null @@ -1,66 +0,0 @@ -module Comm.Send exposing (try_sending) - --- Elm ------------------------------------------------------------------------- -import Http - -import Json.Decode -import Json.Encode - --- Extension ------------------------------------------------------------------- -import Comm.Okay -import Comm.SetBattles - -import Struct.Event -import Struct.ServerReply -import Struct.Model - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -internal_decoder : String -> (Json.Decode.Decoder Struct.ServerReply.Type) -internal_decoder reply_type = - case reply_type of - "okay" -> (Comm.Okay.decoder) - "set_battles" -> (Comm.SetBattles.decoder) - other -> - (Json.Decode.fail - ( - "Unknown server command \"" - ++ other - ++ "\"" - ) - ) - -decoder : (Json.Decode.Decoder Struct.ServerReply.Type) -decoder = - (Json.Decode.field "msg" Json.Decode.string) - |> (Json.Decode.andThen (internal_decoder)) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -try_sending : ( - Struct.Model.Type -> - String -> - (Struct.Model.Type -> (Maybe Json.Encode.Value)) -> - (Maybe (Cmd Struct.Event.Type)) - ) -try_sending model recipient try_encoding_fun = - case (try_encoding_fun model) of - (Just serial) -> - (Just - (Http.send - Struct.Event.ServerReplied - (Http.post - recipient - (Http.jsonBody serial) - (Json.Decode.list (decoder)) - ) - ) - ) - - Nothing -> Nothing diff --git a/src/Comm/SetBattles.elm b/src/Comm/SetBattles.elm deleted file mode 100644 index 0add112..0000000 --- a/src/Comm/SetBattles.elm +++ /dev/null @@ -1,51 +0,0 @@ -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)) |


