| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-06-21 17:48:04 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-06-21 17:48:04 +0200 | 
| commit | 1114c662e477f048ec22ee73bb01121aba954ba7 (patch) | |
| tree | 09da9d6df4a5b50ea07d96d622122f9986d3f418 | |
| parent | fd4f339f24eb427aa7041eeab9873d12744687db (diff) | |
Starting to add attack animations...
| -rw-r--r-- | src/battlemap/src/ElmModule/View.elm | 4 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/Model.elm | 1 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/TurnResult.elm | 4 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleAnimationEnded.elm | 21 | ||||
| -rw-r--r-- | src/battlemap/src/View/Battlemap/Character.elm | 2 | ||||
| -rw-r--r-- | src/battlemap/src/View/MessageBoard.elm | 31 | ||||
| -rw-r--r-- | src/battlemap/src/View/MessageBoard/Animator.elm | 58 | ||||
| -rw-r--r-- | src/battlemap/src/View/MessageBoard/Animator/Attack.elm | 158 | ||||
| -rw-r--r-- | src/battlemap/src/View/MessageBoard/Error.elm | 33 | ||||
| -rw-r--r-- | src/battlemap/src/View/MessageBoard/Help.elm (renamed from src/battlemap/src/View/Help.elm) | 36 | ||||
| -rw-r--r-- | src/battlemap/www/style.css | 4 | 
11 files changed, 320 insertions, 32 deletions
| diff --git a/src/battlemap/src/ElmModule/View.elm b/src/battlemap/src/ElmModule/View.elm index 90177be..5b437b0 100644 --- a/src/battlemap/src/ElmModule/View.elm +++ b/src/battlemap/src/ElmModule/View.elm @@ -13,7 +13,7 @@ import Struct.Model  import View.Battlemap  import View.Controlled -import View.Help +import View.MessageBoard  import View.MainMenu  import View.SubMenu @@ -45,6 +45,6 @@ view model =              [(View.Battlemap.get_html model)]           ),           (View.SubMenu.get_html model), -         (View.Help.get_html model) +         (View.MessageBoard.get_html model)        ]     ) diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index a79e671..9a3b054 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -157,6 +157,7 @@ initialize_animator model =                 (List.reverse timeline_list)                 True              ), +         ui = (Struct.UI.default),           characters =              (List.foldr                 (Struct.TurnResult.apply_inverse_to_characters) diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm index 8a40c1c..9ee8c79 100644 --- a/src/battlemap/src/Struct/TurnResult.elm +++ b/src/battlemap/src/Struct/TurnResult.elm @@ -7,6 +7,7 @@ module Struct.TurnResult exposing        get_next_movement_dir,        get_actor_index,        get_attack_defender_index, +      maybe_get_attack_next_step,        apply_to_characters,        apply_inverse_to_characters,        apply_step_to_characters, @@ -369,6 +370,9 @@ get_next_movement_dir movement =  get_attack_defender_index : Attack -> Int  get_attack_defender_index attack = attack.defender_index +maybe_get_attack_next_step : Attack -> (Maybe Struct.Attack.Type) +maybe_get_attack_next_step attack = (List.head attack.sequence) +  get_actor_index : Type -> Int  get_actor_index turn_result =     case turn_result of diff --git a/src/battlemap/src/Update/HandleAnimationEnded.elm b/src/battlemap/src/Update/HandleAnimationEnded.elm index 59af1b7..741e9bd 100644 --- a/src/battlemap/src/Update/HandleAnimationEnded.elm +++ b/src/battlemap/src/Update/HandleAnimationEnded.elm @@ -15,6 +15,7 @@ import Action.Scroll  import Struct.Character  import Struct.Event  import Struct.Model +import Struct.TurnResult  import Struct.TurnResultAnimator  import Struct.UI @@ -87,6 +88,26 @@ prepare_next_animation model animator =        (Struct.TurnResultAnimator.Focus char_index) ->           (handle_char_focus model animator char_index) +      (Struct.TurnResultAnimator.AttackSetup _) -> +         ( +            model, +            (Delay.after 1.0 Time.second Struct.Event.AnimationEnded) +         ) + +      (Struct.TurnResultAnimator.TurnResult turn_result) -> +         case turn_result of +            (Struct.TurnResult.Attacked _) -> +               ( +                  model, +                  (Delay.after 3.0 Time.second Struct.Event.AnimationEnded) +               ) + +            _ -> +               ( +                  model, +                  (Delay.after 0.1 Time.second Struct.Event.AnimationEnded) +               ) +        _ ->           (              model, diff --git a/src/battlemap/src/View/Battlemap/Character.elm b/src/battlemap/src/View/Battlemap/Character.elm index a9004ea..4ff6c73 100644 --- a/src/battlemap/src/View/Battlemap/Character.elm +++ b/src/battlemap/src/View/Battlemap/Character.elm @@ -4,7 +4,6 @@ module View.Battlemap.Character exposing (get_html)  import Html  import Html.Attributes  import Html.Events -import Html.Lazy  -- Battlemap  ------------------------------------------------------------------  import Constants.UI @@ -13,7 +12,6 @@ import Util.Html  import Struct.Character  import Struct.CharacterTurn -import Struct.Direction  import Struct.Event  import Struct.Model  import Struct.TurnResult diff --git a/src/battlemap/src/View/MessageBoard.elm b/src/battlemap/src/View/MessageBoard.elm new file mode 100644 index 0000000..308a534 --- /dev/null +++ b/src/battlemap/src/View/MessageBoard.elm @@ -0,0 +1,31 @@ +module View.MessageBoard exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes + +-- Struct.Battlemap ------------------------------------------------------------------- +import Struct.Event +import Struct.Model + +import View.MessageBoard.Animator +import View.MessageBoard.Error +import View.MessageBoard.Help + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type) +get_html model = +   case (model.error) of +      (Just error) -> (View.MessageBoard.Error.get_html model error) +      Nothing -> +         case model.animator of +            (Just animator) -> +               (View.MessageBoard.Animator.get_html model animator) + +            Nothing -> (View.MessageBoard.Help.get_html model) diff --git a/src/battlemap/src/View/MessageBoard/Animator.elm b/src/battlemap/src/View/MessageBoard/Animator.elm new file mode 100644 index 0000000..7899d4f --- /dev/null +++ b/src/battlemap/src/View/MessageBoard/Animator.elm @@ -0,0 +1,58 @@ +module View.MessageBoard.Animator exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes + +-- Battlemap ------------------------------------------------------------------- +import Struct.Event +import Struct.Model +import Struct.TurnResult +import Struct.TurnResultAnimator + +import Util.Html + +import View.MessageBoard.Animator.Attack + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_turn_result_html : ( +      Struct.Model.Type -> +      Struct.TurnResult.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_turn_result_html model turn_result = +   case turn_result of +      (Struct.TurnResult.Attacked attack) -> +         (View.MessageBoard.Animator.Attack.get_html +            model +            (Struct.TurnResult.get_actor_index turn_result) +            (Struct.TurnResult.get_attack_defender_index attack) +            (Struct.TurnResult.maybe_get_attack_next_step attack) +         ) + +      _ -> (Util.Html.nothing) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : ( +      Struct.Model.Type -> +      Struct.TurnResultAnimator.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_html model animator = +   case (Struct.TurnResultAnimator.get_current_animation animator) of +      (Struct.TurnResultAnimator.TurnResult turn_result) -> +         (get_turn_result_html model turn_result) + +      (Struct.TurnResultAnimator.AttackSetup (attacker_id, defender_id)) -> +         (View.MessageBoard.Animator.Attack.get_html +            model +            attacker_id +            defender_id +            Nothing +         ) + +      _ -> (Util.Html.nothing) diff --git a/src/battlemap/src/View/MessageBoard/Animator/Attack.elm b/src/battlemap/src/View/MessageBoard/Animator/Attack.elm new file mode 100644 index 0000000..1557ae2 --- /dev/null +++ b/src/battlemap/src/View/MessageBoard/Animator/Attack.elm @@ -0,0 +1,158 @@ +module View.MessageBoard.Animator.Attack exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Array + +import Html +import Html.Attributes + +-- Battlemap ------------------------------------------------------------------- +import Struct.Attack +import Struct.Character +import Struct.Event +import Struct.Model + +import Util.Html + +import View.Controlled.CharacterCard +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_effect_text : Struct.Attack.Type -> String +get_effect_text attack = +   ( +      ( +         case attack.precision of +            Struct.Attack.Hit -> " hit for " +            Struct.Attack.Graze -> " grazed for " +            Struct.Attack.Miss -> " missed." +      ) +      ++ +      ( +         if (attack.precision == Struct.Attack.Miss) +         then +            "" +         else +            ( +               ((toString attack.damage) ++ " damage") +               ++ +               ( +                  if (attack.critical) +                  then " (Critical Hit)." +                  else "." +               ) +            ) +      ) +   ) + +get_attack_html : ( +      Struct.Character.Type -> +      Struct.Character.Type -> +      Struct.Attack.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_attack_html attacker defender attack = +   let +      attacker_name = (Struct.Character.get_name attacker) +      defender_name = (Struct.Character.get_name defender) +   in +   (Html.div +      [] +      [ +         (Html.text +            ( +               case (attack.order, attack.parried) of +                  (Struct.Attack.Counter, True) -> +                     ( +                        defender_name +                        ++ " attempted to strike back, but " +                        ++ attacker_name +                        ++ " parried, and " +                        ++ (get_effect_text attack) +                     ) + +                  (Struct.Attack.Counter, _) -> +                     ( +                        defender_name +                        ++ " striked back, and " +                        ++ (get_effect_text attack) +                     ) + +                  (_, True) -> +                     ( +                        attacker_name +                        ++ " attempted a hit, but " +                        ++ defender_name +                        ++ " parried, and " +                        ++ (get_effect_text attack) +                     ) + +                  (_, _) -> +                     (attacker_name ++ " " ++ (get_effect_text attack)) +            ) +         ) +      ] +   ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_placeholder_html : ( +      (Array.Array Struct.Character.Type) -> +      Int -> +      Int -> +      (Maybe Struct.Attack.Type) -> +      (Html.Html Struct.Event.Type) +   ) +get_placeholder_html characters attacker_ix defender_ix maybe_attack = +   case +      ( +         (Array.get attacker_ix characters), +         (Array.get defender_ix characters) +      ) +   of +      ((Just atkchar), (Just defchar)) -> +         (Html.div +            [ +               (Html.Attributes.class "battlemap-help") +            ] +            ( +               [ +                  (View.Controlled.CharacterCard.get_minimal_html +                     (Struct.Character.get_player_id atkchar) +                     atkchar +                  ), +                  ( +                     case maybe_attack of +                        (Just attack) -> +                           (get_attack_html atkchar defchar attack) + +                        Nothing -> +                           (Util.Html.nothing) +                  ), +                  (View.Controlled.CharacterCard.get_minimal_html "" defchar) +               ] +            ) +         ) + +      _ -> +         (Html.div +            [ +            ] +            [ +               (Html.text "Error: Attack with unknown characters") +            ] +         ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : ( +      Struct.Model.Type -> +      Int -> +      Int -> +      (Maybe Struct.Attack.Type) -> +      (Html.Html Struct.Event.Type) +   ) +get_html model attacker_ix defender_ix maybe_attack = +   (get_placeholder_html model.characters attacker_ix defender_ix maybe_attack) diff --git a/src/battlemap/src/View/MessageBoard/Error.elm b/src/battlemap/src/View/MessageBoard/Error.elm new file mode 100644 index 0000000..d1d9072 --- /dev/null +++ b/src/battlemap/src/View/MessageBoard/Error.elm @@ -0,0 +1,33 @@ +module View.MessageBoard.Error exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes + +-- Battlemap ------------------------------------------------------------------- +import Struct.Error +import Struct.Event +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : ( +      Struct.Model.Type -> +      Struct.Error.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_html model error = +   (Html.div +      [ +         (Html.Attributes.class "battlemap-help"), +         (Html.Attributes.class "battlemap-error") +      ] +      [ +         (Html.text (Struct.Error.to_string error)) +      ] +   ) diff --git a/src/battlemap/src/View/Help.elm b/src/battlemap/src/View/MessageBoard/Help.elm index 7f031e9..8b6ff41 100644 --- a/src/battlemap/src/View/Help.elm +++ b/src/battlemap/src/View/MessageBoard/Help.elm @@ -1,26 +1,17 @@ -module View.Help exposing (get_html) +module View.MessageBoard.Help exposing (get_html)  -- Elm -------------------------------------------------------------------------  import Html  import Html.Attributes --- Struct.Battlemap ------------------------------------------------------------------- +-- Battlemap -------------------------------------------------------------------  import Struct.CharacterTurn -import Struct.Error  import Struct.Event  import Struct.Model  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -get_error_message : ( -      Struct.Model.Type -> -      Struct.Error.Type -> -      (List (Html.Html Struct.Event.Type)) -   ) -get_error_message model error = -   [(Html.text (Struct.Error.to_string error))] -  get_help_message : Struct.Model.Type -> (List (Html.Html Struct.Event.Type))  get_help_message model =     case (Struct.CharacterTurn.get_state model.char_turn) of @@ -73,20 +64,9 @@ get_help_message model =  --------------------------------------------------------------------------------  get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)  get_html model = -   case (model.error) of -      (Just error) -> -         (Html.div -            [ -               (Html.Attributes.class "battlemap-help"), -               (Html.Attributes.class "battlemap-error") -            ] -            (get_error_message model error) -         ) - -      Nothing -> -         (Html.div -            [ -               (Html.Attributes.class "battlemap-help") -            ] -            (get_help_message model) -         ) +   (Html.div +      [ +         (Html.Attributes.class "battlemap-help") +      ] +      (get_help_message model) +   ) diff --git a/src/battlemap/www/style.css b/src/battlemap/www/style.css index 21ba3d4..09e1edd 100644 --- a/src/battlemap/www/style.css +++ b/src/battlemap/www/style.css @@ -44,6 +44,10 @@     margin: 0 1em 0 1em;     background-color: #917C6F; + +   display: flex; +   flex-flow: row; +   justify-content: space-between;  } | 


