| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-06-21 16:12:11 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-06-21 16:12:11 +0200 | 
| commit | fd4f339f24eb427aa7041eeab9873d12744687db (patch) | |
| tree | 76f94b917beacfef96f99f6419d22b1e6bf21693 | |
| parent | 0602055c05077fd8a1597e0ba16b81d71fc84655 (diff) | |
Prepares for more slightly more complex animations.
| -rw-r--r-- | src/battlemap/src/Struct/Model.elm | 19 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/TurnResult.elm | 4 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/TurnResultAnimator.elm | 103 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleAnimationEnded.elm | 94 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleServerReply.elm | 1 | ||||
| -rw-r--r-- | src/battlemap/src/View/Battlemap/Character.elm | 35 | ||||
| -rw-r--r-- | src/battlemap/www/style.css | 1 | 
7 files changed, 213 insertions, 44 deletions
| diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index 87db829..a79e671 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -153,7 +153,10 @@ initialize_animator model =     in        {model |           animator = -            (Struct.TurnResultAnimator.maybe_new (List.reverse timeline_list)), +            (Struct.TurnResultAnimator.maybe_new +               (List.reverse timeline_list) +               True +            ),           characters =              (List.foldr                 (Struct.TurnResult.apply_inverse_to_characters) @@ -171,10 +174,16 @@ apply_animator_step model =              animator =                 (Struct.TurnResultAnimator.maybe_trigger_next_step animator),              characters = -               (Struct.TurnResult.apply_step_to_characters -                  (Struct.TurnResultAnimator.get_current_action animator) -                  model.characters -               ) +               case +                  (Struct.TurnResultAnimator.get_current_animation animator) +               of +                  (Struct.TurnResultAnimator.TurnResult turn_result) -> +                     (Struct.TurnResult.apply_step_to_characters +                        turn_result +                        model.characters +                     ) + +                  _ -> model.characters           }  update_character : Int -> Struct.Character.Type -> Type -> Type diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm index 311fbcf..8a40c1c 100644 --- a/src/battlemap/src/Struct/TurnResult.elm +++ b/src/battlemap/src/Struct/TurnResult.elm @@ -6,6 +6,7 @@ module Struct.TurnResult exposing        WeaponSwitch,        get_next_movement_dir,        get_actor_index, +      get_attack_defender_index,        apply_to_characters,        apply_inverse_to_characters,        apply_step_to_characters, @@ -365,6 +366,9 @@ get_next_movement_dir movement =        (Just dir) -> dir        Nothing -> Struct.Direction.None +get_attack_defender_index : Attack -> Int +get_attack_defender_index attack = attack.defender_index +  get_actor_index : Type -> Int  get_actor_index turn_result =     case turn_result of diff --git a/src/battlemap/src/Struct/TurnResultAnimator.elm b/src/battlemap/src/Struct/TurnResultAnimator.elm index b588631..827b56e 100644 --- a/src/battlemap/src/Struct/TurnResultAnimator.elm +++ b/src/battlemap/src/Struct/TurnResultAnimator.elm @@ -1,9 +1,11 @@  module Struct.TurnResultAnimator exposing     (        Type, +      Animation(..),        maybe_new,        maybe_trigger_next_step, -      get_current_action +      waits_for_focus, +      get_current_animation     )  -- Elm ------------------------------------------------------------------------- @@ -14,37 +16,108 @@ import Struct.TurnResult  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- + +type Animation = +   Inactive +   | AttackSetup (Int, Int) +   | Focus Int +   | TurnResult Struct.TurnResult.Type +  type alias Type =     { -      remaining_actions : (List Struct.TurnResult.Type), -      current_action : Struct.TurnResult.Type +      remaining_animations : (List Animation), +      current_animation : Animation, +      wait_focus : Bool     }  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +turn_result_to_animations : Struct.TurnResult.Type -> (List Animation) +turn_result_to_animations turn_result = +   case turn_result of +      (Struct.TurnResult.Attacked attack) -> +         let +            attacker_ix = (Struct.TurnResult.get_actor_index turn_result) +            defender_ix = (Struct.TurnResult.get_attack_defender_index attack) +         in +            [ +               (Focus attacker_ix), +               (Focus defender_ix), +               (AttackSetup (attacker_ix, defender_ix)), +               (TurnResult turn_result) +            ] + +      _ -> +         [ +            (Focus (Struct.TurnResult.get_actor_index turn_result)), +            (TurnResult turn_result) +         ] + +turn_result_to_animations_foldl : ( +      Struct.TurnResult.Type -> +      (List Animation) -> +      (List Animation) +   ) +turn_result_to_animations_foldl turn_result current_animations = +   (List.append current_animations (turn_result_to_animations turn_result)) + +maybe_go_to_next_animation : Type -> (Maybe Type) +maybe_go_to_next_animation tra = +   case +   ( +      (List.head tra.remaining_animations), +      (List.tail tra.remaining_animations) +   ) +   of +      ((Just head), (Just tail)) -> +         (Just +            {tra | +               remaining_animations = tail, +               current_animation = head +            } +         ) + +      (_, _) -> Nothing  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- -maybe_new : (List Struct.TurnResult.Type) -> (Maybe Type) -maybe_new turn_results = -   case ((List.head turn_results), (List.tail turn_results)) of -      ((Just head), (Just tail)) -> +maybe_new : (List Struct.TurnResult.Type) -> Bool -> (Maybe Type) +maybe_new turn_results wait_focus = +   case (List.head turn_results) of +      (Just head) ->           (Just              { -               remaining_actions = tail, -               current_action = head +               remaining_animations = +                  (List.foldl +                     (turn_result_to_animations_foldl) +                     [] +                     turn_results +                  ), +               current_animation = Inactive, +               wait_focus = wait_focus              }           ) -      (_, _) -> Nothing +      _ -> Nothing  maybe_trigger_next_step : Type -> (Maybe Type)  maybe_trigger_next_step tra = -   case (Struct.TurnResult.maybe_remove_step tra.current_action) of -      (Just updated_action) -> (Just {tra | current_action = updated_action}) -      Nothing -> (maybe_new tra.remaining_actions) +   case tra.current_animation of +      (TurnResult action) -> +         ( +            case (Struct.TurnResult.maybe_remove_step action) of +               (Just updated_action) -> +                  (Just {tra | current_animation = (TurnResult updated_action)}) + +               Nothing -> (maybe_go_to_next_animation tra) +         ) + +      _ -> (maybe_go_to_next_animation tra) + +get_current_animation : Type -> Animation +get_current_animation tra = tra.current_animation -get_current_action : Type -> Struct.TurnResult.Type -get_current_action tra = tra.current_action +waits_for_focus : Type -> Bool +waits_for_focus tra = tra.wait_focus diff --git a/src/battlemap/src/Update/HandleAnimationEnded.elm b/src/battlemap/src/Update/HandleAnimationEnded.elm index f7b17d5..59af1b7 100644 --- a/src/battlemap/src/Update/HandleAnimationEnded.elm +++ b/src/battlemap/src/Update/HandleAnimationEnded.elm @@ -1,17 +1,97 @@  module Update.HandleAnimationEnded exposing (apply_to)  -- Elm ------------------------------------------------------------------------- +import Array +  import Delay  import Time +import Task +  -- Battlemap ------------------------------------------------------------------- +import Action.Scroll + +import Struct.Character  import Struct.Event  import Struct.Model +import Struct.TurnResultAnimator +import Struct.UI  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +handle_char_focus : ( +      Struct.Model.Type -> +      Struct.TurnResultAnimator.Type -> +      Int -> +      (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +handle_char_focus model animator char_index = +   case (Array.get char_index model.characters) of +      (Just char) -> +         if (Struct.TurnResultAnimator.waits_for_focus animator) +         then +            ( +               {model | +                  ui = +                     (Struct.UI.set_previous_action +                        (Just (Struct.UI.SelectedCharacter char_index)) +                        model.ui +                     ) +               }, +               (Cmd.batch +                  [ +                     (Task.attempt +                        (Struct.Event.attempted) +                        (Action.Scroll.to +                           (Struct.Character.get_location char) +                           model.ui +                        ) +                     ), +                     (Delay.after 2.0 Time.second Struct.Event.AnimationEnded) +                  ] +               ) +            ) +         else +            ( +               model, +               (Cmd.batch +                  [ +                     (Task.attempt +                        (Struct.Event.attempted) +                        (Action.Scroll.to +                           (Struct.Character.get_location char) +                           model.ui +                        ) +                     ), +                     (Delay.after 0.3 Time.second Struct.Event.AnimationEnded) +                  ] +               ) +            ) + + +      _ -> +         ( +            model, +            (Delay.after 1.0 Time.millisecond Struct.Event.AnimationEnded) +         ) + +prepare_next_animation : ( +      Struct.Model.Type -> +      Struct.TurnResultAnimator.Type -> +      (Struct.Model.Type, (Cmd Struct.Event.Type)) +   ) +prepare_next_animation model animator = +   case (Struct.TurnResultAnimator.get_current_animation animator) of +      (Struct.TurnResultAnimator.Focus char_index) -> +         (handle_char_focus model animator char_index) + +      _ -> +         ( +            model, +            (Delay.after 0.3 Time.second Struct.Event.AnimationEnded) +         )  --------------------------------------------------------------------------------  -- EXPORTED -------------------------------------------------------------------- @@ -21,10 +101,10 @@ apply_to : (        (Struct.Model.Type, (Cmd Struct.Event.Type))     )  apply_to model = -   case model.animator of -      Nothing -> (model, Cmd.none) -      (Just _) -> -         ( -            (Struct.Model.apply_animator_step model), -            (Delay.after 0.3 Time.second Struct.Event.AnimationEnded) -         ) +   let +      new_model = (Struct.Model.apply_animator_step model) +   in +      case new_model.animator of +         Nothing -> (model, Cmd.none) +         (Just animator) -> +            (prepare_next_animation new_model animator) diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm index c13af87..bc347c9 100644 --- a/src/battlemap/src/Update/HandleServerReply.elm +++ b/src/battlemap/src/Update/HandleServerReply.elm @@ -131,6 +131,7 @@ add_to_timeline turn_results current_state =                 animator =                    (Struct.TurnResultAnimator.maybe_new                       (List.reverse turn_results) +                     False                    ),                 timeline =                    (Array.append diff --git a/src/battlemap/src/View/Battlemap/Character.elm b/src/battlemap/src/View/Battlemap/Character.elm index 215e994..a9004ea 100644 --- a/src/battlemap/src/View/Battlemap/Character.elm +++ b/src/battlemap/src/View/Battlemap/Character.elm @@ -32,24 +32,25 @@ get_animation_class model char =     case model.animator of        Nothing -> (Html.Attributes.class "")        (Just animator) -> -         let -            current_action = -               (Struct.TurnResultAnimator.get_current_action animator) -         in -            if -            ( -               (Struct.TurnResult.get_actor_index current_action) -               /= -               (Struct.Character.get_index char) -            ) -            then -               (Html.Attributes.class "") -            else -               case current_action of -                  (Struct.TurnResult.Moved _) -> -                     (Html.Attributes.class "battlemap-animated-character-icon") +         case (Struct.TurnResultAnimator.get_current_animation animator) of +            (Struct.TurnResultAnimator.TurnResult current_action) -> +               if +               ( +                  (Struct.TurnResult.get_actor_index current_action) +                  /= +                  (Struct.Character.get_index char) +               ) +               then +                  (Html.Attributes.class "") +               else +                  case current_action of +                     (Struct.TurnResult.Moved _) -> +                        (Html.Attributes.class +                           "battlemap-animated-character-icon" +                        ) -                  _ -> (Html.Attributes.class "") +                     _ -> (Html.Attributes.class "") +            _ -> (Html.Attributes.class "")  get_activation_level_class : (        Struct.Character.Type -> diff --git a/src/battlemap/www/style.css b/src/battlemap/www/style.css index d29e1da..21ba3d4 100644 --- a/src/battlemap/www/style.css +++ b/src/battlemap/www/style.css @@ -507,6 +507,7 @@  .battlemap-character-icon  { +   border-radius: 5px;     height: 38px;     margin-top: -6px;  } | 


