summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-09-13 18:30:08 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-09-13 18:30:08 +0200
commitc414c2b9127921d77237d0ad018b87ad044915e8 (patch)
tree1ceac28975e30e1af45bbd9816da0943ec638384
parent317037f9cca1109b4fb6825482c5bbb46b4c567b (diff)
...
-rw-r--r--src/ElmModule/Init.elm2
-rw-r--r--src/ElmModule/Update.elm1
-rw-r--r--src/ElmModule/View.elm35
-rw-r--r--src/Struct/Flags.elm40
-rw-r--r--src/Struct/Model.elm3
-rw-r--r--src/Struct/Player.elm21
-rw-r--r--src/Struct/ServerReply.elm3
-rw-r--r--src/Update/HandleServerReply.elm40
-rw-r--r--src/Util/Array.elm34
-rw-r--r--src/Util/Html.elm6
-rw-r--r--src/Util/List.elm36
-rw-r--r--src/View/Player.elm9
12 files changed, 151 insertions, 79 deletions
diff --git a/src/ElmModule/Init.elm b/src/ElmModule/Init.elm
index 705cff7..ccb3595 100644
--- a/src/ElmModule/Init.elm
+++ b/src/ElmModule/Init.elm
@@ -15,4 +15,4 @@ import Struct.Model
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
init : Struct.Flags.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))
-init flags = (Struct.Model.new flags)
+init flags = ((Struct.Model.new flags), Cmd.none)
diff --git a/src/ElmModule/Update.elm b/src/ElmModule/Update.elm
index 18b2077..5baa84c 100644
--- a/src/ElmModule/Update.elm
+++ b/src/ElmModule/Update.elm
@@ -7,7 +7,6 @@ import Struct.Event
import Struct.Model
import Update.HandleServerReply
-import Update.SelectTab
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
diff --git a/src/ElmModule/View.elm b/src/ElmModule/View.elm
index 0d6a321..3f0a16f 100644
--- a/src/ElmModule/View.elm
+++ b/src/ElmModule/View.elm
@@ -1,19 +1,19 @@
module ElmModule.View exposing (view)
-- Elm -------------------------------------------------------------------------
+import Array
+
import Html
import Html.Attributes
--- Shared ----------------------------------------------------------------------
+-- Extension -------------------------------------------------------------------
import Util.Html
--- Main Menu -------------------------------------------------------------------
import Struct.Error
import Struct.Event
import Struct.Model
-import Struct.Player
-import View.BattleListing
+import View.Player
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -27,28 +27,7 @@ view model =
[
(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)
@@ -60,5 +39,7 @@ view model =
]
)
)
- ]
+ ::
+ (List.map (View.Player.get_html) (Array.toList model.players))
+ )
)
diff --git a/src/Struct/Flags.elm b/src/Struct/Flags.elm
new file mode 100644
index 0000000..0e2ca14
--- /dev/null
+++ b/src/Struct/Flags.elm
@@ -0,0 +1,40 @@
+module Struct.Flags exposing
+ (
+ Type,
+ maybe_get_param
+ )
+
+-- Elm -------------------------------------------------------------------------
+import List
+
+-- Shared ----------------------------------------------------------------------
+import Util.List
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ url_params : (List (List String))
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- 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)
diff --git a/src/Struct/Model.elm b/src/Struct/Model.elm
index 8a4f75d..6d4a588 100644
--- a/src/Struct/Model.elm
+++ b/src/Struct/Model.elm
@@ -14,7 +14,6 @@ import Array
import Struct.Flags
import Struct.Error
import Struct.Player
-import Struct.UI
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -38,7 +37,7 @@ new flags =
{
flags = flags,
error = Nothing,
- players = (Array.new)
+ players = (Array.empty)
}
reset : Type -> Type
diff --git a/src/Struct/Player.elm b/src/Struct/Player.elm
index 7221fb9..6a81daf 100644
--- a/src/Struct/Player.elm
+++ b/src/Struct/Player.elm
@@ -2,8 +2,13 @@ module Struct.Player exposing
(
Type,
get_ix,
+ set_ix,
get_id,
+ set_id,
+ get_url_prefix,
+ set_url_prefix,
get_username,
+ set_username,
get_campaigns,
get_invasions,
get_events,
@@ -26,6 +31,7 @@ type alias Type =
ix : Int,
id : String,
name : String,
+ url_prefix : String,
campaigns : (List Struct.BattleSummary.Type),
invasions : (List Struct.BattleSummary.Type),
events : (List Struct.BattleSummary.Type)
@@ -41,12 +47,27 @@ type alias Type =
get_ix : Type -> Int
get_ix t = t.ix
+set_ix : Int -> Type -> Type
+set_ix val t = {t | ix = val}
+
get_id : Type -> String
get_id t = t.id
+set_id : String -> Type -> Type
+set_id str t = {t | id = str}
+
get_username : Type -> String
get_username t = t.name
+set_username : String -> Type -> Type
+set_username str t = {t | name = str}
+
+get_url_prefix : Type -> String
+get_url_prefix t = t.url_prefix
+
+set_url_prefix : String -> Type -> Type
+set_url_prefix str t = {t | url_prefix = str}
+
get_campaigns : Type -> (List Struct.BattleSummary.Type)
get_campaigns t = t.campaigns
diff --git a/src/Struct/ServerReply.elm b/src/Struct/ServerReply.elm
index fb4967b..65fc063 100644
--- a/src/Struct/ServerReply.elm
+++ b/src/Struct/ServerReply.elm
@@ -11,8 +11,7 @@ import Struct.Player
type Type =
Okay
- | Disconnected
- | SetPlayer Struct.Player.Type
+-- | SetBattles (List, List, List)
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
diff --git a/src/Update/HandleServerReply.elm b/src/Update/HandleServerReply.elm
index d68496c..271ecfb 100644
--- a/src/Update/HandleServerReply.elm
+++ b/src/Update/HandleServerReply.elm
@@ -4,13 +4,9 @@ module Update.HandleServerReply exposing (apply_to)
import Http
-- Shared ----------------------------------------------------------------------
-import Action.Ports
-
import Struct.Flags
-- Main Menu -------------------------------------------------------------------
-import Constants.IO
-
import Struct.Error
import Struct.Event
import Struct.Model
@@ -24,40 +20,6 @@ import Struct.ServerReply
--------------------------------------------------------------------------------
-- 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))) ->
@@ -65,8 +27,6 @@ apply_command : (
)
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
--------------------------------------------------------------------------------
diff --git a/src/Util/Array.elm b/src/Util/Array.elm
new file mode 100644
index 0000000..9e57c18
--- /dev/null
+++ b/src/Util/Array.elm
@@ -0,0 +1,34 @@
+module Util.Array exposing
+ (
+ update,
+ update_unsafe,
+ filter_first
+ )
+
+import Array
+
+update : (
+ Int ->
+ ((Maybe t) -> (Maybe t)) ->
+ (Array.Array t) ->
+ (Array.Array t)
+ )
+update index fun array =
+ case (fun (Array.get index array)) of
+ Nothing -> array
+ (Just e) -> (Array.set index e array)
+
+update_unsafe : (
+ Int ->
+ (t -> t) ->
+ (Array.Array t) ->
+ (Array.Array t)
+ )
+update_unsafe index fun array =
+ case (Array.get index array) of
+ Nothing -> array
+ (Just e) -> (Array.set index (fun e) array)
+
+filter_first : (t -> Bool) -> (Array.Array t) -> (Maybe t)
+filter_first fun array =
+ (Array.get 0 (Array.filter fun array))
diff --git a/src/Util/Html.elm b/src/Util/Html.elm
new file mode 100644
index 0000000..42eadba
--- /dev/null
+++ b/src/Util/Html.elm
@@ -0,0 +1,6 @@
+module Util.Html exposing (nothing)
+
+import Html
+
+nothing : (Html.Html a)
+nothing = (Html.text "")
diff --git a/src/Util/List.elm b/src/Util/List.elm
new file mode 100644
index 0000000..1f914b1
--- /dev/null
+++ b/src/Util/List.elm
@@ -0,0 +1,36 @@
+module Util.List exposing (..)
+
+import List
+
+pop : List a -> (Maybe (a, List a))
+pop l =
+ case
+ ((List.head l), (List.tail l))
+ of
+ (Nothing, _) -> Nothing
+ (_ , Nothing) -> Nothing
+ ((Just head), (Just tail)) -> (Just (head, tail))
+
+get_first : (a -> Bool) -> (List a) -> (Maybe a)
+get_first fun list =
+ (List.head (List.filter fun list))
+
+product_map : (a -> b -> c) -> (List a) -> (List b) -> (List c)
+product_map product_fun list_a list_b =
+ (product_map_rec (product_fun) list_a list_b [])
+
+product_map_rec : (a -> b -> c) -> (List a) -> (List b) -> (List c) -> (List c)
+product_map_rec product_fun list_a list_b result =
+ case (pop list_a) of
+ Nothing -> result
+ (Just (head, tail)) ->
+ (product_map_rec
+ (product_fun)
+ tail
+ list_b
+ (List.append
+ (List.map (product_fun head) list_b)
+ result
+ )
+ )
+
diff --git a/src/View/Player.elm b/src/View/Player.elm
index 7d100e9..2e45463 100644
--- a/src/View/Player.elm
+++ b/src/View/Player.elm
@@ -77,20 +77,17 @@ get_html player =
]
(
(List.map
- (get_item_html url_prefix)
- "campaign-link"
+ (get_item_html url_prefix "campaign-link")
(Struct.Player.get_campaigns player)
)
++
(List.map
- (get_item_html url_prefix)
- "invasion-link"
+ (get_item_html url_prefix "invasion-link")
(Struct.Player.get_invasions player)
)
++
(List.map
- (get_item_html url_prefix)
- "event-link"
+ (get_item_html url_prefix "event-link")
(Struct.Player.get_events player)
)
)