| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/main-menu')
| -rw-r--r-- | src/main-menu/src/ElmModule/Update.elm | 9 | ||||
| -rw-r--r-- | src/main-menu/src/Struct/Event.elm | 6 | ||||
| -rw-r--r-- | src/main-menu/src/Struct/InvasionRequest.elm | 4 | ||||
| -rw-r--r-- | src/main-menu/src/Update/HandleNewInvasion.elm | 89 | ||||
| -rw-r--r-- | src/main-menu/src/View/Tab/NewInvasion.elm | 39 | 
5 files changed, 137 insertions, 10 deletions
| diff --git a/src/main-menu/src/ElmModule/Update.elm b/src/main-menu/src/ElmModule/Update.elm index 04e1310..5eb3e19 100644 --- a/src/main-menu/src/ElmModule/Update.elm +++ b/src/main-menu/src/ElmModule/Update.elm @@ -40,4 +40,13 @@ update event model =        (Struct.Event.NewInvasion ix) ->           (Update.HandleNewInvasion.apply_to new_model ix) +      (Struct.Event.InvasionSetSize size) -> +         (Update.HandleNewInvasion.set_size new_model size) + +      (Struct.Event.InvasionSetCategory cat) -> +         (Update.HandleNewInvasion.set_category new_model cat) + +      (Struct.Event.InvasionSetMap map_summary) -> +         (Update.HandleNewInvasion.set_map new_model map_summary) +        (Struct.Event.TabSelected tab) -> (model, Cmd.none) diff --git a/src/main-menu/src/Struct/Event.elm b/src/main-menu/src/Struct/Event.elm index 21edd3a..24e5ea5 100644 --- a/src/main-menu/src/Struct/Event.elm +++ b/src/main-menu/src/Struct/Event.elm @@ -4,7 +4,10 @@ module Struct.Event exposing (Type(..), attempted)  import Http  -- Main Menu ------------------------------------------------------------------- +import Struct.BattleSummary  import Struct.Error +import Struct.InvasionRequest +import Struct.MapSummary  import Struct.ServerReply  import Struct.UI @@ -16,6 +19,9 @@ type Type =     | Failed Struct.Error.Type     | ServerReplied (Result Http.Error (List Struct.ServerReply.Type))     | NewInvasion Int +   | InvasionSetSize Struct.InvasionRequest.Size +   | InvasionSetMap Struct.MapSummary.Type +   | InvasionSetCategory Struct.BattleSummary.InvasionCategory     | TabSelected Struct.UI.Tab  attempted : (Result.Result err val) -> Type diff --git a/src/main-menu/src/Struct/InvasionRequest.elm b/src/main-menu/src/Struct/InvasionRequest.elm index 46e1304..6a474a5 100644 --- a/src/main-menu/src/Struct/InvasionRequest.elm +++ b/src/main-menu/src/Struct/InvasionRequest.elm @@ -62,8 +62,8 @@ 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} +set_size : Size -> Type -> Type +set_size s ir = {ir | size = (Just s)}  get_map_id : Type -> String  get_map_id ir = ir.map_id diff --git a/src/main-menu/src/Update/HandleNewInvasion.elm b/src/main-menu/src/Update/HandleNewInvasion.elm index ba687dd..1ea2b8a 100644 --- a/src/main-menu/src/Update/HandleNewInvasion.elm +++ b/src/main-menu/src/Update/HandleNewInvasion.elm @@ -1,9 +1,17 @@ -module Update.HandleNewInvasion exposing (apply_to) +module Update.HandleNewInvasion exposing +   ( +      apply_to, +      set_size, +      set_category, +      set_map +   )  -- Elm -------------------------------------------------------------------------  -- Main Menu ------------------------------------------------------------------- +import Struct.BattleSummary  import Struct.Event  import Struct.InvasionRequest +import Struct.MapSummary  import Struct.Model  import Struct.UI @@ -14,6 +22,85 @@ import Struct.UI  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- +set_size : ( +      Struct.Model.Type -> +      Struct.InvasionRequest.Size -> +      (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +set_size model size = +   case (Struct.UI.get_action model.ui) of +      Struct.UI.None -> -- TODO: err +         (model, Cmd.none) + +      (Struct.UI.NewInvasion invasion) -> +         ( +            {model | +               ui = +                  (Struct.UI.set_action +                     (Struct.UI.NewInvasion +                        (Struct.InvasionRequest.set_size size invasion) +                     ) +                     model.ui +                  ) +            }, +            Cmd.none +         ) + +set_category : ( +      Struct.Model.Type -> +      Struct.BattleSummary.InvasionCategory -> +      (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +set_category model category = +   case (Struct.UI.get_action model.ui) of +      Struct.UI.None -> -- TODO: err +         (model, Cmd.none) + +      (Struct.UI.NewInvasion invasion) -> +         ( +            {model | +               ui = +                  (Struct.UI.set_action +                     (Struct.UI.NewInvasion +                        (Struct.InvasionRequest.set_category category invasion) +                     ) +                     model.ui +                  ) +            }, +            Cmd.none +         ) + +set_map : ( +      Struct.Model.Type -> +      Struct.MapSummary.Type -> +      (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +set_map model map = +   case (Struct.UI.get_action model.ui) of +      Struct.UI.None -> -- TODO: err +         (model, Cmd.none) + +      (Struct.UI.NewInvasion invasion) -> +         ( +            {model | +               ui = +                  (Struct.UI.set_action +                     (Struct.UI.NewInvasion +                        (Struct.InvasionRequest.set_map_id +                           "" +                           (Struct.InvasionRequest.set_size +                              -- TODO: get from map summary +                              Struct.InvasionRequest.Small +                              invasion +                           ) +                        ) +                     ) +                     model.ui +                  ) +            }, +            Cmd.none +         ) +  apply_to : (        Struct.Model.Type ->        Int -> diff --git a/src/main-menu/src/View/Tab/NewInvasion.elm b/src/main-menu/src/View/Tab/NewInvasion.elm index 1961174..f0195e1 100644 --- a/src/main-menu/src/View/Tab/NewInvasion.elm +++ b/src/main-menu/src/View/Tab/NewInvasion.elm @@ -2,12 +2,12 @@ module View.Tab.NewInvasion exposing (get_html)  -- Elm -------------------------------------------------------------------------  import Html -import Html.Attributes +-- import Html.Attributes +import Html.Events  -- Main Menu -------------------------------------------------------------------  import Struct.Event  import Struct.Model -import Struct.Player  import Struct.UI  import Struct.InvasionRequest  import Struct.BattleSummary @@ -21,15 +21,25 @@ select_category_html =        [        ]        [ -         (Html.div +         (Html.button              [ +               (Html.Events.onClick +                  (Struct.Event.InvasionSetCategory +                     Struct.BattleSummary.InvasionAttack +                  ) +               )              ]              [                 (Html.text "New Offensive")              ]           ), -         (Html.div +         (Html.button              [ +               (Html.Events.onClick +                  (Struct.Event.InvasionSetCategory +                     Struct.BattleSummary.InvasionDefend +                  ) +               )              ]              [                 (Html.text "New Defense") @@ -44,22 +54,37 @@ select_size_html max_size =        [        ]        [ -         (Html.div +         (Html.button              [ +               (Html.Events.onClick +                  (Struct.Event.InvasionSetSize +                     Struct.InvasionRequest.Small +                  ) +               )              ]              [                 (Html.text "Small")              ]           ), -         (Html.div +         (Html.button              [ +               (Html.Events.onClick +                  (Struct.Event.InvasionSetSize +                     Struct.InvasionRequest.Medium +                  ) +               )              ]              [                 (Html.text "Medium")              ]           ), -         (Html.div +         (Html.button              [ +               (Html.Events.onClick +                  (Struct.Event.InvasionSetSize +                     Struct.InvasionRequest.Large +                  ) +               )              ]              [                 (Html.text "Large") | 


