summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-09-29 13:09:53 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-09-29 13:09:53 +0200
commitaa908fcf7072c0e27d242ecf7014174f9de16965 (patch)
treece5ca5661c582e29075a639c4e843524a88225d7
parent0f0d16d980896f557d53b064d05dbb4a8feceec6 (diff)
downloadtacticians-extension-aa908fcf7072c0e27d242ecf7014174f9de16965.zip
tacticians-extension-aa908fcf7072c0e27d242ecf7014174f9de16965.tar.bz2
...
-rw-r--r--src/background/src/Comm/GetBattles.elm29
-rw-r--r--src/background/src/Comm/Send.elm29
-rw-r--r--src/background/src/Comm/SetBattles.elm1
-rw-r--r--src/background/src/Update/HandleServerReply.elm10
-rw-r--r--src/background/src/Update/RefreshBattles.elm5
-rw-r--r--src/background/src/Update/StoreParams.elm38
-rw-r--r--src/popup/src/Comm/Send.elm28
-rw-r--r--src/popup/src/Struct/ServerReply.elm3
-rw-r--r--src/popup/src/Update/StoreParams.elm2
9 files changed, 29 insertions, 116 deletions
diff --git a/src/background/src/Comm/GetBattles.elm b/src/background/src/Comm/GetBattles.elm
index 0956972..39673d7 100644
--- a/src/background/src/Comm/GetBattles.elm
+++ b/src/background/src/Comm/GetBattles.elm
@@ -1,45 +1,30 @@
-module Comm.GetBattles exposing (try)
+module Comm.GetBattles exposing (request)
-- Elm -------------------------------------------------------------------------
-import Json.Encode
-- Extension -------------------------------------------------------------------
import Comm.Send
import Struct.Event
-import Struct.Model
import Struct.Player
--------------------------------------------------------------------------------
--- TYPES ------------------------------------------------------------------------
+-- 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
+request : Struct.Player.Type -> (Cmd Struct.Event.Type)
+request player =
+ (Comm.Send.commit
(
(Struct.Player.get_query_url player)
- ++ "/handler/player/plr_get_battles"
+ ++ "/handler/player/plr_get_battles?pid="
+ ++ (Struct.Player.get_id player)
)
- (try_encoding (Struct.Player.get_id player))
)
diff --git a/src/background/src/Comm/Send.elm b/src/background/src/Comm/Send.elm
index 3fc30ae..26caf3a 100644
--- a/src/background/src/Comm/Send.elm
+++ b/src/background/src/Comm/Send.elm
@@ -1,10 +1,9 @@
-module Comm.Send exposing (try_sending)
+module Comm.Send exposing (commit)
-- Elm -------------------------------------------------------------------------
import Http
import Json.Decode
-import Json.Encode
-- Extension -------------------------------------------------------------------
import Comm.Okay
@@ -12,7 +11,6 @@ import Comm.SetBattles
import Struct.Event
import Struct.ServerReply
-import Struct.Model
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -43,24 +41,9 @@ decoder =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-try_sending : (
- Struct.Model.Type ->
- String ->
- (Struct.Model.Type -> (Maybe Json.Encode.Value)) ->
- (Maybe (Cmd Struct.Event.Type))
+commit : String -> (Cmd Struct.Event.Type)
+commit query =
+ (Http.send
+ Struct.Event.ServerReplied
+ (Http.get query (Json.Decode.list (decoder)))
)
-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/background/src/Comm/SetBattles.elm b/src/background/src/Comm/SetBattles.elm
index 0add112..5fb3243 100644
--- a/src/background/src/Comm/SetBattles.elm
+++ b/src/background/src/Comm/SetBattles.elm
@@ -5,7 +5,6 @@ import Json.Decode
-- Extension -------------------------------------------------------------------
import Struct.BattleSummary
-import Struct.Player
import Struct.ServerReply
--------------------------------------------------------------------------------
diff --git a/src/background/src/Update/HandleServerReply.elm b/src/background/src/Update/HandleServerReply.elm
index b80c7b4..c95000d 100644
--- a/src/background/src/Update/HandleServerReply.elm
+++ b/src/background/src/Update/HandleServerReply.elm
@@ -67,9 +67,13 @@ handle_set_battles battles current_state =
Nothing -> ({updated_model| query_index = -1}, cmds)
(Just next_player) ->
- case (Comm.GetBattles.try updated_model next_player) of
- Nothing -> ({updated_model| query_index = -1}, cmds)
- (Just query) -> (updated_model, (query :: cmds))
+ (
+ updated_model,
+ (
+ (Comm.GetBattles.request next_player)
+ :: cmds
+ )
+ )
apply_command : (
Struct.ServerReply.Type ->
diff --git a/src/background/src/Update/RefreshBattles.elm b/src/background/src/Update/RefreshBattles.elm
index 513a295..6a9d602 100644
--- a/src/background/src/Update/RefreshBattles.elm
+++ b/src/background/src/Update/RefreshBattles.elm
@@ -21,7 +21,4 @@ apply_to model =
case (Array.get 0 model.players) of
Nothing -> (model, Cmd.none)
(Just player) ->
- case (Comm.GetBattles.try model player) of
- -- TODO: Invalidate only this player, refresh the others.
- Nothing -> (model, Cmd.none)
- (Just cmd) -> ({model | query_index = 0}, cmd)
+ ({model | query_index = 0}, (Comm.GetBattles.request player))
diff --git a/src/background/src/Update/StoreParams.elm b/src/background/src/Update/StoreParams.elm
deleted file mode 100644
index 3472c13..0000000
--- a/src/background/src/Update/StoreParams.elm
+++ /dev/null
@@ -1,38 +0,0 @@
-module Update.StoreParams exposing (apply_to)
-
--- Elm -------------------------------------------------------------------------
-import Array
-
-import Json.Encode
-
--- Extension -------------------------------------------------------------------
-import Action.Ports
-
-import Struct.Event
-import Struct.Flags
-import Struct.Model
-import Struct.Player
-
---------------------------------------------------------------------------------
--- LOCAL -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))
-apply_to model =
- (
- model,
- (Action.Ports.set_params
- (
- (Struct.Flags.get_frequency model.flags),
- (Json.Encode.encode
- 0
- (Json.Encode.list
- (List.map (Struct.Player.encode) (Array.toList model.players))
- )
- )
- )
- )
- )
diff --git a/src/popup/src/Comm/Send.elm b/src/popup/src/Comm/Send.elm
index cda4cf2..1a939c5 100644
--- a/src/popup/src/Comm/Send.elm
+++ b/src/popup/src/Comm/Send.elm
@@ -1,10 +1,9 @@
-module Comm.Send exposing (try_sending)
+module Comm.Send exposing (commit)
-- Elm -------------------------------------------------------------------------
import Http
import Json.Decode
-import Json.Encode
-- Extension -------------------------------------------------------------------
import Comm.Okay
@@ -41,24 +40,9 @@ decoder =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-try_sending : (
- Struct.Model.Type ->
- String ->
- (Struct.Model.Type -> (Maybe Json.Encode.Value)) ->
- (Maybe (Cmd Struct.Event.Type))
+commit : String -> (Cmd Struct.Event.Type)
+commit query =
+ (Http.send
+ Struct.Event.ServerReplied
+ (Http.get query (Json.Decode.list (decoder)))
)
-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/popup/src/Struct/ServerReply.elm b/src/popup/src/Struct/ServerReply.elm
index e995f63..cc9d372 100644
--- a/src/popup/src/Struct/ServerReply.elm
+++ b/src/popup/src/Struct/ServerReply.elm
@@ -2,8 +2,7 @@ module Struct.ServerReply exposing (Type(..))
-- Elm -------------------------------------------------------------------------
--- -------------------------------------------------------------------
-import Struct.BattleSummary
+-- Extension -------------------------------------------------------------------
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
diff --git a/src/popup/src/Update/StoreParams.elm b/src/popup/src/Update/StoreParams.elm
index f369be8..3472c13 100644
--- a/src/popup/src/Update/StoreParams.elm
+++ b/src/popup/src/Update/StoreParams.elm
@@ -24,7 +24,7 @@ apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))
apply_to model =
(
model,
- (Action.Ports.store_params
+ (Action.Ports.set_params
(
(Struct.Flags.get_frequency model.flags),
(Json.Encode.encode