| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | src/Action/Ports.elm | 4 | ||||
| -rw-r--r-- | src/Struct/Flags.elm | 24 | ||||
| -rw-r--r-- | www/index.html | 7 | ||||
| -rw-r--r-- | www/script/load.js | 12 | ||||
| -rw-r--r-- | www/script/params.js | 91 |
6 files changed, 120 insertions, 20 deletions
diff --git a/manifest.json b/manifest.json index f9fb2e6..04eeb32 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "Tacticians Online - Active Battles", - "manifest_version": 1, + "manifest_version": 2, "version": "0.1", "description": diff --git a/src/Action/Ports.elm b/src/Action/Ports.elm new file mode 100644 index 0000000..c79d918 --- /dev/null +++ b/src/Action/Ports.elm @@ -0,0 +1,4 @@ +port module Action.Ports exposing (..) + +port store_new_params : (Int, (List String)) -> (Cmd msg) +port reset_params : () -> (Cmd msg) diff --git a/src/Struct/Flags.elm b/src/Struct/Flags.elm index 0e2ca14..ccda57a 100644 --- a/src/Struct/Flags.elm +++ b/src/Struct/Flags.elm @@ -1,7 +1,8 @@ module Struct.Flags exposing ( Type, - maybe_get_param + get_frequency, + get_players ) -- Elm ------------------------------------------------------------------------- @@ -15,7 +16,8 @@ import Util.List -------------------------------------------------------------------------------- type alias Type = { - url_params : (List (List String)) + frequency : Int, + players : (List String) } -------------------------------------------------------------------------------- @@ -25,16 +27,8 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -maybe_get_param : String -> Type -> (Maybe String) -maybe_get_param param flags = - case - (Util.List.get_first - (\e -> ((List.head e) == (Just param))) - flags.url_params - ) - of - Nothing -> Nothing - (Just a) -> - case (List.tail a) of - Nothing -> Nothing - (Just b) -> (List.head b) +get_frequency : Type -> Int +get_frequency flags = flags.frequency + +get_players : Type -> (List String) +get_players flags = flags.players diff --git a/www/index.html b/www/index.html index f0fc53c..10a422b 100644 --- a/www/index.html +++ b/www/index.html @@ -4,9 +4,8 @@ <link rel="stylesheet" type="text/css" href="/style.css"> </head> <body> - <script src="script/main.js"></script> - <script> - tacticians_online_app = Elm.Main.fullscreen(); - </script> + <script src="/www/script/params.js"></script> + <script src="/www/script/main.js"></script> + <script src="/www/script/load.js"></script> </body> </html> diff --git a/www/script/load.js b/www/script/load.js new file mode 100644 index 0000000..c09570b --- /dev/null +++ b/www/script/load.js @@ -0,0 +1,12 @@ +tacticians_online.params.load(); + +tacticians_online.app = + Elm.Main.fullscreen + ( + { + frequency: tacticians_online.params.get_frequency(), + players: tacticians_online.params.get_players() + } + ); + +tacticians_online.params.attach_to(tacticians_online.app); diff --git a/www/script/params.js b/www/script/params.js new file mode 100644 index 0000000..440a491 --- /dev/null +++ b/www/script/params.js @@ -0,0 +1,91 @@ +/******************************************************************************/ +/** Session Management ********************************************************/ +/******************************************************************************/ +var tacticians_online = tacticians_online || new Object(); + +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.reset = +function () +{ + localStorage.removeItem("frequency"); + localStorage.removeItem("players"); +} + +tacticians_online.params.load = +function () +{ + tacticians_online.params.private.frequency = + localStorage.getItem("frequency"); + + tacticians_online.params.private.players = localStorage.getItem("players"); + + if (tacticians_online.params.private.frequency == null) + { + tacticians_online.params.private.frequency = 15; + } + + if (tacticians_online.params.private.players == null) + { + tacticians_online.params.private.players = []; + } +} + +tacticians_online.params.get_frequency = +function () +{ + return tacticians_online.params.private.frequency; +} + +tacticians_online.params.get_players = +function () +{ + return tacticians_online.params.private.players; +} + +tacticians_online.params.set_frequency = +function (frequency) +{ + tacticians_online.params.private.frequency = frequency; +} + +tacticians_online.params.set_players = +function (players) +{ + tacticians_online.params.private.players = players; +} + +tacticians_online.params.store_new_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.reset_params.subscribe(tacticians_online.params.reset); +} |


