| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Struct/Event.elm | 2 | ||||
| -rw-r--r-- | src/Struct/Model.elm | 15 | ||||
| -rw-r--r-- | src/Struct/Player.elm | 87 | ||||
| -rw-r--r-- | src/Struct/UI.elm | 62 | ||||
| -rw-r--r-- | src/View/BattleListing.elm | 92 | ||||
| -rw-r--r-- | src/View/Player.elm | 99 | 
6 files changed, 135 insertions, 222 deletions
| diff --git a/src/Struct/Event.elm b/src/Struct/Event.elm index 419ef51..3bf64d7 100644 --- a/src/Struct/Event.elm +++ b/src/Struct/Event.elm @@ -6,7 +6,6 @@ import Http  -- Main Menu -------------------------------------------------------------------  import Struct.Error  import Struct.ServerReply -import Struct.UI  --------------------------------------------------------------------------------  -- TYPES ----------------------------------------------------------------------- @@ -15,7 +14,6 @@ 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 = diff --git a/src/Struct/Model.elm b/src/Struct/Model.elm index 747a39e..8a4f75d 100644 --- a/src/Struct/Model.elm +++ b/src/Struct/Model.elm @@ -8,11 +8,10 @@ module Struct.Model exposing     )  -- Elm ------------------------------------------------------------------------- +import Array --- Shared ---------------------------------------------------------------------- +-- Extension -------------------------------------------------------------------  import Struct.Flags - --- Main Menu -------------------------------------------------------------------  import Struct.Error  import Struct.Player  import Struct.UI @@ -24,10 +23,7 @@ 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 +      players: (Array.Array Struct.Player.Type)     }  -------------------------------------------------------------------------------- @@ -42,10 +38,7 @@ new flags =     {        flags = flags,        error = Nothing, -      player_id = flags.user_id, -      session_token = flags.token, -      player = (Struct.Player.none), -      ui = (Struct.UI.default) +      players = (Array.new)     }  reset : Type -> Type diff --git a/src/Struct/Player.elm b/src/Struct/Player.elm index 73fbdb3..7221fb9 100644 --- a/src/Struct/Player.elm +++ b/src/Struct/Player.elm @@ -1,39 +1,34 @@  module Struct.Player exposing     (        Type, +      get_ix,        get_id,        get_username, -      get_maps,        get_campaigns,        get_invasions,        get_events, -      get_roster_id, -      get_inventory_id, -      decoder, -      none +      set_battles, +      has_active_battles     )  -- Elm -------------------------------------------------------------------------  import Json.Decode  import Json.Decode.Pipeline --- Main Menu ------------------------------------------------------------------- +-- Extension -------------------------------------------------------------------  import Struct.BattleSummary -import Struct.MapSummary  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  --------------------------------------------------------------------------------  type alias Type =     { +      ix : Int,        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 +      events : (List Struct.BattleSummary.Type)     }  -------------------------------------------------------------------------------- @@ -43,15 +38,15 @@ type alias Type =  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- +get_ix : Type -> Int +get_ix t = t.ix +  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 @@ -61,47 +56,29 @@ 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 +set_battles : ( +      (List Struct.BattleSummary.Type) -> +      (List Struct.BattleSummary.Type) -> +      (List Struct.BattleSummary.Type) -> +      Type ->        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 = "" +set_battles campaigns invasions events t = +   {t | +      campaigns = +         (List.filter (Struct.BattleSummary.is_players_turn) campaigns), +      invasions = +         (List.filter (Struct.BattleSummary.is_players_turn) invasions), +      events = (List.filter (Struct.BattleSummary.is_players_turn) events)     } + +has_active_battles : Type -> Bool +has_active_battles t = +   ( +      ( +         (List.length t.campaigns) +         + (List.length t.invasions) +         + (List.length t.events) +      ) +      > 0 +   ) diff --git a/src/Struct/UI.elm b/src/Struct/UI.elm deleted file mode 100644 index 6cf853c..0000000 --- a/src/Struct/UI.elm +++ /dev/null @@ -1,62 +0,0 @@ -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/View/BattleListing.elm b/src/View/BattleListing.elm deleted file mode 100644 index 9b667ac..0000000 --- a/src/View/BattleListing.elm +++ /dev/null @@ -1,92 +0,0 @@ -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/Player.elm b/src/View/Player.elm new file mode 100644 index 0000000..7d100e9 --- /dev/null +++ b/src/View/Player.elm @@ -0,0 +1,99 @@ +module View.Player exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes +-- import Html.Events + +-- Extension ------------------------------------------------------------------- +import Struct.BattleSummary +import Struct.Event +import Struct.Player + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_item_html : ( +      String -> +      String -> +      Struct.BattleSummary.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_item_html url_prefix additional_class item = +   (Html.a +      [ +         (Html.Attributes.class additional_class), +         (Html.Attributes.href +            ( +               url_prefix +               ++ (Struct.BattleSummary.get_id item) +            ) +         ) +      ] +      [ +         (Html.div +            [ +               (Html.Attributes.class "battle-summary-name") +            ] +            [ +               (Html.text (Struct.BattleSummary.get_name item)) +            ] +         ), +         (Html.div +            [ +               (Html.Attributes.class "battle-summary-date") +            ] +            [ +               (Html.text (Struct.BattleSummary.get_last_edit item)) +            ] +         ) +      ] +   ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : Struct.Player.Type -> (Html.Html Struct.Event.Type) +get_html player = +   let +      url_prefix = (Struct.Player.get_url_prefix player) +   in +      (Html.div +         [ +            (Html.Attributes.class "player-summary") +         ] +         [ +            (Html.div +               [ +                  (Html.Attributes.class "player-summary-listing-header") +               ] +               [ +                  (Html.text (Struct.Player.get_username player)) +               ] +            ), +            (Html.div +               [ +                  (Html.Attributes.class "player-summary-listing-body") +               ] +               ( +                  (List.map +                     (get_item_html url_prefix) +                     "campaign-link" +                     (Struct.Player.get_campaigns player) +                  ) +                  ++ +                  (List.map +                     (get_item_html url_prefix) +                     "invasion-link" +                     (Struct.Player.get_invasions player) +                  ) +                  ++ +                  (List.map +                     (get_item_html url_prefix) +                     "event-link" +                     (Struct.Player.get_events player) +                  ) +               ) +            ) +         ] +      ) | 


