summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/battle')
-rw-r--r-- | src/battle/src/Struct/Model.elm | 5 | ||||
-rw-r--r-- | src/battle/src/Struct/Puppeteer.elm | 2 | ||||
-rw-r--r-- | src/battle/src/Struct/PuppeteerAction.elm | 230 | ||||
-rw-r--r-- | src/battle/src/Struct/TurnResultAnimator.elm | 227 |
4 files changed, 86 insertions, 378 deletions
diff --git a/src/battle/src/Struct/Model.elm b/src/battle/src/Struct/Model.elm index f0c8695..a53b4df 100644 --- a/src/battle/src/Struct/Model.elm +++ b/src/battle/src/Struct/Model.elm @@ -20,9 +20,8 @@ import BattleMap.Struct.DataSet import Struct.CharacterTurn import Struct.Error import Struct.HelpRequest -import Struct.Puppeteer import Struct.TurnResult -import Struct.TurnResultAnimator +import Struct.Puppeteer import Struct.UI -------------------------------------------------------------------------------- @@ -32,7 +31,6 @@ type alias Type = { flags : Struct.Flags.Type, help_request : Struct.HelpRequest.Type, - animator : (Maybe Struct.TurnResultAnimator.Type), puppeteer : Struct.Puppeteer.Type, ui : Struct.UI.Type, char_turn : Struct.CharacterTurn.Type, @@ -59,7 +57,6 @@ new flags = { flags = flags, help_request = Struct.HelpRequest.None, - animator = Nothing, puppeteer = (Struct.Puppeteer.new), ui = (Struct.UI.default), char_turn = (Struct.CharacterTurn.new), diff --git a/src/battle/src/Struct/Puppeteer.elm b/src/battle/src/Struct/Puppeteer.elm index 00f677f..937b9fd 100644 --- a/src/battle/src/Struct/Puppeteer.elm +++ b/src/battle/src/Struct/Puppeteer.elm @@ -4,7 +4,7 @@ module Struct.Puppeteer exposing new, append, is_active, - requires_priming, + requires_priming ) -- Elm ------------------------------------------------------------------------- diff --git a/src/battle/src/Struct/PuppeteerAction.elm b/src/battle/src/Struct/PuppeteerAction.elm index 197eb08..38a22b2 100644 --- a/src/battle/src/Struct/PuppeteerAction.elm +++ b/src/battle/src/Struct/PuppeteerAction.elm @@ -23,164 +23,102 @@ import Struct.TurnResult -------------------------------------------------------------------------------- type Type = Inactive - | Targetting (Int, Int) - | Hit + | Target (Int, Int) + | Hit Struct.Attack.Type | Focus Int - | TurnResult Struct.TurnResult.Type + | Move (Int, Battle.Struct.Direction) + | SwapWeapons Int | RefreshCharacter Int + | Sequence (List Type) -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -turn_result_to_actions : Struct.TurnResult.Type -> (List Action) -turn_result_to_actions 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 +from_attacked : Struct.Attack.Type -> (List Type) +from_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), + (Hit attack), + (Sequence [ - (Focus attacker_ix), - (Focus defender_ix), - (AttackSetup (attacker_ix, defender_ix)), - (TurnResult turn_result), (RefreshCharacter attacker_ix), (RefreshCharacter defender_ix) ] - - _ -> - let actor_ix = (Struct.TurnResult.get_actor_index turn_result) in - [ - (Focus actor_ix), - (TurnResult turn_result), - (RefreshCharacter actor_ix) - ] - -initialize_animator : Type -> Type -initialize_animator model = - let - timeline_list = (Array.toList model.timeline) - (characters, players) = - (List.foldr - (\event (pcharacters, pplayers) -> - (Struct.TurnResult.apply_inverse_step - (tile_omnimods_fun model) - event - pcharacters - pplayers - ) - ) - (model.characters, model.players) - timeline_list - ) - in - {model | - animator = - (Struct.TurnResultAnimator.maybe_new - (List.reverse timeline_list) - True - ), - ui = (Struct.UI.default), - characters = characters, - players = players - } - -move_animator_to_next_step : (Maybe Type) -> (Maybe Type) -move_animator_to_next_step maybe_animator = - case maybe_animator of - Nothing -> maybe_animator - (Just animator) -> - (Struct.TurnResultAnimator.maybe_trigger_next_step animator) - --- case (Struct.TurnResultAnimator.maybe_trigger_next_step animator) of --- Nothing -> --- (Set.foldl --- (regenerate_attack_of_opportunity_markers) --- {model | animator = Nothing } --- (Struct.TurnResultAnimator.get_animated_character_indices --- animator --- ) --- ) --- --- just_next_animator -> {model | animator = just_next_animator } - -apply_animator_step : ( - BattleMap.Struct.DataSet.Type -> - Type -> - Struct.Battle.Type -> - Struct.Battle.Type - ) -apply_animator_step dataset animator battle = - case (Struct.TurnResultAnimator.get_current_animation animator) of - (Struct.TurnResultAnimator.TurnResult turn_result) -> - let - (characters, players) = - (Struct.TurnResult.apply_step - (Struct.Battle.get_tile_omnimods_fun dataset battle) - turn_result - battle - ) - in - (Struct.Battle.set_players - players - (Struct.Battle.set_characters characters battle) - ) - - _ -> battle - -pop : Type -> (Type, (Maybe Action)) -pop puppeteer = - case (Util.List.pop puppeteer.remaining_animations) of - Nothing -> (puppeteer, Nothing) - (Just (action, remaining_animations)) -> - ( - {puppeteer | - remaining_animations = remaining_animations, - primed = - if (List.isEmpty remaining_animations) - then False - else puppeteer.primed - }, - action ) + ] + +from_moved : Struct.TurnResult.Movement -> (List Type) +from_moved movement = + let actor_ix = (Struct.TurnResult.get_movement_actor movement) in + ( + [ + (Focus actor_ix), + | (List.map (\dir -> (Move (actor_ix, dir)))) + ] + ++ + [ (RefreshCharacter actor_ix) ] + ) + +from_switched_weapon : Struct.TurnResult.WeaponSwitch -> (List Type) +from_switched_weapon weapon_switch = + let actor_ix = (Struct.TurnResult.get_weapon_switch_actor weapon_switch) in + [ + (Focus actor_ix), + (SwapWeapons actor_ix) + ] + +from_player_won : Struct.TurnResult.PlayerVictory -> (List Type) +from_player_won player_victory = [] + +from_player_lost : Struct.TurnResult.PlayerLoss -> (List Type) +from_player_lost player_loss = [] + +from_player_turn_started : Struct.TurnResult.PlayerTurnStart -> (List Type) +from_player_turn_started player_turn_started = [] -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : Type -new = - { - remaining_animations = [], - primed = False - } - -append : (List Struct.TurnResult.Type) -> Type -> Type -append turn_results puppeteer = - {puppeteer | - remaining_animations = - (List.concat - puppeteer.remaining_animations - (List.map (turn_result_to_actions) turn_results) - ) - } - -is_active : Type -> Bool -is_active puppeteer = (not (List.isEmpty puppeteer.remaining_animations)) - -requires_priming : Type -> Bool -requires_priming puppeteer = (is_active and (not puppeteer.is_primed)) - -forward : Struct.Battle.Type -> Type -> (Struct.Battle.Type, Type) -forward battle puppeteer = - case (pop puppeteer) of - (next_puppeteer, Nothing) -> (battle, next_puppeteer) - (next_puppeteer, (Just action)) -> - ((apply_action action battle), next_puppeteer) - -forward : Struct.Battle.Type -> Type -> (Struct.Battle.Type, Type) -forward battle puppeteer = - case (pop puppeteer) of - (next_puppeteer, Nothing) -> (battle, next_puppeteer) - (next_puppeteer, (Just action)) -> - ((apply_action action battle), next_puppeteer) +from_turn_results : Struct.TurnResult.Type -> (List Type) +from_turn_results turn_result = + case turn_result of + (Struct.TurnResult.Moved movement) -> (from_moved movement) + (Struct.TurnResult.Attacked attack) -> (from_attacked attack) + (Struct.TurnResult.SwitchedWeapon weapon_switch) -> + (from_switched_weapon movement) + + (Struct.TurnResult.PlayerWon player_victory) -> + (from_player_won player_victory) + + (Struct.TurnResult.PlayerLost player_loss) -> + (from_player_lost player_loss) + + (Struct.TurnResult.PlayerTurnStarted player_turn_start) -> + (from_player_turn_started player_turn_start) + +forward : Type -> Struct.Battle.Type -> Struct.Battle.Type +forward puppeteer_action battle = + case puppeteer_action of + Inactive -> battle + (Target (actor_ix, target_ix)) -> + (forward_target actor_ix target_ix battle) + (Hit attack) -> (forward_hit attack battle) + (Focus actor_ix) -> (forward_focus actor_ix battle) + (Move (actor_ix, direction)) -> (forward_move actor_ix direction battle) + (SwapWeapons actor_ix) -> (forward_swap_weapons actor_ix battle) + (RefreshCharacter actor_ix) -> (forward_refresh_character actor_ix battle) + (Sequence list) -> (List.foldl (forward) battle list) + +backward : Type -> Struct.Battle.Type -> Struct.Battle.Type +backward puppeteer_action battle = + case puppeteer_action of + (Hit attack) -> (backward_hit attack battle) + (Move (actor_ix, direction)) -> (backward_move actor_ix direction battle) + (SwapWeapons actor_ix) -> (backward_swap_weapons actor_ix battle) + (Sequence list) -> (List.foldr (backward) battle list) + _ -> battle diff --git a/src/battle/src/Struct/TurnResultAnimator.elm b/src/battle/src/Struct/TurnResultAnimator.elm deleted file mode 100644 index 2a1220f..0000000 --- a/src/battle/src/Struct/TurnResultAnimator.elm +++ /dev/null @@ -1,227 +0,0 @@ -module Struct.TurnResultAnimator exposing - ( - Type, - Animation(..), - maybe_new, - maybe_trigger_next_step, - waits_for_focus, - get_current_animation, - get_animated_character_indices - ) - --- Elm ------------------------------------------------------------------------- -import Array -import Set - --- Battle Map ------------------------------------------------------------------ -import BattleMap.Struct.DataSet - --- Local Module ---------------------------------------------------------------- -import Struct.Battle -import Struct.TurnResult - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type Animation = - Inactive - | AttackSetup (Int, Int) - | Focus Int - | TurnResult Struct.TurnResult.Type - -type alias Type = - { - animated_character_ixs : (Set.Set Int), - remaining_animations : (List Animation), - current_animation : Animation, - wait_focus : Bool - } - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -turn_result_to_animations : ( - Struct.TurnResult.Type -> - ((List Animation), (Set.Set Int)) - ) -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) - ], - (Set.fromList [defender_ix, attacker_ix]) - ) - - _ -> - let actor_ix = (Struct.TurnResult.get_actor_index turn_result) in - ( - [ - (Focus actor_ix), - (TurnResult turn_result) - ], - (Set.singleton actor_ix) - ) - -turn_result_to_animations_foldl : ( - Struct.TurnResult.Type -> - ((List Animation), (Set.Set Int)) -> - ((List Animation), (Set.Set Int)) - ) -turn_result_to_animations_foldl turn_result (animations, char_ixs) = - let - (new_animations, new_char_ixs) = (turn_result_to_animations turn_result) - in - ( - (List.append animations new_animations), - (Set.union new_char_ixs char_ixs) - ) - -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 - -initialize_animator : Type -> Type -initialize_animator model = - let - timeline_list = (Array.toList model.timeline) - (characters, players) = - (List.foldr - (\event (pcharacters, pplayers) -> - (Struct.TurnResult.apply_inverse_step - (tile_omnimods_fun model) - event - pcharacters - pplayers - ) - ) - (model.characters, model.players) - timeline_list - ) - in - {model | - animator = - (Struct.TurnResultAnimator.maybe_new - (List.reverse timeline_list) - True - ), - ui = (Struct.UI.default), - characters = characters, - players = players - } - -move_animator_to_next_step : (Maybe Type) -> (Maybe Type) -move_animator_to_next_step maybe_animator = - case maybe_animator of - Nothing -> maybe_animator - (Just animator) -> - (Struct.TurnResultAnimator.maybe_trigger_next_step animator) - --- case (Struct.TurnResultAnimator.maybe_trigger_next_step animator) of --- Nothing -> --- (Set.foldl --- (regenerate_attack_of_opportunity_markers) --- {model | animator = Nothing } --- (Struct.TurnResultAnimator.get_animated_character_indices --- animator --- ) --- ) --- --- just_next_animator -> {model | animator = just_next_animator } - -apply_animator_step : ( - BattleMap.Struct.DataSet.Type -> - Type -> - Struct.Battle.Type -> - Struct.Battle.Type - ) -apply_animator_step dataset animator battle = - case (Struct.TurnResultAnimator.get_current_animation animator) of - (Struct.TurnResultAnimator.TurnResult turn_result) -> - let - (characters, players) = - (Struct.TurnResult.apply_step - (Struct.Battle.get_tile_omnimods_fun dataset battle) - turn_result - battle - ) - in - (Struct.Battle.set_players - players - (Struct.Battle.set_characters characters battle) - ) - - _ -> battle - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -maybe_new : (List Struct.TurnResult.Type) -> Bool -> (Maybe Type) -maybe_new turn_results wait_focus = - case (List.head turn_results) of - (Just head) -> - ( - let - (animations, character_ixs) = - (List.foldl - (turn_result_to_animations_foldl) - ([], (Set.empty)) - turn_results - ) - in - (Just - { - remaining_animations = animations, - current_animation = Inactive, - wait_focus = wait_focus, - animated_character_ixs = character_ixs - } - ) - ) - - _ -> Nothing - -maybe_trigger_next_step : Type -> (Maybe Type) -maybe_trigger_next_step tra = - 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 - -waits_for_focus : Type -> Bool -waits_for_focus tra = tra.wait_focus - -get_animated_character_indices : Type -> (Set.Set Int) -get_animated_character_indices tra = tra.animated_character_ixs |