| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main-menu/src/ElmModule/Update.elm | 7 | ||||
| -rw-r--r-- | src/main-menu/src/ElmModule/View.elm | 28 | ||||
| -rw-r--r-- | src/main-menu/src/Struct/BattleSummary.elm | 19 | ||||
| -rw-r--r-- | src/main-menu/src/Struct/InvasionRequest.elm | 114 | ||||
| -rw-r--r-- | src/main-menu/src/Struct/UI.elm | 60 | ||||
| -rw-r--r-- | src/main-menu/src/Update/HandleNewInvasion.elm (renamed from src/main-menu/src/Update/SelectTab.elm) | 32 | ||||
| -rw-r--r-- | src/main-menu/src/View/CurrentTab.elm | 56 | ||||
| -rw-r--r-- | src/main-menu/src/View/Invasions.elm | 1 | 
8 files changed, 247 insertions, 70 deletions
| diff --git a/src/main-menu/src/ElmModule/Update.elm b/src/main-menu/src/ElmModule/Update.elm index 3f2db04..04e1310 100644 --- a/src/main-menu/src/ElmModule/Update.elm +++ b/src/main-menu/src/ElmModule/Update.elm @@ -6,8 +6,8 @@ module ElmModule.Update exposing (update)  import Struct.Event  import Struct.Model +import Update.HandleNewInvasion  import Update.HandleServerReply -import Update.SelectTab  --------------------------------------------------------------------------------  -- LOCAL ----------------------------------------------------------------------- @@ -38,7 +38,6 @@ update event model =           (Update.HandleServerReply.apply_to model result)        (Struct.Event.NewInvasion ix) -> -         (model, Cmd.none) +         (Update.HandleNewInvasion.apply_to new_model ix) -      (Struct.Event.TabSelected tab) -> -         (Update.SelectTab.apply_to new_model tab) +      (Struct.Event.TabSelected tab) -> (model, Cmd.none) diff --git a/src/main-menu/src/ElmModule/View.elm b/src/main-menu/src/ElmModule/View.elm index a48238c..561f924 100644 --- a/src/main-menu/src/ElmModule/View.elm +++ b/src/main-menu/src/ElmModule/View.elm @@ -11,13 +11,9 @@ import Util.Html  import Struct.Error  import Struct.Event  import Struct.Model -import Struct.Player -import View.BattleListing -import View.Invasions  import View.Header -import View.MapListing -import View.Roster +import View.CurrentTab  --------------------------------------------------------------------------------  -- LOCAL ----------------------------------------------------------------------- @@ -34,27 +30,7 @@ view model =        ]        [           (View.Header.get_html), -         (Html.main_ -            [ -            ] -            [ -               (View.BattleListing.get_html -                  "Campaigns" -                  "main-menu-campaigns" -                  (Struct.Player.get_campaigns model.player) -               ), -               (View.Invasions.get_html -                  (Struct.Player.get_invasions model.player) -               ), -               (View.BattleListing.get_html -                  "Events" -                  "main-menu-events" -                  (Struct.Player.get_events model.player) -               ), -               (View.MapListing.get_html (Struct.Player.get_maps model.player)), -               (View.Roster.get_html) -            ] -         ), +         (View.CurrentTab.get_html model),           (              case model.error of                 Nothing -> (Util.Html.nothing) diff --git a/src/main-menu/src/Struct/BattleSummary.elm b/src/main-menu/src/Struct/BattleSummary.elm index adab965..c67ef04 100644 --- a/src/main-menu/src/Struct/BattleSummary.elm +++ b/src/main-menu/src/Struct/BattleSummary.elm @@ -1,10 +1,13 @@  module Struct.BattleSummary exposing     (        Type, +      InvasionCategory(..),        get_id,        get_name,        get_last_edit,        is_players_turn, +      is_empty_slot, +      get_invasion_category,        decoder,        none     ) @@ -18,6 +21,11 @@ import Json.Decode.Pipeline  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +type InvasionCategory = +   InvasionAttack +   | InvasionDefend +   | InvasionEither +  type alias Type =     {        id : String, @@ -45,6 +53,17 @@ get_last_edit t = t.last_edit  is_players_turn : Type -> Bool  is_players_turn t = t.is_players_turn +is_empty_slot : Type -> Bool +is_empty_slot t = (t.id == "") + +get_invasion_category : Int -> InvasionCategory +get_invasion_category ix = +   if (ix < 3) +   then InvasionAttack +   else if (ix < 6) +   then InvasionEither +   else InvasionDefend +  decoder : (Json.Decode.Decoder Type)  decoder =     (Json.Decode.Pipeline.decode diff --git a/src/main-menu/src/Struct/InvasionRequest.elm b/src/main-menu/src/Struct/InvasionRequest.elm new file mode 100644 index 0000000..46e1304 --- /dev/null +++ b/src/main-menu/src/Struct/InvasionRequest.elm @@ -0,0 +1,114 @@ +module Struct.InvasionRequest exposing +   ( +      Type, +      Size(..), +      new, +      get_ix, +      get_category, +      get_size, +      get_map_id, +      set_category, +      set_size, +      set_map_id, +      get_url_params +   ) + +-- Elm ------------------------------------------------------------------------- + +-- Main Menu ------------------------------------------------------------------- +import Struct.BattleSummary + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Size = +   Small +   | Medium +   | Large + +type alias Type = +   { +      ix : Int, +      category : Struct.BattleSummary.InvasionCategory, +      size : (Maybe Size), +      map_id : String +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Int -> Type +new ix = +   { +      ix = ix, +      category = (Struct.BattleSummary.get_invasion_category ix), +      size = Nothing, +      map_id = "" +   } + +get_ix : Type -> Int +get_ix ir = ir.ix + +get_category : Type -> Struct.BattleSummary.InvasionCategory +get_category ir = ir.category + +set_category : Struct.BattleSummary.InvasionCategory -> Type -> Type +set_category cat ir = {ir | category = cat} + +get_size : Type -> (Maybe Size) +get_size ir = ir.size + +set_size : (Maybe Size) -> Type -> Type +set_size s ir = {ir | size = s} + +get_map_id : Type -> String +get_map_id ir = ir.map_id + +set_map_id : String -> Type -> Type +set_map_id id ir = {ir | map_id = id} + +get_url_params : Type -> (Maybe String) +get_url_params ir = +   case (ir.category, ir.size) of +      (Struct.BattleSummary.InvasionEither, _) -> Nothing +      (_, Nothing) -> Nothing +      (Struct.BattleSummary.InvasionAttack, (Just size)) -> +         (Just +            ( +               "?m=a&ix=" +               ++ (toString ir.ix) +               ++ "&s=" +               ++ +               ( +                  case size of +                     Small -> "s" +                     Medium -> "m" +                     Large -> "l" +               ) +            ) +         ) + +      (Struct.BattleSummary.InvasionDefend, (Just size)) -> +         if (ir.map_id == "") +         then Nothing +         else +            (Just +               ( +                  "?m=a&ix=" +                  ++ (toString ir.ix) +                  ++ "&map_id=" +                  ++ ir.map_id +                  ++ "&s=" +                  ++ +                  ( +                     case size of +                        Small -> "s" +                        Medium -> "m" +                        Large -> "l" +                  ) +               ) +            ) diff --git a/src/main-menu/src/Struct/UI.elm b/src/main-menu/src/Struct/UI.elm index 6cf853c..7539e90 100644 --- a/src/main-menu/src/Struct/UI.elm +++ b/src/main-menu/src/Struct/UI.elm @@ -1,31 +1,37 @@  module Struct.UI exposing     (        Type, +      Action(..),        Tab(..),        default,        -- Tab -      try_getting_displayed_tab, -      set_displayed_tab, -      reset_displayed_tab, -      to_string +      get_current_tab, +      set_current_tab, +      reset_current_tab, +      to_string, +      -- Action +      get_action, +      set_action     )  -- Main Menu ------------------------------------------------------------------- +import Struct.InvasionRequest  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  --------------------------------------------------------------------------------  type Tab = -   CampaignsTab -   | InvasionsTab -   | EventsTab -   | CharactersTab -   | MapsEditorTab -   | AccountTab +   DefaultTab +   | NewInvasionTab + +type Action = +   None +   | NewInvasion Struct.InvasionRequest.Type  type alias Type =     { -      displayed_tab : (Maybe Tab) +      current_tab : Tab, +      action : Action     }  -------------------------------------------------------------------------------- @@ -38,25 +44,31 @@ type alias Type =  default : Type  default =     { -      displayed_tab = Nothing +      current_tab = DefaultTab, +      action = None     }  -- Tab ------------------------------------------------------------------------- -try_getting_displayed_tab : Type -> (Maybe Tab) -try_getting_displayed_tab ui = ui.displayed_tab +get_current_tab : Type -> Tab +get_current_tab ui = +   case ui.action of +      None -> ui.current_tab +      (NewInvasion _) -> NewInvasionTab -set_displayed_tab : Tab -> Type -> Type -set_displayed_tab tab ui = {ui | displayed_tab = (Just tab)} +set_current_tab : Tab -> Type -> Type +set_current_tab tab ui = {ui | current_tab = tab} -reset_displayed_tab : Type -> Type -reset_displayed_tab ui = {ui | displayed_tab = Nothing} +reset_current_tab : Type -> Type +reset_current_tab ui = {ui | current_tab = DefaultTab}  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" +      DefaultTab -> "Main Menu" +      NewInvasionTab -> "New Invasion" + +get_action : Type -> Action +get_action ui = ui.action + +set_action : Action -> Type -> Type +set_action action ui = {ui | action = action} diff --git a/src/main-menu/src/Update/SelectTab.elm b/src/main-menu/src/Update/HandleNewInvasion.elm index d15a463..ba687dd 100644 --- a/src/main-menu/src/Update/SelectTab.elm +++ b/src/main-menu/src/Update/HandleNewInvasion.elm @@ -1,9 +1,10 @@ -module Update.SelectTab exposing (apply_to) +module Update.HandleNewInvasion exposing (apply_to)  -- Elm ------------------------------------------------------------------------- --- Map ------------------------------------------------------------------- -import Struct.Model +-- Main Menu -------------------------------------------------------------------  import Struct.Event +import Struct.InvasionRequest +import Struct.Model  import Struct.UI  -------------------------------------------------------------------------------- @@ -15,18 +16,17 @@ import Struct.UI  --------------------------------------------------------------------------------  apply_to : (        Struct.Model.Type -> -      Struct.UI.Tab -> +      Int ->        (Struct.Model.Type, (Cmd Struct.Event.Type))     ) -apply_to model tab = -   if ((Struct.UI.try_getting_displayed_tab model.ui) == (Just tab)) -   then -      ( -         {model | ui = (Struct.UI.reset_displayed_tab model.ui)}, -         Cmd.none -      ) -   else -      ( -         {model | ui = (Struct.UI.set_displayed_tab tab model.ui)}, -         Cmd.none -      ) +apply_to model ix = +   ( +      {model | +         ui = +            (Struct.UI.set_action +               (Struct.UI.NewInvasion (Struct.InvasionRequest.new ix)) +               model.ui +            ) +      }, +      Cmd.none +   ) diff --git a/src/main-menu/src/View/CurrentTab.elm b/src/main-menu/src/View/CurrentTab.elm new file mode 100644 index 0000000..efc3e37 --- /dev/null +++ b/src/main-menu/src/View/CurrentTab.elm @@ -0,0 +1,56 @@ +module View.CurrentTab exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes + +-- Main Menu ------------------------------------------------------------------- +import Struct.Event +import Struct.Model +import Struct.Player +import Struct.UI + +import View.BattleListing +import View.Invasions +import View.MapListing +import View.Roster + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +default_tab : (Struct.Model.Type -> (Html.Html Struct.Event.Type)) +default_tab model = +   (Html.main_ +      [ +      ] +      [ +         (View.BattleListing.get_html +            "Campaigns" +            "main-menu-campaigns" +            (Struct.Player.get_campaigns model.player) +         ), +         (View.Invasions.get_html +            (Struct.Player.get_invasions model.player) +         ), +         (View.BattleListing.get_html +            "Events" +            "main-menu-events" +            (Struct.Player.get_events model.player) +         ), +         (View.MapListing.get_html (Struct.Player.get_maps model.player)), +         (View.Roster.get_html) +      ] +   ) +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : (Struct.Model.Type -> (Html.Html Struct.Event.Type)) +get_html model = +   case (Struct.UI.get_current_tab model.ui) of +      Struct.UI.DefaultTab -> (default_tab model) +      Struct.UI.NewInvasionTab -> +         (Html.main_ +            [ +            ] +            [] +         ) diff --git a/src/main-menu/src/View/Invasions.elm b/src/main-menu/src/View/Invasions.elm index b6bf17d..b4ce14c 100644 --- a/src/main-menu/src/View/Invasions.elm +++ b/src/main-menu/src/View/Invasions.elm @@ -40,6 +40,7 @@ get_invasion_html ix invasion =           (Html.a              [                 (Html.Events.onClick (Struct.Event.NewInvasion ix)), +               (Html.Attributes.class "clickable"),                 invasion_type              ]              [ | 


