From 2542493b58b23106a398ca048d4c238d442573fd Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 16 Dec 2019 14:08:35 +0100 Subject: Don't re-compute effects on every display. --- src/battle/src/Struct/Character.elm | 57 +++++- src/battle/src/Update/HandleServerReply.elm | 1 - .../src/Update/Puppeteer/RefreshCharactersOf.elm | 63 +++++++ .../Update/Puppeteer/RefreshCharactersOfPlayer.elm | 63 ------- src/battle/src/View/Character.elm | 200 ++------------------- src/battle/src/View/Map/Character.elm | 125 ++----------- 6 files changed, 147 insertions(+), 362 deletions(-) create mode 100644 src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm delete mode 100644 src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm (limited to 'src/battle') diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm index 54a3a8c..8f452c4 100644 --- a/src/battle/src/Struct/Character.elm +++ b/src/battle/src/Struct/Character.elm @@ -21,6 +21,11 @@ module Struct.Character exposing set_base_character, get_melee_attack_range, refresh_omnimods, + add_extra_display_effect, + remove_extra_display_effect, + get_extra_display_effects, + get_extra_display_effects_list, + reset_extra_display_effects, decoder, resolve ) @@ -60,7 +65,8 @@ type alias Type = player_ix : Int, enabled : Bool, defeated : Bool, - base : BattleCharacters.Struct.Character.Type + base : BattleCharacters.Struct.Character.Type, + extra_display_effects : (Set.Set String) } type alias Unresolved = @@ -236,6 +242,52 @@ set_enabled enabled char = {char | enabled = enabled} set_defeated : Bool -> Type -> Type set_defeated defeated char = {char | defeated = defeated} +add_extra_display_effect : String -> Type -> Type +add_extra_display_effect effect_name char = + {char | + extra_display_effects = + (Set.insert effect_name char.extra_display_effects) + } + +remove_extra_display_effect : String -> Type -> Type +remove_extra_display_effect effect_name char = + {char | + extra_display_effects = + (Set.remove effect_name char.extra_display_effects) + } + +get_extra_display_effects : Type -> (Set.Set String) +get_extra_display_effects char = char.extra_display_effects + +get_extra_display_effects_list : Type -> (Set.Set String) +get_extra_display_effects_list char = (Set.toList char.extra_display_effects) + +reset_extra_display_effects : Int -> Type -> Type +reset_extra_display_effects viewer_ix char = + {char | + extra_display_effects = + (Set.fromList + [ + ( + if (viewer_ix == char.player_ix) + then "ally" + else "enemy" + ), + ("team-" ++ char.player_ix), + ( + if (char.enabled) + then "enabled" + else "disabled" + ), + ( + if (is_alive) + then "alive" + else "dead" + ) + ] + ) + } + decoder : (Json.Decode.Decoder Unresolved) decoder = (Json.Decode.succeed @@ -284,5 +336,6 @@ resolve location_omnimod_resolver equipment_resolver ref = (equipment_resolver) (location_omnimod_resolver ref.location) ref.base - ) + ), + extra_display_effects = (Set.empty) } diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm index 31dc97a..c72d165 100644 --- a/src/battle/src/Update/HandleServerReply.elm +++ b/src/battle/src/Update/HandleServerReply.elm @@ -39,7 +39,6 @@ import Struct.Model import Struct.Player import Struct.ServerReply import Struct.TurnResult -import Struct.TurnResultAnimator import Struct.UI import Update.Puppeteer diff --git a/src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm b/src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm new file mode 100644 index 0000000..a83cc91 --- /dev/null +++ b/src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm @@ -0,0 +1,63 @@ +module Update.Puppeteer.RefreshCharactersOf 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) diff --git a/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm b/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm deleted file mode 100644 index 6c91c9c..0000000 --- a/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm +++ /dev/null @@ -1,63 +0,0 @@ -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) diff --git a/src/battle/src/View/Character.elm b/src/battle/src/View/Character.elm index dc256c6..3a3f820 100644 --- a/src/battle/src/View/Character.elm +++ b/src/battle/src/View/Character.elm @@ -1,217 +1,43 @@ -module View.Character exposing - ( - get_portrait_html, - get_icon_html - ) +module View.Character exposing (get_portrait_html) -- Elm ------------------------------------------------------------------------- import Html import Html.Attributes import Html.Events --- Shared ---------------------------------------------------------------------- -import Util.Html - -- Battle Characters ----------------------------------------------------------- -import BattleCharacters.Struct.Character -import BattleCharacters.Struct.Equipment -import BattleCharacters.Struct.Portrait - import BattleCharacters.View.Portrait -- Local Module ---------------------------------------------------------------- -import Constants.UI - import Struct.Character -import Struct.CharacterTurn import Struct.Event -import Struct.Model -import Struct.UI -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_activation_level_class : ( - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_activation_level_class char = - if (Struct.Character.is_enabled char) - then - (Html.Attributes.class "character-icon-enabled") - else - (Html.Attributes.class "character-icon-disabled") - -get_alliance_class : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_alliance_class model char = - if - ( - (Struct.Character.get_player_index char) == model.player_i - == - (Struct.Battle.get_own_player_index model.battle) - ) - then (Html.Attributes.class "character-ally") - else (Html.Attributes.class "character-enemy") - -get_position_style : ( - Struct.Character.Type -> - (List (Html.Attribute Struct.Event.Type)) - ) -get_position_style char = - let char_loc = (Struct.Character.get_location char) in - [ - (Html.Attributes.style - "top" - ((String.fromInt (char_loc.y * Constants.UI.tile_size)) ++ "px") - ), - (Html.Attributes.style - "left" - ((String.fromInt (char_loc.x * Constants.UI.tile_size)) ++ "px") - ) - ] - -get_focus_class : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_focus_class model char = - if - ( - (Struct.UI.get_previous_action model.ui) - == - (Just (Struct.UI.SelectedCharacter (Struct.Character.get_index char))) - ) - then - (Html.Attributes.class "character-selected") - else - if - ( - (Struct.CharacterTurn.try_getting_target model.char_turn) - == - (Just (Struct.Character.get_index char)) - ) - then - (Html.Attributes.class "character-targeted") - else - (Html.Attributes.class "") - -get_icon_body_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) -get_icon_body_html char = - (Html.div - [ - (Html.Attributes.class "character-icon-body"), - (Html.Attributes.class - ( - "asset-character-team-body-" - ++ (String.fromInt (Struct.Character.get_player_index char)) - ) - ) - ] - [ - ] - ) - -get_icon_head_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) -get_icon_head_html char = - (Html.div - [ - (Html.Attributes.class "character-icon-head"), - (Html.Attributes.class - ( - "asset-character-icon-" - ++ - (BattleCharacters.Struct.Portrait.get_icon_id - (BattleCharacters.Struct.Equipment.get_portrait - (BattleCharacters.Struct.Character.get_equipment - (Struct.Character.get_base_character char) - ) - ) - ) - ) - ) - ] - [ - ] - ) - -get_icon_actual_html : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_icon_actual_html model char = - (Html.div - ( - [ - (Html.Attributes.class "tiled"), - (Html.Attributes.class "character-icon"), - (get_activation_level_class char), - (get_alliance_class model char), - (get_focus_class model char), - (Html.Attributes.class "clickable"), - (Html.Events.onClick - (Struct.Event.CharacterSelected - (Struct.Character.get_index char) - ) - ) - ] - ++ (get_position_style char) - ) - [ - (get_icon_body_html char), - (get_icon_head_html char) - ] - ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_portrait_html : ( - Int -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_portrait_html viewer_ix char = +get_portrait_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) +get_portrait_html char = (BattleCharacters.View.Portrait.get_html [ - (Html.Attributes.class - ( - if ((Struct.Character.get_player_index char) == viewer_ix) - then - "character-ally" - else - "character-enemy" - ) - ), - (Html.Attributes.class - ( - "character-portrait-team-" - ++ - (String.fromInt (Struct.Character.get_player_index char)) - ) - ), (Html.Events.onClick (Struct.Event.LookingForCharacter (Struct.Character.get_index char)) ) + | + (List.map + ( + \effect_name -> + (Html.Attributes.class + ("character-portrait-effect-" ++ effect_name) + ) + ) + (Struct.Character.get_extra_display_effects_list char) + ) ] (BattleCharacters.Struct.Character.get_equipment (Struct.Character.get_base_character char) ) ) - -get_icon_html : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_icon_html model char = - if (Struct.Character.is_alive char) - then - (get_icon_actual_html model char) - else - (Util.Html.nothing) diff --git a/src/battle/src/View/Map/Character.elm b/src/battle/src/View/Map/Character.elm index b20c29a..a62d197 100644 --- a/src/battle/src/View/Map/Character.elm +++ b/src/battle/src/View/Map/Character.elm @@ -20,7 +20,6 @@ import Struct.Battle import Struct.Character import Struct.CharacterTurn import Struct.Event -import Struct.Model import Struct.TurnResult import Struct.TurnResultAnimator import Struct.UI @@ -28,68 +27,6 @@ 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) -> - case (Struct.TurnResultAnimator.get_current_animation animator) of - (Struct.TurnResultAnimator.Focus char_index) -> - if ((Struct.Character.get_index char) /= char_index) - then - (Html.Attributes.class "") - else - (Html.Attributes.class "character-selected") - - (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 - "animated-character-icon" - ) - - _ -> (Html.Attributes.class "") - _ -> (Html.Attributes.class "") - -get_activation_level_class : ( - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_activation_level_class char = - if (Struct.Character.is_enabled char) - then - (Html.Attributes.class "character-icon-enabled") - else - (Html.Attributes.class "character-icon-disabled") - -get_alliance_class : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_alliance_class model char = - if - ( - (Struct.Character.get_player_index char) - == - (Struct.Battle.get_own_player_index model.battle) - ) - then (Html.Attributes.class "character-ally") - else (Html.Attributes.class "character-enemy") - get_position_style : ( Struct.Character.Type -> (List (Html.Attribute Struct.Event.Type)) @@ -107,32 +44,6 @@ get_position_style char = ) ] -get_focus_class : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Attribute Struct.Event.Type) - ) -get_focus_class model char = - if - ( - (Struct.UI.get_previous_action model.ui) - == - (Just (Struct.UI.SelectedCharacter (Struct.Character.get_index char))) - ) - then - (Html.Attributes.class "character-selected") - else - if - ( - (Struct.CharacterTurn.try_getting_target model.char_turn) - == - (Just (Struct.Character.get_index char)) - ) - then - (Html.Attributes.class "character-targeted") - else - (Html.Attributes.class "") - get_body_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) get_body_html char = (Html.div @@ -195,21 +106,13 @@ get_banner_html char = _ -> (Util.Html.nothing) -get_actual_html : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_actual_html model char = +get_actual_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) +get_actual_html char = (Html.div ( [ (Html.Attributes.class "tiled"), (Html.Attributes.class "character-icon"), - (get_animation_class model char), - (get_activation_level_class char), - (get_alliance_class model char), - (get_focus_class model char), (Html.Attributes.class "clickable"), (Html.Events.onClick (Struct.Event.CharacterSelected @@ -218,6 +121,16 @@ get_actual_html model char = ) ] ++ + (List.map + ( + \effect_name -> + (Html.Attributes.class + ("character-icon-effect-" ++ effect_name) + ) + ) + (Struct.Character.get_extra_display_effects_list char) + ) + ++ (get_position_style char) ) [ @@ -230,14 +143,8 @@ get_actual_html model char = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_html : ( - Struct.Model.Type -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_html model char = +get_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) +get_html char = if (Struct.Character.is_alive char) - then - (get_actual_html model char) - else - (Util.Html.nothing) + then (get_actual_html char) + else (Util.Html.nothing) -- cgit v1.2.3-70-g09d2 From a22cf9ed01111999a8397ed4a9723d97ea407bdd Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 16 Dec 2019 14:22:16 +0100 Subject: ... --- src/battle/src/Struct/Battle.elm | 15 +++++++++++---- src/battle/src/View/Map/Character.elm | 4 ---- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/battle') diff --git a/src/battle/src/Struct/Battle.elm b/src/battle/src/Struct/Battle.elm index c7f5c0a..19c3ceb 100644 --- a/src/battle/src/Struct/Battle.elm +++ b/src/battle/src/Struct/Battle.elm @@ -131,12 +131,19 @@ new = ---- Characters ---- -------------------- add_character : Struct.Character.Type -> Type -> Type -add_character char battle = - let characters = battle.characters in +add_character s0char battle = + let + s1char = + (Struct.Character.reset_extra_display_effects + battle.own_player_ix + s0char + ) + characters = battle.characters + in (regenerate_attack_of_opportunity_markers_of_char (Array.length characters) - char - {battle | characters = (Array.push char characters)} + s1char + {battle | characters = (Array.push s1char characters)} ) get_character : Int -> Type -> (Maybe Struct.Character.Type) diff --git a/src/battle/src/View/Map/Character.elm b/src/battle/src/View/Map/Character.elm index a62d197..b1442b1 100644 --- a/src/battle/src/View/Map/Character.elm +++ b/src/battle/src/View/Map/Character.elm @@ -16,12 +16,8 @@ import BattleCharacters.Struct.Equipment -- Local Module ---------------------------------------------------------------- import Constants.UI -import Struct.Battle import Struct.Character -import Struct.CharacterTurn import Struct.Event -import Struct.TurnResult -import Struct.TurnResultAnimator import Struct.UI -------------------------------------------------------------------------------- -- cgit v1.2.3-70-g09d2 From 0db9aabba95a33fd23c192343721559f9ca15581 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 17 Dec 2019 17:44:38 +0100 Subject: ... --- src/battle/src/Struct/MessageBoard.elm | 72 ++++++++++++++++++++++++++++++++++ src/battle/src/Struct/Model.elm | 22 +++++------ 2 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 src/battle/src/Struct/MessageBoard.elm (limited to 'src/battle') diff --git a/src/battle/src/Struct/MessageBoard.elm b/src/battle/src/Struct/MessageBoard.elm new file mode 100644 index 0000000..9ddecf0 --- /dev/null +++ b/src/battle/src/Struct/MessageBoard.elm @@ -0,0 +1,72 @@ +module Struct.MessageBoard exposing + ( + Type, + Message(..), + display, + try_getting_current_message, + clear_current_message, + new, + clear + ) + +-- Elm ------------------------------------------------------------------------- + +-- Local Module ---------------------------------------------------------------- +import Struct.Attack +import Struct.Error +import Struct.HelpRequest + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Message = + Help Struct.HelpRequest.Type + | Error Struct.Error.Type + | AttackReport Struct.Attack.Type + +type alias Type = + { + secondary_messages = (List Message), + main_message = (Maybe Message) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +display : Message -> Type -> Type +display message board = + case message of + (AttackReport _) -> {board | main_message = (Just message)} + _ -> + {board | + secondary_messages = [message|board.secondary_messages] + } + +try_getting_current_message : Type -> (Maybe Message) +try_getting_current_message board = + case secondary_messages of + [] -> board.main_message + [secondary_message|_] -> (Just secondary_message) + +clear_current_message : Type -> Type +clear_current_message board = + case secondary_messages of + [] -> {board | main_message = Nothing} + [_|remaining_secondary_messages] -> + {board | + secondary_messages = remaining_secondary_messages + } + +new : Type +new = + { + secondary_messages = [], + main_message = Nothing + } + +clear : Type -> Type +clear board = (new) diff --git a/src/battle/src/Struct/Model.elm b/src/battle/src/Struct/Model.elm index a53b4df..989f66d 100644 --- a/src/battle/src/Struct/Model.elm +++ b/src/battle/src/Struct/Model.elm @@ -19,9 +19,9 @@ import BattleMap.Struct.DataSet -- Local Module ---------------------------------------------------------------- import Struct.CharacterTurn import Struct.Error -import Struct.HelpRequest -import Struct.TurnResult +import Struct.MessageBoard import Struct.Puppeteer +import Struct.TurnResult import Struct.UI -------------------------------------------------------------------------------- @@ -30,11 +30,10 @@ import Struct.UI type alias Type = { flags : Struct.Flags.Type, - help_request : Struct.HelpRequest.Type, puppeteer : Struct.Puppeteer.Type, ui : Struct.UI.Type, char_turn : Struct.CharacterTurn.Type, - error : (Maybe Struct.Error.Type), + message_board : Struct.MessageBoard.Type, battle : Struct.Battle.Type, @@ -56,11 +55,10 @@ new flags = model = { flags = flags, - help_request = Struct.HelpRequest.None, puppeteer = (Struct.Puppeteer.new), ui = (Struct.UI.default), char_turn = (Struct.CharacterTurn.new), - error = Nothing, + message_board = (Struct.MessageBoard.new), characters_data_set = (BattleCharacters.Struct.DataSet.new), map_data_set = (BattleMap.Struct.DataSet.new), @@ -86,8 +84,7 @@ new flags = clear : Type -> Type clear model = {model | - help_request = Struct.HelpRequest.None, - error = Nothing, + message_board = (Struct.MessageBoard.clear), ui = (Struct.UI.reset_displayed_nav (Struct.UI.set_previous_action Nothing model.ui) @@ -98,8 +95,9 @@ clear model = invalidate : Struct.Error.Type -> Type -> Type invalidate err model = {model | - error = (Just err) + message_board = + (Struct.MessageBoard.display + (Struct.MessageBoard.Error err) + model.message_board + ) } - -clear_error : Type -> Type -clear_error model = {model | error = Nothing} -- cgit v1.2.3-70-g09d2 From dc7c1857845a5da7cd6cba178c16fa8ea8c68cec Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 14 Jan 2020 17:55:15 +0100 Subject: ... --- conf/nginx.conf | 15 + src/battle/src/Struct/Battle.elm | 40 ++- src/battle/src/Struct/Character.elm | 8 +- src/battle/src/Struct/MessageBoard.elm | 14 +- src/battle/src/Struct/PuppeteerAction.elm | 16 +- src/battle/src/Struct/TurnResult.elm | 371 --------------------- src/battle/src/View/Character.elm | 8 +- src/battle/src/View/Controlled/CharacterCard.elm | 6 +- src/battle/src/View/MessageBoard.elm | 28 +- .../src/View/MessageBoard/Animator/Attack.elm | 304 ----------------- src/battle/src/View/MessageBoard/Attack.elm | 262 +++++++++++++++ src/battle/src/View/SubMenu/Timeline/Attack.elm | 4 +- src/battle/src/View/SubMenu/Timeline/Movement.elm | 2 +- .../src/View/SubMenu/Timeline/WeaponSwitch.elm | 2 +- 14 files changed, 352 insertions(+), 728 deletions(-) delete mode 100644 src/battle/src/View/MessageBoard/Animator/Attack.elm create mode 100644 src/battle/src/View/MessageBoard/Attack.elm (limited to 'src/battle') diff --git a/conf/nginx.conf b/conf/nginx.conf index afafbd5..82ec6b7 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -69,6 +69,21 @@ http { } } + server { +# listen 127.0.0.1; + listen *:2900; + server_name localhost; + access_log /var/log/nginx/localhost.access_log main; + error_log /var/log/nginx/localhost.error_log info; + + root /my/src/nickel-bet-client/www/; + + location / { + autoindex on; + autoindex_exact_size off; + } + } + # ## Public tests # server { # listen 443; diff --git a/src/battle/src/Struct/Battle.elm b/src/battle/src/Struct/Battle.elm index 19c3ceb..84d08ba 100644 --- a/src/battle/src/Struct/Battle.elm +++ b/src/battle/src/Struct/Battle.elm @@ -85,14 +85,14 @@ regenerate_attack_of_opportunity_tags_for_char char_ix char battle = let tag_name = ("matk_c" ++ (String.fromInt char_ix)) map_without_this_tag = - (BattleMap.Struct.Map.remove_tag tag_name battle.map) + (BattleMap.Struct.Map.remove_marker tag_name battle.map) in case (Struct.Character.get_melee_attack_range char) of 0 -> {battle | map = map_without_this_tag} attack_range -> {battle | map = - (BattleMap.Struct.Map.add_tag + (BattleMap.Struct.Map.add_marker tag_name (BattleMap.Struct.Marker.new_melee_attack char_ix @@ -140,7 +140,7 @@ add_character s0char battle = ) characters = battle.characters in - (regenerate_attack_of_opportunity_markers_of_char + (regenerate_attack_of_opportunity_tags_for_char (Array.length characters) s1char {battle | characters = (Array.push s1char characters)} @@ -170,21 +170,27 @@ set_characters chars battle = {battle | characters = chars} refresh_character : BattleMap.Struct.DataSet.Type -> Int -> Type -> Type refresh_character map_dataset ix battle = - let - character = (get_character ix battle) - refreshed_character = - (Struct.Character.refresh_omnimods - (\loc -> - (BattleMap.Struct.Map.get_omnimods_at loc map_dataset battle.map) + case (get_character ix battle) of + Nothing -> battle + (Just character) -> + let + refreshed_character = + (Struct.Character.refresh_omnimods + (\loc -> + (BattleMap.Struct.Map.get_omnimods_at + loc + map_dataset + battle.map + ) + ) + character + ) + in + (regenerate_attack_of_opportunity_tags_for_char + ix + refreshed_character + (set_character ix refreshed_character battle) ) - character - ) - in - (regenerate_attack_of_opportunity_tags_for_char - ix - refreshed_character - (set_character ix refreshed_character battle) - ) ----------------- ---- Players ---- diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm index 8f452c4..6cdbaab 100644 --- a/src/battle/src/Struct/Character.elm +++ b/src/battle/src/Struct/Character.elm @@ -193,7 +193,7 @@ refresh_omnimods : ( Type -> Type ) -refresh_omnimods omnimods_fun character = +refresh_omnimods omnimods_fun char = let previous_max_health = (Battle.Struct.Attributes.get_max_health @@ -259,7 +259,7 @@ remove_extra_display_effect effect_name char = get_extra_display_effects : Type -> (Set.Set String) get_extra_display_effects char = char.extra_display_effects -get_extra_display_effects_list : Type -> (Set.Set String) +get_extra_display_effects_list : Type -> (List String) get_extra_display_effects_list char = (Set.toList char.extra_display_effects) reset_extra_display_effects : Int -> Type -> Type @@ -273,14 +273,14 @@ reset_extra_display_effects viewer_ix char = then "ally" else "enemy" ), - ("team-" ++ char.player_ix), + ("team-" ++ (String.fromInt char.player_ix)), ( if (char.enabled) then "enabled" else "disabled" ), ( - if (is_alive) + if (is_alive char) then "alive" else "dead" ) diff --git a/src/battle/src/Struct/MessageBoard.elm b/src/battle/src/Struct/MessageBoard.elm index 9ddecf0..4c3ad1c 100644 --- a/src/battle/src/Struct/MessageBoard.elm +++ b/src/battle/src/Struct/MessageBoard.elm @@ -26,8 +26,8 @@ type Message = type alias Type = { - secondary_messages = (List Message), - main_message = (Maybe Message) + secondary_messages : (List Message), + main_message : (Maybe Message) } -------------------------------------------------------------------------------- @@ -43,20 +43,20 @@ display message board = (AttackReport _) -> {board | main_message = (Just message)} _ -> {board | - secondary_messages = [message|board.secondary_messages] + secondary_messages = (message :: board.secondary_messages) } try_getting_current_message : Type -> (Maybe Message) try_getting_current_message board = - case secondary_messages of + case board.secondary_messages of [] -> board.main_message - [secondary_message|_] -> (Just secondary_message) + (secondary_message :: _) -> (Just secondary_message) clear_current_message : Type -> Type clear_current_message board = - case secondary_messages of + case board.secondary_messages of [] -> {board | main_message = Nothing} - [_|remaining_secondary_messages] -> + (_ :: remaining_secondary_messages) -> {board | secondary_messages = remaining_secondary_messages } diff --git a/src/battle/src/Struct/PuppeteerAction.elm b/src/battle/src/Struct/PuppeteerAction.elm index 47a0bcc..c8207b0 100644 --- a/src/battle/src/Struct/PuppeteerAction.elm +++ b/src/battle/src/Struct/PuppeteerAction.elm @@ -11,8 +11,10 @@ import Set -- Battle Map ------------------------------------------------------------------ import BattleMap.Struct.DataSet +import BattleMap.Struct.Direction -- Local Module ---------------------------------------------------------------- +import Struct.Attack import Struct.Battle import Struct.TurnResult @@ -24,9 +26,9 @@ type Effect = | AnnounceVictory Int | Focus Int | Hit Struct.Attack.Type - | Move (Int, Battle.Struct.Direction) - | RefreshCharacter (Boolean, Int) - | RefreshCharactersOf (Boolean, Int) + | Move (Int, BattleMap.Struct.Direction.Type) + | RefreshCharacter (Bool, Int) + | RefreshCharactersOf (Bool, Int) | StartTurn Int | SwapWeapons Int | Target (Int, Int) @@ -54,7 +56,7 @@ from_attacked attack = (PerformFor (2.0, [(Focus attacker_ix)])), (PerformFor (2.0, [(Focus defender_ix)])), (List.map - (PerformFor (..., (Hit attack))) + (PerformFor (5.0, (Hit attack))) ), (Perform [ @@ -70,8 +72,10 @@ from_moved movement = ( [ (PerformFor (1.0, [(Focus actor_ix)])), - (Perform [(RefreshCharacter (False, actor_ix))]), - | + (Perform [(RefreshCharacter (False, actor_ix))]) + ] + ++ + [ (List.map (\dir -> (PerformFor diff --git a/src/battle/src/Struct/TurnResult.elm b/src/battle/src/Struct/TurnResult.elm index aaf3dfa..b0d7d09 100644 --- a/src/battle/src/Struct/TurnResult.elm +++ b/src/battle/src/Struct/TurnResult.elm @@ -7,13 +7,6 @@ module Struct.TurnResult exposing PlayerVictory, PlayerDefeat, PlayerTurnStart, - get_next_movement_dir, - get_actor_index, - get_attack_defender_index, - maybe_get_attack_next_step, - apply_inverse_step, - apply_step, - maybe_remove_step, decoder ) @@ -90,218 +83,6 @@ type Type = -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -apply_movement_step : ( - (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> - Movement -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_movement_step tile_omnimods movement characters players = - ( - (Util.Array.update_unsafe - movement.character_index - (\char -> - case (List.head movement.path) of - (Just dir) -> - (Struct.Character.dirty_set_location - (BattleMap.Struct.Location.neighbor - dir - (Struct.Character.get_location char) - ) - char - ) - - Nothing -> - let current_location = (Struct.Character.get_location char) in - (Struct.Character.set_location - current_location - (tile_omnimods current_location) - char - ) - ) - characters - ), - players - ) - -apply_inverse_movement_step : ( - (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> - Movement -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_inverse_movement_step tile_omnimods movement characters players = - ( - (Util.Array.update_unsafe - movement.character_index - (\char -> - ( - let - location = - (List.foldr - (BattleMap.Struct.Location.neighbor) - (Struct.Character.get_location char) - --(movement.destination) - (List.map - (BattleMap.Struct.Direction.opposite_of) - movement.path - ) - ) - in - (Struct.Character.set_location - location - (tile_omnimods location) - char - ) - ) - ) - characters - ), - players - ) - -apply_switched_weapon : ( - WeaponSwitch -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_switched_weapon weapon_switch characters players = - ( - (Util.Array.update_unsafe - weapon_switch.character_index - (\char -> - (Struct.Character.set_base_character - (BattleCharacters.Struct.Character.switch_weapons - (Struct.Character.get_base_character char) - ) - char - ) - ) - characters - ), - players - ) - -apply_player_defeat : ( - PlayerDefeat -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_player_defeat pdefeat characters players = - ( - (Array.map - (\c -> - if ((Struct.Character.get_player_index c) == pdefeat.player_index) - then (Struct.Character.set_defeated True c) - else c - ) - characters - ), - players - ) - -apply_inverse_player_defeat : ( - PlayerDefeat -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_inverse_player_defeat pdefeat characters players = - ( - (Array.map - (\c -> - ( - if - ( - (Struct.Character.get_player_index c) - == pdefeat.player_index - ) - then (Struct.Character.set_defeated False c) - else c - ) - ) - characters - ), - players - ) - -apply_attack_step : ( - Attack -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_attack_step attack characters players = - case (List.head attack.sequence) of - (Just attack_step) -> - ( - (Struct.Attack.apply_to_characters - attack.attacker_index - attack.defender_index - attack_step - characters - ), - players - ) - - Nothing -> - ( - characters, - (Util.Array.update_unsafe - attack.attacker_index - (Struct.Player.set_luck attack.attacker_luck) - (Util.Array.update_unsafe - attack.defender_index - (Struct.Player.set_luck attack.defender_luck) - players - ) - ) - ) - -apply_inverse_attack : ( - Attack -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_inverse_attack attack characters players = - ( - (List.foldr - (Struct.Attack.apply_inverse_to_characters - attack.attacker_index - attack.defender_index - ) - characters - attack.sequence - ), - players - ) - movement_decoder : (Json.Decode.Decoder Movement) movement_decoder = (Json.Decode.map3 @@ -397,162 +178,10 @@ internal_decoder kind = ++ "\"." ) ) - -maybe_remove_movement_step : Movement -> (Maybe Type) -maybe_remove_movement_step movement = - case (List.tail movement.path) of - Nothing -> Nothing - (Just path_tail) -> - (Just - (Moved - {movement | - path = path_tail - } - ) - ) - -maybe_remove_attack_step : Attack -> (Maybe Type) -maybe_remove_attack_step attack = - case (List.tail attack.sequence) of - Nothing -> Nothing - (Just sequence_tail) -> - (Just - (Attacked - {attack | - sequence = sequence_tail - } - ) - ) - -apply_player_victory : ( - PlayerVictory -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_player_victory player_victory characters players = - ( - characters, - players - ) - -apply_player_turn_started : ( - PlayerTurnStart -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_player_turn_started player_defeat characters players = - ( - characters, - players - ) - -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -apply_step : ( - (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> - Type -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_step tile_omnimods turn_result characters players = - case turn_result of - (Moved movement) -> - (apply_movement_step (tile_omnimods) movement characters players) - - (SwitchedWeapon weapon_switch) -> - (apply_switched_weapon weapon_switch characters players) - - (Attacked attack) -> - (apply_attack_step attack characters players) - - (PlayerWon pvict) -> - (apply_player_victory pvict characters players) - - (PlayerLost pdefeat) -> - (apply_player_defeat pdefeat characters players) - - (PlayerTurnStarted pturns) -> - (apply_player_turn_started pturns characters players) - -apply_inverse_step : ( - (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) -> - Type -> - (Array.Array Struct.Character.Type) -> - (Array.Array Struct.Player.Type) -> - ( - (Array.Array Struct.Character.Type), - (Array.Array Struct.Player.Type) - ) - ) -apply_inverse_step tile_omnimods turn_result characters players = - case turn_result of - (Moved movement) -> - (apply_inverse_movement_step - (tile_omnimods) - movement - characters - players - ) - - (SwitchedWeapon weapon_switch) -> - (apply_switched_weapon weapon_switch characters players) - - (Attacked attack) -> - (apply_inverse_attack attack characters players) - - (PlayerWon pvict) -> (characters, players) - - (PlayerLost pdefeat) -> - (apply_inverse_player_defeat pdefeat characters players) - - (PlayerTurnStarted pturns) -> (characters, players) - decoder : (Json.Decode.Decoder Type) decoder = (Json.Decode.field "t" Json.Decode.string) |> (Json.Decode.andThen internal_decoder) - -maybe_remove_step : Type -> (Maybe Type) -maybe_remove_step turn_result = - case turn_result of - (Moved movement) -> (maybe_remove_movement_step movement) - (SwitchedWeapon _) -> Nothing - (Attacked attack) -> (maybe_remove_attack_step attack) - (PlayerWon pvict) -> Nothing - (PlayerLost pdefeat) -> Nothing - (PlayerTurnStarted pturns) -> Nothing - -get_next_movement_dir : Movement -> BattleMap.Struct.Direction.Type -get_next_movement_dir movement = - case (List.head movement.path) of - (Just dir) -> dir - Nothing -> BattleMap.Struct.Direction.None - -get_attack_defender_index : Attack -> Int -get_attack_defender_index attack = attack.defender_index - -maybe_get_attack_next_step : Attack -> (Maybe Struct.Attack.Type) -maybe_get_attack_next_step attack = (List.head attack.sequence) - -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 - (PlayerWon pvict) -> pvict.player_index - (PlayerLost pdefeat) -> pdefeat.player_index - (PlayerTurnStarted pturns) -> pturns.player_index diff --git a/src/battle/src/View/Character.elm b/src/battle/src/View/Character.elm index 3a3f820..dac5989 100644 --- a/src/battle/src/View/Character.elm +++ b/src/battle/src/View/Character.elm @@ -6,6 +6,8 @@ import Html.Attributes import Html.Events -- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Character + import BattleCharacters.View.Portrait -- Local Module ---------------------------------------------------------------- @@ -22,11 +24,11 @@ import Struct.Event get_portrait_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) get_portrait_html char = (BattleCharacters.View.Portrait.get_html - [ + ( (Html.Events.onClick (Struct.Event.LookingForCharacter (Struct.Character.get_index char)) ) - | + :: (List.map ( \effect_name -> @@ -36,7 +38,7 @@ get_portrait_html char = ) (Struct.Character.get_extra_display_effects_list char) ) - ] + ) (BattleCharacters.Struct.Character.get_equipment (Struct.Character.get_base_character char) ) diff --git a/src/battle/src/View/Controlled/CharacterCard.elm b/src/battle/src/View/Controlled/CharacterCard.elm index 291263c..0d7eda1 100644 --- a/src/battle/src/View/Controlled/CharacterCard.elm +++ b/src/battle/src/View/Controlled/CharacterCard.elm @@ -352,7 +352,7 @@ get_minimal_html player_ix char = (Html.Attributes.class "info-card-picture") ] [ - (View.Character.get_portrait_html player_ix char) + (View.Character.get_portrait_html char) ] ), (get_health_bar char), @@ -400,7 +400,7 @@ get_summary_html char_turn player_ix char = (Html.Attributes.class "info-card-picture") ] [ - (View.Character.get_portrait_html player_ix char) + (View.Character.get_portrait_html char) ] ), (get_health_bar char), @@ -456,7 +456,7 @@ get_full_html player_ix char = (Html.Attributes.class "info-card-picture") ] [ - (View.Character.get_portrait_html player_ix char) + (View.Character.get_portrait_html char) ] ), (get_health_bar char), diff --git a/src/battle/src/View/MessageBoard.elm b/src/battle/src/View/MessageBoard.elm index 9b31f65..8a47b40 100644 --- a/src/battle/src/View/MessageBoard.elm +++ b/src/battle/src/View/MessageBoard.elm @@ -3,28 +3,38 @@ module View.MessageBoard exposing (get_html) -- Elm ------------------------------------------------------------------------- import Html +-- Shared ---------------------------------------------------------------------- +import Util.Html + -- Local Module ---------------------------------------------------------------- import Struct.Event import Struct.Model +import Struct.MessageBoard -import View.MessageBoard.Animator +import View.MessageBoard.Attack import View.MessageBoard.Error import View.MessageBoard.Help -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +display : ( + Struct.Model.Type -> + Struct.MessageBoard.Message -> + (Html.Html Struct.Event.Type) + ) +display model message = + case message of + (Error error_msg) -> (View.MessageBoard.Error.get_html model error_msg) + (AttackReport attack) -> (View.MessageBoard.Attack.get_html model attack) + (Help help_request) -> + (View.MessageBoard.Help.get_html model help_request) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type) get_html model = - case (model.error) of - (Just error) -> (View.MessageBoard.Error.get_html model error) - Nothing -> - case model.animator of - (Just animator) -> - (View.MessageBoard.Animator.get_html model.battle animator) - - Nothing -> (View.MessageBoard.Help.get_html model) + case (Struct.MessageBoard.try_getting_current_message model.message_board) of + Nothing -> (Util.Html.nothing) + (Just message) -> (display model message) diff --git a/src/battle/src/View/MessageBoard/Animator/Attack.elm b/src/battle/src/View/MessageBoard/Animator/Attack.elm deleted file mode 100644 index 6b79903..0000000 --- a/src/battle/src/View/MessageBoard/Animator/Attack.elm +++ /dev/null @@ -1,304 +0,0 @@ -module View.MessageBoard.Animator.Attack exposing (get_html) - --- Elm ------------------------------------------------------------------------- -import Array - -import Html -import Html.Attributes - --- Battle Characters ----------------------------------------------------------- -import BattleCharacters.Struct.Character - --- Local Module ---------------------------------------------------------------- -import Struct.Attack -import Struct.Battle -import Struct.Character -import Struct.Event - -import View.Controlled.CharacterCard - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_effect_text : Struct.Attack.Type -> String -get_effect_text attack = - ( - ( - case attack.precision of - Struct.Attack.Hit -> " hit for " - Struct.Attack.Graze -> " grazed for " - Struct.Attack.Miss -> " missed." - ) - ++ - ( - if (attack.precision == Struct.Attack.Miss) - then - "" - else - ( - ((String.fromInt attack.damage) ++ " damage") - ++ - ( - if (attack.critical) - then " (Critical Hit)." - else "." - ) - ) - ) - ) - -get_empty_attack_html : (Html.Html Struct.Event.Type) -get_empty_attack_html = - (Html.div - [ - (Html.Attributes.class "message-attack-text") - ] - [] - ) - -get_attack_html : ( - Struct.Character.Type -> - Struct.Character.Type -> - Struct.Attack.Type -> - (Html.Html Struct.Event.Type) - ) -get_attack_html attacker defender attack = - let - attacker_name = - (BattleCharacters.Struct.Character.get_name - (Struct.Character.get_base_character attacker) - ) - defender_name = - (BattleCharacters.Struct.Character.get_name - (Struct.Character.get_base_character defender) - ) - in - (Html.div - [ - (Html.Attributes.class "message-attack-text") - ] - [ - (Html.text - ( - case (attack.order, attack.parried) of - (Struct.Attack.Counter, True) -> - ( - defender_name - ++ " attempted to strike back, but " - ++ attacker_name - ++ " parried, and " - ++ (get_effect_text attack) - ) - - (Struct.Attack.Counter, _) -> - ( - defender_name - ++ " striked back, and " - ++ (get_effect_text attack) - ) - - (_, True) -> - ( - attacker_name - ++ " attempted a hit, but " - ++ defender_name - ++ " parried, and " - ++ (get_effect_text attack) - ) - - (_, _) -> - (attacker_name ++ " " ++ (get_effect_text attack)) - ) - ) - ] - ) - -get_attack_animation_class : ( - Struct.Attack.Type -> - Struct.Character.Type -> - String - ) -get_attack_animation_class attack char = - if (attack.critical) - then "animated-portrait-attack-critical" - else "animated-portrait-attacks" - -get_defense_animation_class : ( - Struct.Attack.Type -> - Struct.Character.Type -> - String - ) -get_defense_animation_class attack char = - if (attack.damage == 0) - then - if (attack.precision == Struct.Attack.Miss) - then "animated-portrait-dodges" - else "animated-portrait-undamaged" - else if ((Struct.Character.get_current_health char) > 0) - then - if (attack.precision == Struct.Attack.Graze) - then "animated-portrait-grazed-damage" - else "animated-portrait-damaged" - else - if (attack.precision == Struct.Attack.Graze) - then "animated-portrait-grazed-death" - else "animated-portrait-dies" - -get_attacker_card : ( - (Maybe Struct.Attack.Type) -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_attacker_card maybe_attack char = - (Html.div - (case maybe_attack of - Nothing -> - if ((Struct.Character.get_current_health char) > 0) - then - [ - (Html.Attributes.class "animated-portrait") - ] - else - [ - (Html.Attributes.class "animated-portrait-absent"), - (Html.Attributes.class "animated-portrait") - ] - - (Just attack) -> - [ - (Html.Attributes.class - (case (attack.order, attack.parried) of - (Struct.Attack.Counter, True) -> - (get_attack_animation_class attack char) - - (Struct.Attack.Counter, _) -> - (get_defense_animation_class attack char) - - (_, True) -> - (get_defense_animation_class attack char) - - (_, _) -> - (get_attack_animation_class attack char) - ) - ), - (Html.Attributes.class "animated-portrait") - ] - ) - [ - (View.Controlled.CharacterCard.get_minimal_html - (Struct.Character.get_player_index char) - char - ) - ] - ) - -get_defender_card : ( - (Maybe Struct.Attack.Type) -> - Struct.Character.Type -> - (Html.Html Struct.Event.Type) - ) -get_defender_card maybe_attack char = - (Html.div - (case maybe_attack of - Nothing -> - if ((Struct.Character.get_current_health char) > 0) - then - [ - (Html.Attributes.class "animated-portrait") - ] - else - [ - (Html.Attributes.class "animated-portrait-absent"), - (Html.Attributes.class "animated-portrait") - ] - - (Just attack) -> - [ - (Html.Attributes.class - (case (attack.order, attack.parried) of - (Struct.Attack.Counter, True) -> - (get_defense_animation_class attack char) - - (Struct.Attack.Counter, _) -> - (get_attack_animation_class attack char) - - (_, True) -> - (get_attack_animation_class attack char) - - (_, _) -> - (get_defense_animation_class attack char) - ) - ), - (Html.Attributes.class "animated-portrait") - ] - ) - [ - (View.Controlled.CharacterCard.get_minimal_html -1 char) - ] - ) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_placeholder_html : ( - (Array.Array Struct.Character.Type) -> - Int -> - Int -> - (Maybe Struct.Attack.Type) -> - (Html.Html Struct.Event.Type) - ) -get_placeholder_html characters attacker_ix defender_ix maybe_attack = - case - ( - (Array.get attacker_ix characters), - (Array.get defender_ix characters) - ) - of - ((Just atkchar), (Just defchar)) -> - (Html.div - [ - (Html.Attributes.class "message-board"), - (Html.Attributes.class "message-attack") - ] - ( - [ - (get_attacker_card maybe_attack atkchar), - ( - case maybe_attack of - (Just attack) -> - (get_attack_html atkchar defchar attack) - - Nothing -> - (get_empty_attack_html) - ), - (get_defender_card maybe_attack defchar) - ] - ) - ) - - _ -> - (Html.div - [ - ] - [ - (Html.text "Error: Attack with unknown characters") - ] - ) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_html : ( - Struct.Battle.Type -> - Int -> - Int -> - (Maybe Struct.Attack.Type) -> - (Html.Html Struct.Event.Type) - ) -get_html battle attacker_ix defender_ix maybe_attack = - (get_placeholder_html - (Struct.Battle.get_characters battle) - attacker_ix - defender_ix - maybe_attack - ) diff --git a/src/battle/src/View/MessageBoard/Attack.elm b/src/battle/src/View/MessageBoard/Attack.elm new file mode 100644 index 0000000..041b3e3 --- /dev/null +++ b/src/battle/src/View/MessageBoard/Attack.elm @@ -0,0 +1,262 @@ +module View.MessageBoard.Attack exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Array + +import Html +import Html.Attributes + +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Character + +-- Local Module ---------------------------------------------------------------- +import Struct.Attack +import Struct.Battle +import Struct.Character +import Struct.Event +import Struct.Model + +import View.Controlled.CharacterCard + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_effect_text : Struct.Attack.Type -> String +get_effect_text attack = + ( + ( + case attack.precision of + Struct.Attack.Hit -> " hit for " + Struct.Attack.Graze -> " grazed for " + Struct.Attack.Miss -> " missed." + ) + ++ + ( + if (attack.precision == Struct.Attack.Miss) + then + "" + else + ( + ((String.fromInt attack.damage) ++ " damage") + ++ + ( + if (attack.critical) + then " (Critical Hit)." + else "." + ) + ) + ) + ) + +get_empty_attack_html : (Html.Html Struct.Event.Type) +get_empty_attack_html = + (Html.div + [ + (Html.Attributes.class "message-attack-text") + ] + [] + ) + +get_attack_html : ( + Struct.Character.Type -> + Struct.Character.Type -> + Struct.Attack.Type -> + (Html.Html Struct.Event.Type) + ) +get_attack_html attacker defender attack = + let + attacker_name = + (BattleCharacters.Struct.Character.get_name + (Struct.Character.get_base_character attacker) + ) + defender_name = + (BattleCharacters.Struct.Character.get_name + (Struct.Character.get_base_character defender) + ) + in + (Html.div + [ + (Html.Attributes.class "message-attack-text") + ] + [ + (Html.text + ( + case (attack.order, attack.parried) of + (Struct.Attack.Counter, True) -> + ( + defender_name + ++ " attempted to strike back, but " + ++ attacker_name + ++ " parried, and " + ++ (get_effect_text attack) + ) + + (Struct.Attack.Counter, _) -> + ( + defender_name + ++ " striked back, and " + ++ (get_effect_text attack) + ) + + (_, True) -> + ( + attacker_name + ++ " attempted a hit, but " + ++ defender_name + ++ " parried, and " + ++ (get_effect_text attack) + ) + + (_, _) -> + (attacker_name ++ " " ++ (get_effect_text attack)) + ) + ) + ] + ) + +get_attack_animation_class : ( + Struct.Attack.Type -> + Struct.Character.Type -> + String + ) +get_attack_animation_class attack char = + if (attack.critical) + then "animated-portrait-attack-critical" + else "animated-portrait-attacks" + +get_defense_animation_class : ( + Struct.Attack.Type -> + Struct.Character.Type -> + String + ) +get_defense_animation_class attack char = + if (attack.damage == 0) + then + if (attack.precision == Struct.Attack.Miss) + then "animated-portrait-dodges" + else "animated-portrait-undamaged" + else if ((Struct.Character.get_current_health char) > 0) + then + if (attack.precision == Struct.Attack.Graze) + then "animated-portrait-grazed-damage" + else "animated-portrait-damaged" + else + if (attack.precision == Struct.Attack.Graze) + then "animated-portrait-grazed-death" + else "animated-portrait-dies" + +get_attacker_card : ( + Struct.Attack.Type -> + Struct.Character.Type -> + (Html.Html Struct.Event.Type) + ) +get_attacker_card attack char = + (Html.div + [ + (Html.Attributes.class + (case (attack.order, attack.parried) of + (Struct.Attack.Counter, True) -> + (get_attack_animation_class attack char) + + (Struct.Attack.Counter, _) -> + (get_defense_animation_class attack char) + + (_, True) -> + (get_defense_animation_class attack char) + + (_, _) -> + (get_attack_animation_class attack char) + ) + ), + (Html.Attributes.class "animated-portrait") + ] + [ + (View.Controlled.CharacterCard.get_minimal_html + (Struct.Character.get_player_index char) + char + ) + ] + ) + +get_defender_card : ( + Struct.Attack.Type -> + Struct.Character.Type -> + (Html.Html Struct.Event.Type) + ) +get_defender_card attack char = + (Html.div + [ + (Html.Attributes.class + (case (attack.order, attack.parried) of + (Struct.Attack.Counter, True) -> + (get_defense_animation_class attack char) + + (Struct.Attack.Counter, _) -> + (get_attack_animation_class attack char) + + (_, True) -> + (get_attack_animation_class attack char) + + (_, _) -> + (get_defense_animation_class attack char) + ) + ), + (Html.Attributes.class "animated-portrait") + ] + [ + (View.Controlled.CharacterCard.get_minimal_html -1 char) + ] + ) + +get_placeholder_html : ( + (Array.Array Struct.Character.Type) -> + Int -> + Int -> + Struct.Attack.Type -> + (Html.Html Struct.Event.Type) + ) +get_placeholder_html characters attacker_ix defender_ix attack = + case + ( + (Array.get attacker_ix characters), + (Array.get defender_ix characters) + ) + of + ((Just atkchar), (Just defchar)) -> + (Html.div + [ + (Html.Attributes.class "message-board"), + (Html.Attributes.class "message-attack") + ] + ( + [ + (get_attacker_card attack atkchar), + (get_attack_html atkchar defchar attack), + (get_defender_card attack defchar) + ] + ) + ) + + _ -> + (Html.div + [ + ] + [ + (Html.text "Error: Attack with unknown characters") + ] + ) +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : ( + Struct.Model.Type -> + Struct.Attack.Type -> + (Html.Html Struct.Event.Type) + ) +get_html model attack = + (get_placeholder_html + (Struct.Battle.get_characters model.battle) + 0 -- TODO: get attacker IX + 0 -- TODO: get defender IX + attack + ) diff --git a/src/battle/src/View/SubMenu/Timeline/Attack.elm b/src/battle/src/View/SubMenu/Timeline/Attack.elm index 7301126..fe43b6a 100644 --- a/src/battle/src/View/SubMenu/Timeline/Attack.elm +++ b/src/battle/src/View/SubMenu/Timeline/Attack.elm @@ -153,8 +153,8 @@ get_html characters player_ix attack = ] ( [ - (View.Character.get_portrait_html player_ix atkchar), - (View.Character.get_portrait_html player_ix defchar), + (View.Character.get_portrait_html atkchar), + (View.Character.get_portrait_html defchar), (get_title_html atkchar defchar) ] ++ diff --git a/src/battle/src/View/SubMenu/Timeline/Movement.elm b/src/battle/src/View/SubMenu/Timeline/Movement.elm index 3ef305e..4d748be 100644 --- a/src/battle/src/View/SubMenu/Timeline/Movement.elm +++ b/src/battle/src/View/SubMenu/Timeline/Movement.elm @@ -38,7 +38,7 @@ get_html characters player_ix movement = (Html.Attributes.class "timeline-movement") ] [ - (View.Character.get_portrait_html player_ix char), + (View.Character.get_portrait_html char), (Html.text ( (BattleCharacters.Struct.Character.get_name diff --git a/src/battle/src/View/SubMenu/Timeline/WeaponSwitch.elm b/src/battle/src/View/SubMenu/Timeline/WeaponSwitch.elm index 50fd702..f547df8 100644 --- a/src/battle/src/View/SubMenu/Timeline/WeaponSwitch.elm +++ b/src/battle/src/View/SubMenu/Timeline/WeaponSwitch.elm @@ -38,7 +38,7 @@ get_html characters player_ix weapon_switch = (Html.Attributes.class "timeline-weapon-switch") ] [ - (View.Character.get_portrait_html player_ix char), + (View.Character.get_portrait_html char), (Html.text ( (BattleCharacters.Struct.Character.get_name -- cgit v1.2.3-70-g09d2