From c70d77cea8ef6d98c3c1f50728e45b655d7b2a54 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 14 Sep 2019 12:51:50 +0200 Subject: Removes code smell, fixes roster editor atts view. It's still not coloring the negative values correctly, though. --- src/battle/src/View/SubMenu/Status/TileInfo.elm | 2 +- src/roster-editor/src/View/ArmorSelection.elm | 2 +- src/roster-editor/src/View/CharacterCard.elm | 46 ++---- src/roster-editor/src/View/GlyphBoardSelection.elm | 19 --- src/roster-editor/src/View/GlyphManagement.elm | 2 +- src/roster-editor/src/View/GlyphSelection.elm | 2 +- src/roster-editor/src/View/WeaponSelection.elm | 24 +-- src/shared/battle/Battle/View/Attribute.elm | 162 ++++++--------------- src/shared/battle/Battle/View/DamageType.elm | 74 +++------- src/shared/battle/Battle/View/Omnimods.elm | 30 ++-- 10 files changed, 97 insertions(+), 266 deletions(-) diff --git a/src/battle/src/View/SubMenu/Status/TileInfo.elm b/src/battle/src/View/SubMenu/Status/TileInfo.elm index 76e6e0e..ff983b2 100644 --- a/src/battle/src/View/SubMenu/Status/TileInfo.elm +++ b/src/battle/src/View/SubMenu/Status/TileInfo.elm @@ -148,7 +148,7 @@ get_html model loc = (get_cost tile) ] ), - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html ((Struct.Model.tile_omnimods_fun model) loc) ) ] diff --git a/src/roster-editor/src/View/ArmorSelection.elm b/src/roster-editor/src/View/ArmorSelection.elm index 0a3beb5..671e56e 100644 --- a/src/roster-editor/src/View/ArmorSelection.elm +++ b/src/roster-editor/src/View/ArmorSelection.elm @@ -62,7 +62,7 @@ get_armor_html armor = ) ] ), - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (BattleCharacters.Struct.Armor.get_omnimods armor) ) ] diff --git a/src/roster-editor/src/View/CharacterCard.elm b/src/roster-editor/src/View/CharacterCard.elm index 0dc8c4c..ef211e9 100644 --- a/src/roster-editor/src/View/CharacterCard.elm +++ b/src/roster-editor/src/View/CharacterCard.elm @@ -203,38 +203,6 @@ get_weapon_field_header is_active_wp weapon = ] ) -get_mod_html : (String, Int) -> (Html.Html Struct.Event.Type) -get_mod_html mod = - let - (category, value) = mod - in - (Html.div - [ - (Html.Attributes.class "info-card-mod"), - (Html.Attributes.class - ( - if (value < 0) - then "omnimod-negative-value" - else - if (value > 0) - then "omnimod-positive-value" - else "omnimod-nil-value" - ) - ) - ] - [ - (Html.div - [ - (Html.Attributes.class "omnimod-icon"), - (Html.Attributes.class ("omnimod-icon-" ++ category)) - ] - [ - ] - ), - (Html.text (String.fromInt value)) - ] - ) - get_weapon_details : ( Struct.UI.Tab -> Bool -> @@ -259,7 +227,7 @@ get_weapon_details current_tab is_active_wp weapon = ( if (is_active_wp && (current_tab == Struct.UI.WeaponSelectionTab)) then - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (BattleCharacters.Struct.Weapon.get_omnimods weapon) ) else (Util.Html.nothing) @@ -293,7 +261,7 @@ get_armor_details current_tab armor = ( if (current_tab == Struct.UI.ArmorSelectionTab) then - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (BattleCharacters.Struct.Armor.get_omnimods armor) ) else (Util.Html.nothing) @@ -467,6 +435,14 @@ get_full_html current_tab char = ) (BattleCharacters.Struct.Equipment.get_glyph_board equipment) ), - (Battle.View.Omnimods.get_user_friendly_html omnimods) + (Battle.View.Omnimods.get_unsigned_html + (Battle.Struct.Omnimods.apply_damage_modifier + (Battle.Struct.Omnimods.get_attribute_mod + Battle.Struct.Attributes.DamageModifier + omnimods + ) + omnimods + ) + ) ] ) diff --git a/src/roster-editor/src/View/GlyphBoardSelection.elm b/src/roster-editor/src/View/GlyphBoardSelection.elm index 803b362..b9edfa8 100644 --- a/src/roster-editor/src/View/GlyphBoardSelection.elm +++ b/src/roster-editor/src/View/GlyphBoardSelection.elm @@ -7,9 +7,6 @@ import Html import Html.Attributes import Html.Events --- Battle ---------------------------------------------------------------------- -import Battle.View.Omnimods - -- Battle Characters ----------------------------------------------------------- import BattleCharacters.Struct.GlyphBoard @@ -20,22 +17,6 @@ import Struct.Model -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_mod_html : (String, Int) -> (Html.Html Struct.Event.Type) -get_mod_html mod = - let - (category, value) = mod - in - (Html.div - [ - (Html.Attributes.class "info-card-mod") - ] - [ - (Html.text - (category ++ ": " ++ (String.fromInt value)) - ) - ] - ) - get_glyph_board_html : ( BattleCharacters.Struct.GlyphBoard.Type -> (Html.Html Struct.Event.Type) diff --git a/src/roster-editor/src/View/GlyphManagement.elm b/src/roster-editor/src/View/GlyphManagement.elm index a636516..458b713 100644 --- a/src/roster-editor/src/View/GlyphManagement.elm +++ b/src/roster-editor/src/View/GlyphManagement.elm @@ -76,7 +76,7 @@ get_glyph_html invalid_family_ids modifier (index, glyph) = ++ "%)" ) ), - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (Battle.Struct.Omnimods.scale ((toFloat modifier) / 100.0) (BattleCharacters.Struct.Glyph.get_omnimods glyph) diff --git a/src/roster-editor/src/View/GlyphSelection.elm b/src/roster-editor/src/View/GlyphSelection.elm index 67faf59..9cc825d 100644 --- a/src/roster-editor/src/View/GlyphSelection.elm +++ b/src/roster-editor/src/View/GlyphSelection.elm @@ -75,7 +75,7 @@ get_glyph_html invalid_family_ids factor glyph = ] [ (Html.text (BattleCharacters.Struct.Glyph.get_name glyph)), - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (Battle.Struct.Omnimods.scale factor (BattleCharacters.Struct.Glyph.get_omnimods glyph) diff --git a/src/roster-editor/src/View/WeaponSelection.elm b/src/roster-editor/src/View/WeaponSelection.elm index 7844237..361db6b 100644 --- a/src/roster-editor/src/View/WeaponSelection.elm +++ b/src/roster-editor/src/View/WeaponSelection.elm @@ -25,28 +25,6 @@ import Struct.Model -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_mod_html : (String, Int) -> (Html.Html Struct.Event.Type) -get_mod_html mod = - let - (category, value) = mod - in - (Html.div - [ - (Html.Attributes.class "info-card-mod") - ] - [ - (Html.div - [ - (Html.Attributes.class "omnimod-icon"), - (Html.Attributes.class ("omnimod-icon-" ++ category)) - ] - [ - ] - ), - (Html.text (String.fromInt value)) - ] - ) - get_weapon_html : ( BattleCharacters.Struct.Weapon.Type -> (Html.Html Struct.Event.Type) @@ -116,7 +94,7 @@ get_weapon_html weapon = ) ] ), - (Battle.View.Omnimods.get_html + (Battle.View.Omnimods.get_signed_html (BattleCharacters.Struct.Weapon.get_omnimods weapon) ) ] diff --git a/src/shared/battle/Battle/View/Attribute.elm b/src/shared/battle/Battle/View/Attribute.elm index 80e75f1..7e00b2f 100644 --- a/src/shared/battle/Battle/View/Attribute.elm +++ b/src/shared/battle/Battle/View/Attribute.elm @@ -1,9 +1,8 @@ module Battle.View.Attribute exposing ( - get_html, - get_all_html, - get_true_all_html, - get_all_but_gauges_html, + get_unsigned_html, + get_all_unsigned_html, + get_all_but_gauges_unsigned_html, get_signed_html, get_all_signed_html, get_all_but_gauges_signed_html @@ -24,16 +23,13 @@ import Struct.HelpRequest -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- get_html : ( + Bool -> Battle.Struct.Attributes.Category -> Int -> (Html.Html Struct.Event.Type) ) -get_html attribute value = +get_html signed attribute value = (Html.div [ (Html.Events.onClick @@ -45,54 +41,7 @@ get_html attribute value = ( if (value < 0) then "omnimod-negative-value" - else - if (value > 0) - then "omnimod-positive-value" - else "omnimod-nil-value" - ) - ), - (Html.Attributes.class "omnimod-icon"), - (Html.Attributes.class - ( - "omnimod-icon-" - ++ (Battle.Struct.Attributes.encode_category attribute) - ) - ) - ] - [ - (Html.div - [ - (Html.Attributes.class "omnimod-value") - ] - [ - (Html.text - ( - if (Battle.Struct.Attributes.is_percent attribute) - then ((String.fromInt value) ++ "%") - else (String.fromInt value) - ) - ) - ] - ) - ] - ) - -get_signed_html : ( - Battle.Struct.Attributes.Category -> - Int -> - (Html.Html Struct.Event.Type) - ) -get_signed_html attribute value = - (Html.div - [ - ( - if (value < 0) - then (Html.Attributes.class "omnimod-negative") - else (Html.Attributes.class "omnimod-positive") - ), - (Html.Events.onClick - (Struct.Event.RequestedHelp - (Struct.HelpRequest.Attribute attribute) + else "omnimod-positive-value" ) ), (Html.Attributes.class "omnimod-icon"), @@ -112,7 +61,7 @@ get_signed_html attribute value = (Html.text ( ( - if (value > 0) + if ((value > 0) && signed) then ("+" ++ (String.fromInt value)) else (String.fromInt value) ) @@ -129,86 +78,65 @@ get_signed_html attribute value = ] ) -get_all_html : ( +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_signed_html : ( + Battle.Struct.Attributes.Category -> + Int -> + (Html.Html Struct.Event.Type) + ) +get_signed_html attribute value = + (get_html True attribute value) + +get_unsigned_html : ( + Battle.Struct.Attributes.Category -> + Int -> + (Html.Html Struct.Event.Type) + ) +get_unsigned_html attribute value = + (get_html False attribute value) + +get_all_unsigned_html : ( Battle.Struct.Attributes.Type -> (List (Html.Html Struct.Event.Type)) ) -get_all_html atts = +get_all_unsigned_html atts = [ - (get_html + (get_unsigned_html Battle.Struct.Attributes.Dodges (Battle.Struct.Attributes.get_dodges atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.Parries (Battle.Struct.Attributes.get_parries atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.Accuracy (Battle.Struct.Attributes.get_accuracy atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.DoubleHits (Battle.Struct.Attributes.get_double_hits atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.CriticalHits (Battle.Struct.Attributes.get_critical_hits atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.MaxHealth (Battle.Struct.Attributes.get_max_health atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.MovementPoints (Battle.Struct.Attributes.get_movement_points atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.DamageModifier (Battle.Struct.Attributes.get_damage_modifier atts) ) ] -get_true_all_html : ( - Battle.Struct.Attributes.Type -> - (List (Html.Html Struct.Event.Type)) - ) -get_true_all_html atts = - [ - (get_html - Battle.Struct.Attributes.Dodges - (Battle.Struct.Attributes.get_true_dodges atts) - ), - (get_html - Battle.Struct.Attributes.Parries - (Battle.Struct.Attributes.get_true_parries atts) - ), - (get_html - Battle.Struct.Attributes.Accuracy - (Battle.Struct.Attributes.get_true_accuracy atts) - ), - (get_html - Battle.Struct.Attributes.DoubleHits - (Battle.Struct.Attributes.get_true_double_hits atts) - ), - (get_html - Battle.Struct.Attributes.CriticalHits - (Battle.Struct.Attributes.get_true_critical_hits atts) - ), - (get_html - Battle.Struct.Attributes.MaxHealth - (Battle.Struct.Attributes.get_true_max_health atts) - ), - (get_html - Battle.Struct.Attributes.MovementPoints - (Battle.Struct.Attributes.get_true_movement_points atts) - ), - (get_html - Battle.Struct.Attributes.DamageModifier - (Battle.Struct.Attributes.get_true_damage_modifier atts) - ) - ] - get_all_signed_html : ( Battle.Struct.Attributes.Type -> (List (Html.Html Struct.Event.Type)) @@ -249,37 +177,37 @@ get_all_signed_html atts = ) ] -get_all_but_gauges_html : ( +get_all_but_gauges_unsigned_html : ( Battle.Struct.Attributes.Type -> (List (Html.Html Struct.Event.Type)) ) -get_all_but_gauges_html atts = +get_all_but_gauges_unsigned_html atts = [ - (get_html + (get_unsigned_html Battle.Struct.Attributes.Dodges (Battle.Struct.Attributes.get_dodges atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.Parries (Battle.Struct.Attributes.get_parries atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.Accuracy (Battle.Struct.Attributes.get_accuracy atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.DoubleHits (Battle.Struct.Attributes.get_double_hits atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.CriticalHits (Battle.Struct.Attributes.get_critical_hits atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.CriticalHits (Battle.Struct.Attributes.get_critical_hits atts) ), - (get_html + (get_unsigned_html Battle.Struct.Attributes.DamageModifier (Battle.Struct.Attributes.get_damage_modifier atts) ) diff --git a/src/shared/battle/Battle/View/DamageType.elm b/src/shared/battle/Battle/View/DamageType.elm index 1302407..bd1242d 100644 --- a/src/shared/battle/Battle/View/DamageType.elm +++ b/src/shared/battle/Battle/View/DamageType.elm @@ -1,6 +1,6 @@ module Battle.View.DamageType exposing ( - get_html, + get_unsigned_html, get_signed_html ) @@ -21,55 +21,21 @@ import Struct.HelpRequest -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- get_html : ( + Bool -> Battle.Struct.DamageType.Type -> Int -> (Html.Html Struct.Event.Type) ) -get_html damage_type value = +get_html signed damage_type value = (Html.div [ - (Html.Events.onClick - (Struct.Event.RequestedHelp - (Struct.HelpRequest.DamageType damage_type) - ) - ), - (Html.Attributes.class "omnimod-icon"), (Html.Attributes.class ( - "omnimod-icon-" - ++ (Battle.Struct.DamageType.encode damage_type) + if (value < 0) + then "omnimod-negative-value" + else "omnimod-positive-value" ) - ) - ] - [ - (Html.div - [ - (Html.Attributes.class "omnimod-value") - ] - [ - (Html.text (String.fromInt value)) - ] - ) - ] - ) - -get_signed_html : ( - Battle.Struct.DamageType.Type -> - Int -> - (Html.Html Struct.Event.Type) - ) -get_signed_html damage_type value = - (Html.div - [ - ( - if (value < 0) - then (Html.Attributes.class "omnimod-negative") - else (Html.Attributes.class "omnimod-positive") ), (Html.Events.onClick (Struct.Event.RequestedHelp @@ -92,7 +58,7 @@ get_signed_html damage_type value = [ (Html.text ( - if (value > 0) + if ((value > 0) && signed) then ("+" ++ (String.fromInt value)) else (String.fromInt value) ) @@ -102,16 +68,22 @@ get_signed_html damage_type value = ] ) -get_all_html : ( - (List (Battle.Struct.DamageType.Type, Int)) -> - (List (Html.Html Struct.Event.Type)) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_unsigned_html : ( + Battle.Struct.DamageType.Type -> + Int -> + (Html.Html Struct.Event.Type) ) -get_all_html damage_types = - (List.map (\(d, v) -> (get_html d v)) damage_types) +get_unsigned_html damage_type value = + (get_html False damage_type value) -get_all_signed_html : ( - (List (Battle.Struct.DamageType.Type, Int)) -> - (List (Html.Html Struct.Event.Type)) +get_signed_html : ( + Battle.Struct.DamageType.Type -> + Int -> + (Html.Html Struct.Event.Type) ) -get_all_signed_html damage_types = - (List.map (\(d, v) -> (get_signed_html d v)) damage_types) +get_signed_html damage_type value = + (get_html True damage_type value) diff --git a/src/shared/battle/Battle/View/Omnimods.elm b/src/shared/battle/Battle/View/Omnimods.elm index 14da8ed..8693e9e 100644 --- a/src/shared/battle/Battle/View/Omnimods.elm +++ b/src/shared/battle/Battle/View/Omnimods.elm @@ -1,7 +1,7 @@ module Battle.View.Omnimods exposing ( - get_html_with_modifier, - get_html, + get_signed_html, + get_unsigned_html, get_user_friendly_html ) @@ -30,12 +30,8 @@ import Struct.Event -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_html_with_modifier : ( - Float -> - Battle.Struct.Omnimods.Type -> - (Html.Html Struct.Event.Type) - ) -get_html_with_modifier attack_multiplier omnimods = +get_signed_html : Battle.Struct.Omnimods.Type -> (Html.Html Struct.Event.Type) +get_signed_html omnimods = (Html.div [ (Html.Attributes.class "omnimod-listing") @@ -49,7 +45,7 @@ get_html_with_modifier attack_multiplier omnimods = (\(k, v) -> (Battle.View.DamageType.get_signed_html (Battle.Struct.DamageType.decode k) - (ceiling ((toFloat v) * attack_multiplier)) + v ) ) (Battle.Struct.Omnimods.get_attack_mods omnimods) @@ -86,8 +82,8 @@ get_html_with_modifier attack_multiplier omnimods = ] ) -get_html : Battle.Struct.Omnimods.Type -> (Html.Html Struct.Event.Type) -get_html omnimods = +get_unsigned_html : Battle.Struct.Omnimods.Type -> (Html.Html Struct.Event.Type) +get_unsigned_html omnimods = (Html.div [ (Html.Attributes.class "omnimod-listing") @@ -99,7 +95,7 @@ get_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.DamageType.get_signed_html + (Battle.View.DamageType.get_unsigned_html (Battle.Struct.DamageType.decode k) v ) @@ -113,7 +109,7 @@ get_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.DamageType.get_signed_html + (Battle.View.DamageType.get_unsigned_html (Battle.Struct.DamageType.decode k) v ) @@ -127,7 +123,7 @@ get_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.Attribute.get_signed_html + (Battle.View.Attribute.get_unsigned_html (Battle.Struct.Attributes.decode_category k) v ) @@ -169,7 +165,7 @@ get_user_friendly_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.DamageType.get_html + (Battle.View.DamageType.get_unsigned_html (Battle.Struct.DamageType.decode k) (max 0 v) ) @@ -183,7 +179,7 @@ get_user_friendly_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.DamageType.get_html + (Battle.View.DamageType.get_unsigned_html (Battle.Struct.DamageType.decode k) (max 0 v) ) @@ -197,7 +193,7 @@ get_user_friendly_html omnimods = ] (List.map (\(k, v) -> - (Battle.View.Attribute.get_html + (Battle.View.Attribute.get_unsigned_html (Battle.Struct.Attributes.decode_category k) (max 0 v) ) -- cgit v1.2.3-70-g09d2