| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-06-20 16:22:57 +0200 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-06-20 16:22:57 +0200 | 
| commit | 734f10c3de28cd432b16a19600a01f8b091a3ab4 (patch) | |
| tree | 4c43e45a4076538596f78ebc0be2a2bb2fc5da9c /src/battlemap | |
| parent | 9a241ec0f014943e87c7e78b1d3ef57771d96b04 (diff) | |
Okay, it seems to work. Next step: CSS animation.
Diffstat (limited to 'src/battlemap')
| -rw-r--r-- | src/battlemap/src/Struct/Animation.elm | 45 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/Model.elm | 37 | ||||
| -rw-r--r-- | src/battlemap/src/Struct/TurnResultAnimator.elm | 50 | ||||
| -rw-r--r-- | src/battlemap/src/Update/HandleAnimationEnded.elm | 5 | ||||
| -rw-r--r-- | src/battlemap/src/View/SubMenu/Settings.elm | 2 | 
5 files changed, 92 insertions, 47 deletions
| diff --git a/src/battlemap/src/Struct/Animation.elm b/src/battlemap/src/Struct/Animation.elm deleted file mode 100644 index 7b7e4d1..0000000 --- a/src/battlemap/src/Struct/Animation.elm +++ /dev/null @@ -1,45 +0,0 @@ -module Struct.Animation exposing -   ( -      Type -   ) - --- Elm ------------------------------------------------------------------------- - --- Battlemap ------------------------------------------------------------------- -import Struct.Direction -import Struct.Weapon - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type alias CharMoves = -   { -      char_ix : Int, -      dir : Struct.Direction.Type -   } - -type alias CharSwitchesWeapon = -   { -      char_ix : Int -      new_weapon_id : Struct.Weapon.Ref -   } - -type alias CharAttacks = -   { -      char_ix : Int, -      target_ix : Int, -      sequence : (List Struct.Attack.Type) -   } - -type Type = -   CharacterMoves CharMoves -   | CharacterSwitchesWeapon CharSwitchesWeapon -   | CharacterAttacks CharAttacks - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index b0752d9..87db829 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -9,6 +9,8 @@ module Struct.Model exposing        add_armor,        add_tile,        invalidate, +      initialize_animator, +      apply_animator_step,        reset,        full_debug_reset,        clear_error @@ -27,6 +29,7 @@ import Struct.CharacterTurn  import Struct.Error  import Struct.Tile  import Struct.TurnResult +import Struct.TurnResultAnimator  import Struct.UI  import Struct.Weapon @@ -37,6 +40,7 @@ import Util.Array  --------------------------------------------------------------------------------  type alias Type =     { +      animator: (Maybe Struct.TurnResultAnimator.Type),        battlemap: Struct.Battlemap.Type,        characters: (Array.Array Struct.Character.Type),        weapons: (Dict.Dict Struct.Weapon.Ref Struct.Weapon.Type), @@ -59,6 +63,7 @@ type alias Type =  new : Type  new =     { +      animator = Nothing,        battlemap = (Struct.Battlemap.empty),        characters = (Array.empty),        weapons = (Dict.empty), @@ -128,6 +133,7 @@ reset model =  full_debug_reset : Type -> Type  full_debug_reset model =     {model | +      animator = Nothing,        battlemap = (Struct.Battlemap.empty),        characters = (Array.empty),        weapons = (Dict.empty), @@ -140,6 +146,37 @@ full_debug_reset model =        timeline = (Array.empty)     } +initialize_animator : Type -> Type +initialize_animator model = +   let +      timeline_list = (Array.toList model.timeline) +   in +      {model | +         animator = +            (Struct.TurnResultAnimator.maybe_new (List.reverse timeline_list)), +         characters = +            (List.foldr +               (Struct.TurnResult.apply_inverse_to_characters) +               model.characters +               timeline_list +            ) +      } + +apply_animator_step : Type -> Type +apply_animator_step model = +   case model.animator of +      Nothing -> model +      (Just animator) -> +         {model | +            animator = +               (Struct.TurnResultAnimator.maybe_trigger_next_step animator), +            characters = +               (Struct.TurnResult.apply_step_to_characters +                  (Struct.TurnResultAnimator.get_current_action animator) +                  model.characters +               ) +         } +  update_character : Int -> Struct.Character.Type -> Type -> Type  update_character ix new_val model =     {model | diff --git a/src/battlemap/src/Struct/TurnResultAnimator.elm b/src/battlemap/src/Struct/TurnResultAnimator.elm new file mode 100644 index 0000000..b588631 --- /dev/null +++ b/src/battlemap/src/Struct/TurnResultAnimator.elm @@ -0,0 +1,50 @@ +module Struct.TurnResultAnimator exposing +   ( +      Type, +      maybe_new, +      maybe_trigger_next_step, +      get_current_action +   ) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.TurnResult + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = +   { +      remaining_actions : (List Struct.TurnResult.Type), +      current_action : Struct.TurnResult.Type +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- 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)) -> +         (Just +            { +               remaining_actions = tail, +               current_action = head +            } +         ) + +      (_, _) -> 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) + +get_current_action : Type -> Struct.TurnResult.Type +get_current_action tra = tra.current_action diff --git a/src/battlemap/src/Update/HandleAnimationEnded.elm b/src/battlemap/src/Update/HandleAnimationEnded.elm index 0d9adc9..c699c49 100644 --- a/src/battlemap/src/Update/HandleAnimationEnded.elm +++ b/src/battlemap/src/Update/HandleAnimationEnded.elm @@ -17,4 +17,7 @@ apply_to : (        Struct.Model.Type ->        (Struct.Model.Type, (Cmd Struct.Event.Type))     ) -apply_to model = (model, Cmd.none) +apply_to model = +   case model.animator of +      Nothing -> ((Struct.Model.initialize_animator model), Cmd.none) +      (Just _) -> ((Struct.Model.apply_animator_step model), Cmd.none) diff --git a/src/battlemap/src/View/SubMenu/Settings.elm b/src/battlemap/src/View/SubMenu/Settings.elm index 22aa99a..fb7ebe8 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.DebugTestAnimation) +               (Html.Events.onClick Struct.Event.AnimationEnded)              ]              [ (Html.text "[DEBUG] Test animations") ]           ) | 


