summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-09-13 16:51:08 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-09-13 16:51:08 +0200
commit9ec5806bc721734923ff4c93f7ef1f97a6a03248 (patch)
treec80b737a8bf0cc6e311c4fe7256f68e7ea8e158a /src
Starting an browser extension for TO...
Diffstat (limited to 'src')
-rw-r--r--src/Comm/GetBattles.elm41
-rw-r--r--src/Comm/GetID.elm43
-rw-r--r--src/Comm/Okay.elm21
-rw-r--r--src/Comm/Send.elm67
-rw-r--r--src/Comm/SetPlayer.elm26
-rw-r--r--src/ElmModule/Init.elm18
-rw-r--r--src/ElmModule/Subscriptions.elm17
-rw-r--r--src/ElmModule/Update.elm38
-rw-r--r--src/ElmModule/View.elm64
-rw-r--r--src/Main.elm23
-rw-r--r--src/Struct/BattleSummary.elm65
-rw-r--r--src/Struct/Error.elm45
-rw-r--r--src/Struct/Event.elm25
-rw-r--r--src/Struct/Model.elm64
-rw-r--r--src/Struct/Player.elm107
-rw-r--r--src/Struct/ServerReply.elm23
-rw-r--r--src/Struct/UI.elm62
-rw-r--r--src/Update/HandleServerReply.elm104
-rw-r--r--src/View/BattleListing.elm92
-rw-r--r--src/View/Header.elm79
20 files changed, 1024 insertions, 0 deletions
diff --git a/src/Comm/GetBattles.elm b/src/Comm/GetBattles.elm
new file mode 100644
index 0000000..59b8d1d
--- /dev/null
+++ b/src/Comm/GetBattles.elm
@@ -0,0 +1,41 @@
+module Comm.GetBattles exposing (try)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Encode
+
+-- Extension -------------------------------------------------------------------
+import Comm.Send
+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 player_id =
+ (Comm.Send.try_sending
+ model
+ -- FIXME: this is a param now...
+ Constants.IO.get_battles_handler
+ (try_encoding player_id)
+ )
diff --git a/src/Comm/GetID.elm b/src/Comm/GetID.elm
new file mode 100644
index 0000000..14d668c
--- /dev/null
+++ b/src/Comm/GetID.elm
@@ -0,0 +1,43 @@
+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
new file mode 100644
index 0000000..ca7a2eb
--- /dev/null
+++ b/src/Comm/Okay.elm
@@ -0,0 +1,21 @@
+module Comm.Okay exposing (decode)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+decode : (Json.Decode.Decoder Struct.ServerReply.Type)
+decode = (Json.Decode.succeed Struct.ServerReply.Okay)
diff --git a/src/Comm/Send.elm b/src/Comm/Send.elm
new file mode 100644
index 0000000..dd9dc28
--- /dev/null
+++ b/src/Comm/Send.elm
@@ -0,0 +1,67 @@
+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.decode)
+ "set_battles" -> (Comm.SetBattles.decode)
+ other ->
+ (Json.Decode.fail
+ (
+ "Unknown server command \""
+ ++ other
+ ++ "\""
+ )
+ )
+
+decode : (Json.Decode.Decoder Struct.ServerReply.Type)
+decode =
+ (Json.Decode.field "msg" Json.Decode.string)
+ |> (Json.Decode.andThen (internal_decoder))
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+-- TODO: turn this into a multi-server version.
+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 (decode))
+ )
+ )
+ )
+
+ Nothing -> Nothing
diff --git a/src/Comm/SetPlayer.elm b/src/Comm/SetPlayer.elm
new file mode 100644
index 0000000..a595777
--- /dev/null
+++ b/src/Comm/SetPlayer.elm
@@ -0,0 +1,26 @@
+module Comm.SetPlayer exposing (decode)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Map -------------------------------------------------------------------------
+import Struct.Player
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+internal_decoder : Struct.Player.Type -> Struct.ServerReply.Type
+internal_decoder player =
+ (Struct.ServerReply.SetPlayer player)
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+decode : (Json.Decode.Decoder Struct.ServerReply.Type)
+decode =
+ (Json.Decode.map (internal_decoder) (Struct.Player.decoder))
diff --git a/src/ElmModule/Init.elm b/src/ElmModule/Init.elm
new file mode 100644
index 0000000..705cff7
--- /dev/null
+++ b/src/ElmModule/Init.elm
@@ -0,0 +1,18 @@
+module ElmModule.Init exposing (init)
+
+-- Elm -------------------------------------------------------------------------
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Event
+import Struct.Flags
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+init : Struct.Flags.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))
+init flags = (Struct.Model.new flags)
diff --git a/src/ElmModule/Subscriptions.elm b/src/ElmModule/Subscriptions.elm
new file mode 100644
index 0000000..e9b557e
--- /dev/null
+++ b/src/ElmModule/Subscriptions.elm
@@ -0,0 +1,17 @@
+module ElmModule.Subscriptions exposing (..)
+
+-- Elm -------------------------------------------------------------------------
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Model
+import Struct.Event
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+subscriptions : Struct.Model.Type -> (Sub Struct.Event.Type)
+subscriptions model = Sub.none
diff --git a/src/ElmModule/Update.elm b/src/ElmModule/Update.elm
new file mode 100644
index 0000000..18b2077
--- /dev/null
+++ b/src/ElmModule/Update.elm
@@ -0,0 +1,38 @@
+module ElmModule.Update exposing (update)
+
+-- Elm -------------------------------------------------------------------------
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Event
+import Struct.Model
+
+import Update.HandleServerReply
+import Update.SelectTab
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+update : (
+ Struct.Event.Type ->
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+update event model =
+ let
+ new_model = (Struct.Model.clear_error model)
+ in
+ case event of
+ Struct.Event.None -> (model, Cmd.none)
+
+ (Struct.Event.Failed err) ->
+ (
+ (Struct.Model.invalidate err new_model),
+ Cmd.none
+ )
+
+ (Struct.Event.ServerReplied result) ->
+ (Update.HandleServerReply.apply_to model result)
diff --git a/src/ElmModule/View.elm b/src/ElmModule/View.elm
new file mode 100644
index 0000000..0d6a321
--- /dev/null
+++ b/src/ElmModule/View.elm
@@ -0,0 +1,64 @@
+module ElmModule.View exposing (view)
+
+-- Elm -------------------------------------------------------------------------
+import Html
+import Html.Attributes
+
+-- Shared ----------------------------------------------------------------------
+import Util.Html
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Error
+import Struct.Event
+import Struct.Model
+import Struct.Player
+
+import View.BattleListing
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+view : Struct.Model.Type -> (Html.Html Struct.Event.Type)
+view model =
+ (Html.div
+ [
+ (Html.Attributes.class "fullscreen-module")
+ ]
+ [
+ (Html.main_
+ [
+ ]
+ [
+ (View.BattleListing.get_html
+ "Campaigns"
+ "main-menu-campaigns"
+ (Struct.Player.get_campaigns model.player)
+ ),
+ (View.BattleListing.get_html
+ "Invasions"
+ "main-menu-invasions"
+ (Struct.Player.get_invasions model.player)
+ ),
+ (View.BattleListing.get_html
+ "Events"
+ "main-menu-events"
+ (Struct.Player.get_events model.player)
+ )
+ ]
+ ),
+ (
+ case model.error of
+ Nothing -> (Util.Html.nothing)
+ (Just err) ->
+ (Html.div
+ []
+ [
+ (Html.text (Struct.Error.to_string err))
+ ]
+ )
+ )
+ ]
+ )
diff --git a/src/Main.elm b/src/Main.elm
new file mode 100644
index 0000000..8140041
--- /dev/null
+++ b/src/Main.elm
@@ -0,0 +1,23 @@
+-- Elm ------------------------------------------------------------------------
+import Html
+
+-- Map -------------------------------------------------------------------
+import Struct.Model
+import Struct.Event
+import Struct.Flags
+
+import ElmModule.Init
+import ElmModule.Subscriptions
+import ElmModule.View
+import ElmModule.Update
+
+main : (Program Struct.Flags.Type Struct.Model.Type Struct.Event.Type)
+main =
+ (Html.programWithFlags
+ {
+ init = ElmModule.Init.init,
+ view = ElmModule.View.view,
+ update = ElmModule.Update.update,
+ subscriptions = ElmModule.Subscriptions.subscriptions
+ }
+ )
diff --git a/src/Struct/BattleSummary.elm b/src/Struct/BattleSummary.elm
new file mode 100644
index 0000000..adab965
--- /dev/null
+++ b/src/Struct/BattleSummary.elm
@@ -0,0 +1,65 @@
+module Struct.BattleSummary exposing
+ (
+ Type,
+ get_id,
+ get_name,
+ get_last_edit,
+ is_players_turn,
+ decoder,
+ none
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Main Menu -------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- 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)
+ )
+
+none : Type
+none =
+ {
+ id = "",
+ name = "Unknown",
+ last_edit = "Never",
+ is_players_turn = False
+ }
diff --git a/src/Struct/Error.elm b/src/Struct/Error.elm
new file mode 100644
index 0000000..5f40c09
--- /dev/null
+++ b/src/Struct/Error.elm
@@ -0,0 +1,45 @@
+module Struct.Error exposing (Type, Mode(..), new, to_string)
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type Mode =
+ IllegalAction
+ | Programming
+ | Unimplemented
+ | Networking
+ | Failure
+
+type alias Type =
+ {
+ mode: Mode,
+ message: String
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+new : Mode -> String -> Type
+new mode str =
+ {
+ mode = mode,
+ message = str
+ }
+
+to_string : Type -> String
+to_string e =
+ (
+ (case e.mode of
+ Failure -> "The action failed: "
+ IllegalAction -> "Request discarded: "
+ Programming -> "Error in the program (please report): "
+ Unimplemented -> "Update discarded due to unimplemented feature: "
+ Networking -> "Error while conversing with the server: "
+ )
+ ++ e.message
+ )
+
diff --git a/src/Struct/Event.elm b/src/Struct/Event.elm
new file mode 100644
index 0000000..419ef51
--- /dev/null
+++ b/src/Struct/Event.elm
@@ -0,0 +1,25 @@
+module Struct.Event exposing (Type(..), attempted)
+
+-- Elm -------------------------------------------------------------------------
+import Http
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Error
+import Struct.ServerReply
+import Struct.UI
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type Type =
+ None
+ | Failed Struct.Error.Type
+ | ServerReplied (Result Http.Error (List Struct.ServerReply.Type))
+ | TabSelected Struct.UI.Tab
+
+attempted : (Result.Result err val) -> Type
+attempted act =
+ case act of
+ (Result.Ok _) -> None
+ (Result.Err msg) ->
+ (Failed (Struct.Error.new Struct.Error.Failure (toString msg)))
diff --git a/src/Struct/Model.elm b/src/Struct/Model.elm
new file mode 100644
index 0000000..747a39e
--- /dev/null
+++ b/src/Struct/Model.elm
@@ -0,0 +1,64 @@
+module Struct.Model exposing
+ (
+ Type,
+ new,
+ invalidate,
+ reset,
+ clear_error
+ )
+
+-- Elm -------------------------------------------------------------------------
+
+-- Shared ----------------------------------------------------------------------
+import Struct.Flags
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Error
+import Struct.Player
+import Struct.UI
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ flags: Struct.Flags.Type,
+ error: (Maybe Struct.Error.Type),
+ player_id: String,
+ session_token: String,
+ player: Struct.Player.Type,
+ ui: Struct.UI.Type
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+new : Struct.Flags.Type -> Type
+new flags =
+ {
+ flags = flags,
+ error = Nothing,
+ player_id = flags.user_id,
+ session_token = flags.token,
+ player = (Struct.Player.none),
+ ui = (Struct.UI.default)
+ }
+
+reset : Type -> Type
+reset model =
+ {model |
+ error = Nothing
+ }
+
+invalidate : Struct.Error.Type -> Type -> Type
+invalidate err model =
+ {model |
+ error = (Just err)
+ }
+
+clear_error : Type -> Type
+clear_error model = {model | error = Nothing}
diff --git a/src/Struct/Player.elm b/src/Struct/Player.elm
new file mode 100644
index 0000000..73fbdb3
--- /dev/null
+++ b/src/Struct/Player.elm
@@ -0,0 +1,107 @@
+module Struct.Player exposing
+ (
+ Type,
+ get_id,
+ get_username,
+ get_maps,
+ get_campaigns,
+ get_invasions,
+ get_events,
+ get_roster_id,
+ get_inventory_id,
+ decoder,
+ none
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.BattleSummary
+import Struct.MapSummary
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ id : String,
+ name : String,
+ maps : (List Struct.MapSummary.Type),
+ campaigns : (List Struct.BattleSummary.Type),
+ invasions : (List Struct.BattleSummary.Type),
+ events : (List Struct.BattleSummary.Type),
+ roster_id : String,
+ inventory_id : String
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_id : Type -> String
+get_id t = t.id
+
+get_username : Type -> String
+get_username t = t.name
+
+get_maps : Type -> (List Struct.MapSummary.Type)
+get_maps t = t.maps
+
+get_campaigns : Type -> (List Struct.BattleSummary.Type)
+get_campaigns t = t.campaigns
+
+get_invasions : Type -> (List Struct.BattleSummary.Type)
+get_invasions t = t.invasions
+
+get_events : Type -> (List Struct.BattleSummary.Type)
+get_events t = t.events
+
+get_roster_id : Type -> String
+get_roster_id t = t.roster_id
+
+get_inventory_id : Type -> String
+get_inventory_id t = t.inventory_id
+
+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
+ "maps"
+ (Json.Decode.list Struct.MapSummary.decoder)
+ )
+ |> (Json.Decode.Pipeline.required
+ "cmps"
+ (Json.Decode.list Struct.BattleSummary.decoder)
+ )
+ |> (Json.Decode.Pipeline.required
+ "invs"
+ (Json.Decode.list Struct.BattleSummary.decoder)
+ )
+ |> (Json.Decode.Pipeline.required
+ "evts"
+ (Json.Decode.list Struct.BattleSummary.decoder)
+ )
+ |> (Json.Decode.Pipeline.required "rtid" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "ivid" Json.Decode.string)
+ )
+
+none : Type
+none =
+ {
+ id = "",
+ name = "Unknown",
+ maps = [],
+ campaigns = [],
+ invasions = [],
+ events = [],
+ roster_id = "",
+ inventory_id = ""
+ }
diff --git a/src/Struct/ServerReply.elm b/src/Struct/ServerReply.elm
new file mode 100644
index 0000000..fb4967b
--- /dev/null
+++ b/src/Struct/ServerReply.elm
@@ -0,0 +1,23 @@
+module Struct.ServerReply exposing (Type(..))
+
+-- Elm -------------------------------------------------------------------------
+
+-- Main Menu -------------------------------------------------------------------
+import Struct.Player
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+type Type =
+ Okay
+ | Disconnected
+ | SetPlayer Struct.Player.Type
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
diff --git a/src/Struct/UI.elm b/src/Struct/UI.elm
new file mode 100644
index 0000000..6cf853c
--- /dev/null
+++ b/src/Struct/UI.elm
@@ -0,0 +1,62 @@
+module Struct.UI exposing
+ (
+ Type,
+ Tab(..),
+ default,
+ -- Tab
+ try_getting_displayed_tab,
+ set_displayed_tab,
+ reset_displayed_tab,
+ to_string
+ )
+
+-- Main Menu -------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type Tab =
+ CampaignsTab
+ | InvasionsTab
+ | EventsTab
+ | CharactersTab
+ | MapsEditorTab
+ | AccountTab
+
+type alias Type =
+ {
+ displayed_tab : (Maybe Tab)
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+default : Type
+default =
+ {
+ displayed_tab = Nothing
+ }
+
+-- Tab -------------------------------------------------------------------------
+try_getting_displayed_tab : Type -> (Maybe Tab)
+try_getting_displayed_tab ui = ui.displayed_tab
+
+set_displayed_tab : Tab -> Type -> Type
+set_displayed_tab tab ui = {ui | displayed_tab = (Just tab)}
+
+reset_displayed_tab : Type -> Type
+reset_displayed_tab ui = {ui | displayed_tab = Nothing}
+
+to_string : Tab -> String
+to_string tab =
+ case tab of
+ CampaignsTab -> "Campaigns"
+ InvasionsTab -> "Invasions"
+ EventsTab -> "Events"
+ CharactersTab -> "Character Editor"
+ MapsEditorTab -> "Map Editor"
+ AccountTab -> "Account Settings"
diff --git a/src/Update/HandleServerReply.elm b/src/Update/HandleServerReply.elm
new file mode 100644
index 0000000..d68496c
--- /dev/null
+++ b/src/Update/HandleServerReply.elm
@@ -0,0 +1,104 @@
+module Update.HandleServerReply exposing (apply_to)
+
+-- Elm -------------------------------------------------------------------------
+import Http
+
+-- Shared ----------------------------------------------------------------------
+import Action.Ports
+
+import Struct.Flags
+
+-- Main Menu -------------------------------------------------------------------
+import Constants.IO
+
+import Struct.Error
+import Struct.Event
+import Struct.Model
+import Struct.Player
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+disconnected : (
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type)))
+ )
+disconnected current_state =
+ let (model, cmds) = current_state in
+ (
+ model,
+ [
+ (Action.Ports.go_to
+ (
+ Constants.IO.base_url
+ ++ "/login/?action=disconnect&goto="
+ ++
+ (Http.encodeUri
+ (
+ "/main-menu/?"
+ ++ (Struct.Flags.get_params_as_url model.flags)
+ )
+ )
+ )
+ )
+ ]
+ )
+
+set_player : (
+ Struct.Player.Type ->
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type)))
+ )
+set_player player current_state =
+ let (model, cmds) = current_state in
+ ({model | player = player}, cmds)
+
+apply_command : (
+ Struct.ServerReply.Type ->
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->
+ (Struct.Model.Type, (List (Cmd Struct.Event.Type)))
+ )
+apply_command command current_state =
+ case command of
+ Struct.ServerReply.Disconnected -> (disconnected current_state)
+ (Struct.ServerReply.SetPlayer player) -> (set_player player current_state)
+ Struct.ServerReply.Okay -> current_state
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ (Result Http.Error (List Struct.ServerReply.Type)) ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model query_result =
+ case query_result of
+ (Result.Err error) ->
+ (
+ (Struct.Model.invalidate
+ (Struct.Error.new Struct.Error.Networking (toString error))
+ model
+ ),
+ Cmd.none
+ )
+
+ (Result.Ok commands) ->
+ let
+ (new_model, elm_commands) =
+ (List.foldl (apply_command) (model, [Cmd.none]) commands)
+ in
+ (
+ new_model,
+ (
+ case elm_commands of
+ [] -> Cmd.none
+ [cmd] -> cmd
+ _ -> (Cmd.batch elm_commands)
+ )
+ )
diff --git a/src/View/BattleListing.elm b/src/View/BattleListing.elm
new file mode 100644
index 0000000..9b667ac
--- /dev/null
+++ b/src/View/BattleListing.elm
@@ -0,0 +1,92 @@
+module View.BattleListing exposing (get_html)
+
+-- Elm -------------------------------------------------------------------------
+import Html
+import Html.Attributes
+-- import Html.Events
+
+-- Map -------------------------------------------------------------------
+import Struct.BattleSummary
+import Struct.Event
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_item_html : Struct.BattleSummary.Type -> (Html.Html Struct.Event.Type)
+get_item_html item =
+ (Html.a
+ [
+ (Html.Attributes.href
+ (
+ "/battle/?id="
+ ++ (Struct.BattleSummary.get_id item)
+ )
+ ),
+ (
+ if (Struct.BattleSummary.is_players_turn item)
+ then
+ (Html.Attributes.class "main-menu-battle-summary-is-active")
+ else
+ (Html.Attributes.class "main-menu-battle-summary-is-inactive")
+ )
+ ]
+ [
+ (Html.div
+ [
+ (Html.Attributes.class "main-menu-battle-summary-name")
+ ]
+ [
+ (Html.text (Struct.BattleSummary.get_name item))
+ ]
+ ),
+ (Html.div
+ [
+ (Html.Attributes.class "main-menu-battle-summary-date")
+ ]
+ [
+ (Html.text (Struct.BattleSummary.get_last_edit item))
+ ]
+ )
+ ]
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_html : (
+ String ->
+ String ->
+ (List Struct.BattleSummary.Type) ->
+ (Html.Html Struct.Event.Type)
+ )
+get_html name class battle_summaries =
+ (Html.div
+ [
+ (Html.Attributes.class class),
+ (Html.Attributes.class "main-menu-battle-listing")
+ ]
+ [
+ (Html.div
+ [
+ (Html.Attributes.class "main-menu-battle-listing-header")
+ ]
+ [
+ (Html.text name)
+ ]
+ ),
+ (Html.div
+ [
+ (Html.Attributes.class "main-menu-battle-listing-body")
+ ]
+ (List.map (get_item_html) battle_summaries)
+ ),
+ (Html.div
+ [
+ (Html.Attributes.class "main-menu-battle-listing-add-new")
+ ]
+ [
+ (Html.text "New")
+ ]
+ )
+ ]
+ )
diff --git a/src/View/Header.elm b/src/View/Header.elm
new file mode 100644
index 0000000..fd8e693
--- /dev/null
+++ b/src/View/Header.elm
@@ -0,0 +1,79 @@
+module View.Header exposing (get_html)
+
+-- Elm -------------------------------------------------------------------------
+import Html
+import Html.Attributes
+
+-- Map -------------------------------------------------------------------
+import Struct.Event
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+link_html : String -> String -> Bool -> (Html.Html Struct.Event.Type)
+link_html src label is_active =
+ (Html.a
+ [
+ (Html.Attributes.href src)
+ ]
+ [
+ (
+ if (is_active)
+ then (Html.text label)
+ else (Html.s [] [(Html.text label)])
+ )
+ ]
+ )
+
+navigation_html : (Html.Html Struct.Event.Type)
+navigation_html =
+ (Html.nav
+ []
+ [
+ (link_html "/about.html" "About" True),
+ (link_html "/news/" "News" False),
+ (link_html "/community/" "Community" False),
+ (link_html "/login/?action=disconnect" "Disconnect" True)
+ ]
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_html : (Html.Html Struct.Event.Type)
+get_html =
+ (Html.header
+ []
+ [
+ (Html.div
+ [
+ (Html.Attributes.class "main-server-logo")
+ ]
+ [
+ (Html.a
+ [
+ (Html.Attributes.href "http://127.0.0.1")
+ ]
+ [
+ (Html.img
+ [
+ (Html.Attributes.src "/asset/svg/to-logo-no-bg.svg")
+ ]
+ [
+ ]
+ )
+ ]
+ )
+ ]
+ ),
+ (Html.div
+ [
+ (Html.Attributes.class "main-server-version")
+ ]
+ [
+ (Html.text "Latest Dev. Build (Mon, 10 Sep 2018 10:30:17 +0000)")
+ ]
+ ),
+ (navigation_html)
+ ]
+ )