| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-06-20 17:47:02 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-06-20 17:47:02 +0200 | 
| commit | c4bdab007fa34dd685fa7700086e4f500a954d38 (patch) | |
| tree | 0388d2c84ffaa77d1d8cf97954ff628621c87369 /src | |
| parent | 734f10c3de28cd432b16a19600a01f8b091a3ab4 (diff) | |
They're not smooth, but there are some animations.
Diffstat (limited to 'src')
| -rw-r--r-- | src/battlemap/elm-package.json | 1 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/TurnResult.elm | 15 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleAnimationEnded.elm | 11 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleServerReply.elm | 70 | ||||
| -rw-r--r-- | src/battlemap/src/Update/TestAnimation.elm | 9 | ||||
| -rw-r--r-- | src/battlemap/src/View/Battlemap/Character.elm | 34 | ||||
| -rw-r--r-- | src/battlemap/src/View/SubMenu/Settings.elm | 2 | ||||
| -rw-r--r-- | src/battlemap/www/style.css | 41 | 
8 files changed, 147 insertions, 36 deletions
| diff --git a/src/battlemap/elm-package.json b/src/battlemap/elm-package.json index 5f6573f..43957bf 100644 --- a/src/battlemap/elm-package.json +++ b/src/battlemap/elm-package.json @@ -9,6 +9,7 @@      "exposed-modules": [],      "dependencies": {          "NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0", +        "andrewMacmurray/elm-delay": "2.0.3 <= v < 3.0.0",          "elm-lang/core": "5.1.1 <= v < 6.0.0",          "elm-lang/dom": "1.1.1 <= v < 2.0.0",          "elm-lang/html": "2.0.0 <= v < 3.0.0", diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm index 59a004a..311fbcf 100644 --- a/src/battlemap/src/Struct/TurnResult.elm +++ b/src/battlemap/src/Struct/TurnResult.elm @@ -4,6 +4,8 @@ module Struct.TurnResult exposing        Attack,        Movement,        WeaponSwitch, +      get_next_movement_dir, +      get_actor_index,        apply_to_characters,        apply_inverse_to_characters,        apply_step_to_characters, @@ -356,3 +358,16 @@ maybe_remove_step turn_result =        (Moved movement) -> (maybe_remove_movement_step movement)        (SwitchedWeapon _) -> Nothing        (Attacked attack) -> (maybe_remove_attack_step attack) + +get_next_movement_dir : Movement -> Struct.Direction.Type +get_next_movement_dir movement = +   case (List.head movement.path) of +      (Just dir) -> dir +      Nothing -> Struct.Direction.None + +get_actor_index : Type -> Int +get_actor_index turn_result = +   case turn_result of +      (Moved movement) -> movement.character_index +      (SwitchedWeapon weapon_switch) -> weapon_switch.character_index +      (Attacked attack) -> attack.attacker_index diff --git a/src/battlemap/src/Update/HandleAnimationEnded.elm b/src/battlemap/src/Update/HandleAnimationEnded.elm index c699c49..f7b17d5 100644 --- a/src/battlemap/src/Update/HandleAnimationEnded.elm +++ b/src/battlemap/src/Update/HandleAnimationEnded.elm @@ -1,6 +1,9 @@  module Update.HandleAnimationEnded exposing (apply_to)  -- Elm ------------------------------------------------------------------------- +import Delay + +import Time  -- Battlemap -------------------------------------------------------------------  import Struct.Event @@ -19,5 +22,9 @@ apply_to : (     )  apply_to model =     case model.animator of -      Nothing -> ((Struct.Model.initialize_animator model), Cmd.none) -      (Just _) -> ((Struct.Model.apply_animator_step model), Cmd.none) +      Nothing -> (model, Cmd.none) +      (Just _) -> +         ( +            (Struct.Model.apply_animator_step model), +            (Delay.after 0.3 Time.second Struct.Event.AnimationEnded) +         ) diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm index 27ea1ac..c13af87 100644 --- a/src/battlemap/src/Update/HandleServerReply.elm +++ b/src/battlemap/src/Update/HandleServerReply.elm @@ -3,10 +3,14 @@ module Update.HandleServerReply exposing (apply_to)  -- Elm -------------------------------------------------------------------------  import Array +import Delay +  import Dict  import Http +import Time +  -- Battlemap -------------------------------------------------------------------  import Struct.Armor  import Struct.Battlemap @@ -17,6 +21,7 @@ import Struct.Model  import Struct.ServerReply  import Struct.Tile  import Struct.TurnResult +import Struct.TurnResultAnimator  import Struct.UI  import Struct.Weapon @@ -121,30 +126,25 @@ add_to_timeline turn_results current_state =        (_, (Just _)) -> current_state        (model, _) -> -         let -            updated_characters = -               (List.foldl -                  (Struct.TurnResult.apply_to_characters) -                  model.characters -                  turn_results -               ) -         in -            ( -               {model | -                  timeline = -                     (Array.append -                        (Array.fromList turn_results) -                        model.timeline -                     ), -                  ui = -                     (Struct.UI.set_displayed_tab -                        Struct.UI.TimelineTab -                        model.ui -                     ), -                  characters = updated_characters -               }, -               Nothing -            ) +         ( +            {model | +               animator = +                  (Struct.TurnResultAnimator.maybe_new +                     (List.reverse turn_results) +                  ), +               timeline = +                  (Array.append +                     (Array.fromList turn_results) +                     model.timeline +                  ), +               ui = +                  (Struct.UI.set_displayed_tab +                     Struct.UI.TimelineTab +                     model.ui +                  ) +            }, +            Nothing +         )  set_timeline : (        (List Struct.TurnResult.Type) -> @@ -211,11 +211,19 @@ apply_to model query_result =           )        (Result.Ok commands) -> -         ( +         let +            new_model = +               ( +                  case (List.foldl (apply_command) (model, Nothing) commands) of +                     (updated_model, Nothing) -> updated_model +                     (_, (Just error)) -> (Struct.Model.invalidate error model) +               ) +         in              ( -               case (List.foldl (apply_command) (model, Nothing) commands) of -                  (updated_model, Nothing) -> updated_model -                  (_, (Just error)) -> (Struct.Model.invalidate error model) -            ), -            Cmd.none -         ) +               new_model, +               if (new_model.animator == Nothing) +               then +                  Cmd.none +               else +                  (Delay.after 1 Time.millisecond Struct.Event.AnimationEnded) +            ) diff --git a/src/battlemap/src/Update/TestAnimation.elm b/src/battlemap/src/Update/TestAnimation.elm index fa7cb65..8fa16e7 100644 --- a/src/battlemap/src/Update/TestAnimation.elm +++ b/src/battlemap/src/Update/TestAnimation.elm @@ -1,6 +1,9 @@  module Update.TestAnimation exposing (apply_to)  -- Elm ------------------------------------------------------------------------- +import Delay + +import Time  -- Battlemap -------------------------------------------------------------------  import Struct.Model @@ -17,4 +20,8 @@ apply_to : (        Struct.Model.Type ->        (Struct.Model.Type, (Cmd Struct.Event.Type))     ) -apply_to model = (model, Cmd.none) +apply_to model = +   ( +      (Struct.Model.initialize_animator model), +      (Delay.after 1 Time.millisecond Struct.Event.AnimationEnded) +   ) diff --git a/src/battlemap/src/View/Battlemap/Character.elm b/src/battlemap/src/View/Battlemap/Character.elm index a32ef5e..215e994 100644 --- a/src/battlemap/src/View/Battlemap/Character.elm +++ b/src/battlemap/src/View/Battlemap/Character.elm @@ -13,13 +13,44 @@ import Util.Html  import Struct.Character  import Struct.CharacterTurn +import Struct.Direction  import Struct.Event  import Struct.Model +import Struct.TurnResult +import Struct.TurnResultAnimator  import Struct.UI  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +get_animation_class : ( +      Struct.Model.Type -> +      Struct.Character.Type -> +      (Html.Attribute Struct.Event.Type) +   ) +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") + +                  _ -> (Html.Attributes.class "") +  get_activation_level_class : (        Struct.Character.Type ->        (Html.Attribute Struct.Event.Type) @@ -121,6 +152,7 @@ get_actual_html model char =           [              (Html.Attributes.class "battlemap-tiled"),              (Html.Attributes.class "battlemap-character-icon"), +            (get_animation_class model char),              (get_activation_level_class char),              (get_alliance_class model char),              (get_position_style char), @@ -149,6 +181,6 @@ get_html : (  get_html model char =     if (Struct.Character.is_alive char)     then -      (Html.Lazy.lazy (get_actual_html model) char) +      (get_actual_html model char)     else        (Util.Html.nothing) diff --git a/src/battlemap/src/View/SubMenu/Settings.elm b/src/battlemap/src/View/SubMenu/Settings.elm index fb7ebe8..22aa99a 100644 --- a/src/battlemap/src/View/SubMenu/Settings.elm +++ b/src/battlemap/src/View/SubMenu/Settings.elm @@ -51,7 +51,7 @@ get_html model =           ),           (Html.button              [ -               (Html.Events.onClick Struct.Event.AnimationEnded) +               (Html.Events.onClick Struct.Event.DebugTestAnimation)              ]              [ (Html.text "[DEBUG] Test animations") ]           ) diff --git a/src/battlemap/www/style.css b/src/battlemap/www/style.css index fc93e8d..b50d65d 100644 --- a/src/battlemap/www/style.css +++ b/src/battlemap/www/style.css @@ -691,6 +691,47 @@     filter: contrast(35%);  } +.battlemap-animated-character-icon +{ +   transition: top linear 0.3s, left linear 0.3s; +} + +.battlemap-animation-move-1 +.battlemap-animation-move-R, +.battlemap-animation-move-L, +.battlemap-animation-move-U, +.battlemap-animation-move-D +{ +   animation-duration: 0.3s; +   animation-iteration-count: 1; +   animation-fill-mode: forwards; +} + +.battlemap-animation-move-R { animation-name: move-right; } +.battlemap-animation-move-L { animation-name: move-left; } +.battlemap-animation-move-U { animation-name: move-up; } +.battlemap-animation-move-D { animation-name: move-down; } + +@keyframes move-right { +    from { transform: translate(0, 0);} +    to   { transform: translate(100%, 0);} +} + +@keyframes move-left { +    from { transform: translate(0, 0);} +    to   { transform: translate(-100%, 0);} +} + +@keyframes move-up { +    from { transform: translate(0, 0);} +    to   { transform: translate(0, -100%);} +} + +@keyframes move-down { +    from { transform: translate(0, 0);} +    to   { transform: translate(0, 100%);} +} +  @keyframes red-alarm-bg {      0% {background-color: rgba(255,0,0,0.25);}      25% {background-color: rgba(255,0,0,1);} | 


