| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | manifest.json | 9 | ||||
| -rw-r--r-- | src/Action/Ports.elm | 2 | ||||
| -rw-r--r-- | src/ElmModule/Update.elm | 6 | ||||
| -rw-r--r-- | src/Struct/Event.elm | 4 | ||||
| -rw-r--r-- | src/Struct/Flags.elm | 4 | ||||
| -rw-r--r-- | src/Update/StoreParams.elm | 24 | ||||
| -rw-r--r-- | www/script/params.js | 31 |
7 files changed, 57 insertions, 23 deletions
diff --git a/manifest.json b/manifest.json index 04eeb32..e3f369c 100644 --- a/manifest.json +++ b/manifest.json @@ -19,5 +19,14 @@ "default_icon": "images/to-favicon.svg", "default_title": "TO - Active Battles", "default_popup": "www/index.html" + }, + + "background": { + "scripts": + [ + "www/script/params.js", + "www/script/main.js", + "www/script/load.js" + ] } } diff --git a/src/Action/Ports.elm b/src/Action/Ports.elm index c79d918..4d83077 100644 --- a/src/Action/Ports.elm +++ b/src/Action/Ports.elm @@ -1,4 +1,4 @@ port module Action.Ports exposing (..) -port store_new_params : (Int, (List String)) -> (Cmd msg) +port store_params : (Int, String) -> (Cmd msg) port reset_params : () -> (Cmd msg) diff --git a/src/ElmModule/Update.elm b/src/ElmModule/Update.elm index 5baa84c..fbe8dfe 100644 --- a/src/ElmModule/Update.elm +++ b/src/ElmModule/Update.elm @@ -7,6 +7,7 @@ import Struct.Event import Struct.Model import Update.HandleServerReply +import Update.StoreParams -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- @@ -27,6 +28,11 @@ update event model = case event of Struct.Event.None -> (model, Cmd.none) + (Struct.Event.SetUsername str) -> (model, Cmd.none) + (Struct.Event.SetID str) -> (model, Cmd.none) + (Struct.Event.SetURLPrefix str) -> (model, Cmd.none) + (Struct.Event.SetFrequency val) -> (Update.StoreParams.apply_to model) + (Struct.Event.Failed err) -> ( (Struct.Model.invalidate err new_model), diff --git a/src/Struct/Event.elm b/src/Struct/Event.elm index 3bf64d7..68bca98 100644 --- a/src/Struct/Event.elm +++ b/src/Struct/Event.elm @@ -13,6 +13,10 @@ import Struct.ServerReply type Type = None | Failed Struct.Error.Type + | SetUsername String + | SetID String + | SetURLPrefix String + | SetFrequency Int | ServerReplied (Result Http.Error (List Struct.ServerReply.Type)) attempted : (Result.Result err val) -> Type diff --git a/src/Struct/Flags.elm b/src/Struct/Flags.elm index ccda57a..d9d2dcd 100644 --- a/src/Struct/Flags.elm +++ b/src/Struct/Flags.elm @@ -17,7 +17,7 @@ import Util.List type alias Type = { frequency : Int, - players : (List String) + players : String } -------------------------------------------------------------------------------- @@ -30,5 +30,5 @@ type alias Type = get_frequency : Type -> Int get_frequency flags = flags.frequency -get_players : Type -> (List String) +get_players : Type -> String get_players flags = flags.players diff --git a/src/Update/StoreParams.elm b/src/Update/StoreParams.elm new file mode 100644 index 0000000..3955ecd --- /dev/null +++ b/src/Update/StoreParams.elm @@ -0,0 +1,24 @@ +module Update.StoreParams exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- + +-- Login ----------------------------------------------------------------------- +import Action.Ports + +import Struct.Event +import Struct.Flags +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) +apply_to model = + ( + model, + (Action.Ports.store_params (5, "")) + ) diff --git a/www/script/params.js b/www/script/params.js index 440a491..803003c 100644 --- a/www/script/params.js +++ b/www/script/params.js @@ -7,19 +7,7 @@ tacticians_online.params = new Object(); tacticians_online.params.private = new Object(); tacticians_online.params.private.frequency = 15; -tacticians_online.params.private.players = []; - -tacticians_online.params.store = -function () -{ - localStorage.setItem - ( - "frequency", - tacticians_online.params.private.frequency - ); - - localStorage.setItem("players", tacticians_online.params.private.players); -} +tacticians_online.params.private.players = ""; tacticians_online.params.reset = function () @@ -43,7 +31,7 @@ function () if (tacticians_online.params.private.players == null) { - tacticians_online.params.private.players = []; + tacticians_online.params.private.players = ""; } } @@ -63,29 +51,32 @@ tacticians_online.params.set_frequency = function (frequency) { tacticians_online.params.private.frequency = frequency; + + localStorage.setItem + ( + "frequency", + tacticians_online.params.private.frequency + ); } tacticians_online.params.set_players = function (players) { tacticians_online.params.private.players = players; + localStorage.setItem("players", tacticians_online.params.private.players); } -tacticians_online.params.store_new_params = +tacticians_online.params.store_params = function (params) { var [frequency, players] = params; tacticians_online.params.set_frequency(frequency); tacticians_online.params.set_players(players); - tacticians_online.params.store(); } tacticians_online.params.attach_to = function (app) { - app.ports.store_new_params.subscribe( - tacticians_online.params.store_new_params - ); - + app.ports.store_params.subscribe(tacticians_online.params.store_params); app.ports.reset_params.subscribe(tacticians_online.params.reset); } |


