summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/src/Struct/PuppeteerAction.elm | 35 | ||||
-rw-r--r-- | src/battle/src/Update/Puppeteer/RefreshCharacter.elm | 50 | ||||
-rw-r--r-- | src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm | 63 |
3 files changed, 113 insertions, 35 deletions
diff --git a/src/battle/src/Struct/PuppeteerAction.elm b/src/battle/src/Struct/PuppeteerAction.elm index 6f7b102..47a0bcc 100644 --- a/src/battle/src/Struct/PuppeteerAction.elm +++ b/src/battle/src/Struct/PuppeteerAction.elm @@ -25,7 +25,8 @@ type Effect = | Focus Int | Hit Struct.Attack.Type | Move (Int, Battle.Struct.Direction) - | RefreshCharacter Int + | RefreshCharacter (Boolean, Int) + | RefreshCharactersOf (Boolean, Int) | StartTurn Int | SwapWeapons Int | Target (Int, Int) @@ -44,6 +45,12 @@ from_attacked attack = defender_ix = (Struct.TurnResult.get_attack_defender_index attack) in [ + (Perform + [ + (RefreshCharacter (False, attacker_ix)), + (RefreshCharacter (False, defender_ix)) + ] + ), (PerformFor (2.0, [(Focus attacker_ix)])), (PerformFor (2.0, [(Focus defender_ix)])), (List.map @@ -51,8 +58,8 @@ from_attacked attack = ), (Perform [ - (RefreshCharacter attacker_ix), - (RefreshCharacter defender_ix) + (RefreshCharacter (True, attacker_ix)), + (RefreshCharacter (True, defender_ix)) ] ) ] @@ -63,6 +70,7 @@ from_moved movement = ( [ (PerformFor (1.0, [(Focus actor_ix)])), + (Perform [(RefreshCharacter (False, actor_ix))]), | (List.map (\dir -> @@ -76,7 +84,7 @@ from_moved movement = ) ] ++ - [ (Perform [(RefreshCharacter actor_ix)]) ] + [ (Perform [(RefreshCharacter (True, actor_ix))]) ] ) from_switched_weapon : Struct.TurnResult.WeaponSwitch -> (List Type) @@ -84,7 +92,16 @@ from_switched_weapon weapon_switch = let actor_ix = (Struct.TurnResult.get_weapon_switch_actor weapon_switch) in [ (PerformFor (1.0, [(Focus actor_ix)])), - (PerformFor (2.0, [(SwapWeapons actor_ix)])) + (PerformFor + ( + 2.0, + [ + (RefreshCharacter (False, actor_ix)), + (SwapWeapons actor_ix) + (RefreshCharacter (True, actor_ix)) + ] + ) + ) ] from_player_won : Struct.TurnResult.PlayerVictory -> (List Type) @@ -109,9 +126,11 @@ from_player_lost player_loss = ( 2.0, [ + (RefreshCharactersOf (False, player_ix)), (AnnounceLoss (Struct.TurnResult.get_player_loss_index player_loss) - ) + ), + (RefreshCharactersOf (True, player_ix)) ] ) ) @@ -124,11 +143,13 @@ from_player_turn_started player_turn_started = ( 2.0, [ + (RefreshCharactersOf (False, player_ix)), (StartPlayerTurn (Struct.TurnResult.get_player_start_of_turn_index player_turn_started ) - ) + ), + (RefreshCharactersOf (True, player_ix)) ] ) ) diff --git a/src/battle/src/Update/Puppeteer/RefreshCharacter.elm b/src/battle/src/Update/Puppeteer/RefreshCharacter.elm index 75b86dc..a392238 100644 --- a/src/battle/src/Update/Puppeteer/RefreshCharacter.elm +++ b/src/battle/src/Update/Puppeteer/RefreshCharacter.elm @@ -1,53 +1,47 @@ module Update.Puppeteer.RefreshCharacter exposing (forward, backward) --- FIXME: This might not be the way to go about it. This works when going --- forward, as all the "dirty" changes have applied before the character is --- refreshed, but this step will appear *before* the changes when going --- backward, which means those changes are not taken into account during the --- "refresh". - -- Local Module ---------------------------------------------------------------- -import Action.Scroll - import Struct.Battle -import Struct.Character import Struct.Event import Struct.Model -import Struct.UI -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- - +perform : ( + Int -> + Struct.Model.Type -> + (Struct.Model.Type, (List (Cmd Struct.Event.Type))) + ) +perform actor_ix model = + ( + {model | + battle = (Struct.Battle.refresh_character actor_ix model.battle) + }, + [] + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- forward : ( + Bool -> Int -> Struct.Model.Type -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ) -forward actor_ix model = - let character = (Struct.Battle.get_character actor_ix model.battle) in - ( - {model | - battle = - (Struct.Battle.set_character - actor_ix - (Struct.Character.set_location - (Struct.Character.get_location character) - character - ) - model.battle - ) - }, - [] - ) +forward is_forward actor_ix model = + if (is_forward) + then (perform actor_ix model) + else (model, []) backward : ( + Bool -> Int -> Struct.Model.Type -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ) -backward actor_ix model = (model, []) +backward is_forward actor_ix model = (model, []) + if (is_forward) + then (model, []) + else (perform actor_ix model) diff --git a/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm b/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm new file mode 100644 index 0000000..6c91c9c --- /dev/null +++ b/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm @@ -0,0 +1,63 @@ +module Update.Puppeteer.RefreshCharactersOfPlayer exposing (forward, backward) + +-- Elm ------------------------------------------------------------------------- +import Array + +-- Local Module ---------------------------------------------------------------- +import Struct.Battle +import Struct.Character +import Struct.Event +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +perform : ( + Int -> + Struct.Model.Type -> + (Struct.Model.Type, (List (Cmd Struct.Event.Type))) + ) +perform player_ix model = + ( + {model | + battle = + (Array.foldl + (\actor battle -> + if ((Struct.Character.get_player_index actor) == player_ix) + then + (Struct.Battle.refresh_character + (Struct.Character.get_index actor) + battle + ) + else battle + ) + model.battle + (Struct.Battle.get_characters model.battle) + ) + }, + [] + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +forward : ( + Bool -> + Int -> + Struct.Model.Type -> + (Struct.Model.Type, (List (Cmd Struct.Event.Type))) + ) +forward is_forward player_ix model = + if (is_forward) + then (perform player_ix model) + else (model, []) + +backward : ( + Int -> + Struct.Model.Type -> + (Struct.Model.Type, (List (Cmd Struct.Event.Type))) + ) +backward is_forward player_ix model = + if (is_forward) + then (model, []) + else (perform player_ix model) |