summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css/src/roster-editor/controlled-panel.scss | 6 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Character.elm | 53 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetGlyph.elm | 29 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetGlyphBoard.elm | 27 | ||||
-rw-r--r-- | src/roster-editor/src/View/CharacterCard.elm | 17 | ||||
-rw-r--r-- | src/roster-editor/src/View/GlyphManagement.elm | 35 | ||||
-rw-r--r-- | src/roster-editor/src/View/GlyphSelection.elm | 2 | ||||
-rw-r--r-- | src/shared/elm/Util/List.elm | 17 |
8 files changed, 148 insertions, 38 deletions
diff --git a/src/css/src/roster-editor/controlled-panel.scss b/src/css/src/roster-editor/controlled-panel.scss index 6b6f687..c1480ce 100644 --- a/src/css/src/roster-editor/controlled-panel.scss +++ b/src/css/src/roster-editor/controlled-panel.scss @@ -25,7 +25,8 @@ } -.roster-editor-atts .omnimod-negative-value +.roster-editor-atts .omnimod-negative-value, +.roster-editor-invalid-glyph { background-color: $RED-2; border-radius: 6px; @@ -38,7 +39,8 @@ justify-items: space-evenly; } .roster-editor-invalid-character > .info-card-name, -.roster-editor-invalid-character > .character-card-name +.roster-editor-invalid-character > .character-card-name, +.roster-editor-glyph-board-problem > .character-card-glyph-board-name { background-color: $RED-2; } diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm index 003d466..c927c05 100644 --- a/src/roster-editor/src/Struct/Character.elm +++ b/src/roster-editor/src/Struct/Character.elm @@ -11,6 +11,8 @@ module Struct.Character exposing get_was_edited, set_is_valid, get_is_valid, + set_invalid_glyph_family_indices, + get_invalid_glyph_family_indices, resolve, to_unresolved, decoder, @@ -18,11 +20,18 @@ module Struct.Character exposing ) -- Elm ------------------------------------------------------------------------- +import Array + +import Set + import Json.Decode import Json.Decode.Pipeline import Json.Encode +-- Shared ---------------------------------------------------------------------- +import Util.List + -- Battle ---------------------------------------------------------------------- import Battle.Struct.Attributes import Battle.Struct.Omnimods @@ -30,6 +39,7 @@ import Battle.Struct.Omnimods -- Battle Characters ----------------------------------------------------------- import BattleCharacters.Struct.Character import BattleCharacters.Struct.Equipment +import BattleCharacters.Struct.Glyph -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -40,6 +50,7 @@ type alias Type = battle_ix : Int, was_edited : Bool, is_valid : Bool, + invalid_glyph_family_ids : (Set.Set BattleCharacters.Struct.Glyph.Ref), base : BattleCharacters.Struct.Character.Type } @@ -49,12 +60,31 @@ type alias Unresolved = battle_ix : Int, was_edited : Bool, is_valid : Bool, + invalid_glyph_family_ids : (Set.Set BattleCharacters.Struct.Glyph.Ref), base : BattleCharacters.Struct.Character.Unresolved } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +compute_invalid_glyph_family_ids : ( + BattleCharacters.Struct.Equipment.Type -> + (Set.Set BattleCharacters.Struct.Glyph.Ref) + ) +compute_invalid_glyph_family_ids equipment = + (Set.remove + (BattleCharacters.Struct.Glyph.get_family_id + (BattleCharacters.Struct.Glyph.none) + ) + (Util.List.duplicates + (List.map + (BattleCharacters.Struct.Glyph.get_family_id) + (Array.toList + (BattleCharacters.Struct.Equipment.get_glyphs equipment) + ) + ) + ) + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -88,6 +118,8 @@ set_is_valid char = {char | is_valid = ( + (Set.isEmpty char.invalid_glyph_family_ids) + && (List.all (\(s, i) -> (i >= 0)) (Battle.Struct.Omnimods.get_all_mods @@ -104,6 +136,24 @@ set_is_valid char = ) } +get_invalid_glyph_family_indices : ( + Type -> + (Set.Set BattleCharacters.Struct.Glyph.Ref) + ) +get_invalid_glyph_family_indices char = char.invalid_glyph_family_ids + +set_invalid_glyph_family_indices : ( + BattleCharacters.Struct.Equipment.Type -> + Type -> + Type + ) +set_invalid_glyph_family_indices equipment char = + let ids = (compute_invalid_glyph_family_ids equipment) in + {char | + invalid_glyph_family_ids = ids, + is_valid = (char.is_valid && (Set.isEmpty ids)) + } + resolve : ( ( BattleCharacters.Struct.Equipment.Unresolved -> @@ -119,6 +169,7 @@ resolve equipment_resolver ref = battle_ix = ref.battle_ix, was_edited = ref.was_edited, is_valid = False, + invalid_glyph_family_ids = ref.invalid_glyph_family_ids, base = (BattleCharacters.Struct.Character.resolve (equipment_resolver) @@ -135,6 +186,7 @@ to_unresolved char = battle_ix = char.battle_ix, was_edited = char.was_edited, is_valid = char.is_valid, + invalid_glyph_family_ids = char.invalid_glyph_family_ids, base = (BattleCharacters.Struct.Character.to_unresolved char.base) } @@ -146,6 +198,7 @@ decoder = |> (Json.Decode.Pipeline.hardcoded -1) |> (Json.Decode.Pipeline.hardcoded False) |> (Json.Decode.Pipeline.hardcoded True) + |> (Json.Decode.Pipeline.hardcoded (Set.empty)) |> (Json.Decode.Pipeline.required "bas" diff --git a/src/roster-editor/src/Update/SetGlyph.elm b/src/roster-editor/src/Update/SetGlyph.elm index 5d0a7f6..7007d47 100644 --- a/src/roster-editor/src/Update/SetGlyph.elm +++ b/src/roster-editor/src/Update/SetGlyph.elm @@ -31,22 +31,29 @@ apply_to model ref = ( case (model.edited_char, (Dict.get ref model.glyphs)) of ((Just char), (Just glyph)) -> - let base_char = (Struct.Character.get_base_character char) in + let + base_char = (Struct.Character.get_base_character char) + updated_equipment = + (BattleCharacters.Struct.Equipment.set_glyph + (Struct.UI.get_glyph_slot model.ui) + glyph + (BattleCharacters.Struct.Character.get_equipment + base_char + ) + ) + in {model | edited_char = (Just - (Struct.Character.set_base_character - (BattleCharacters.Struct.Character.set_equipment - (BattleCharacters.Struct.Equipment.set_glyph - (Struct.UI.get_glyph_slot model.ui) - glyph - (BattleCharacters.Struct.Character.get_equipment - base_char - ) + (Struct.Character.set_invalid_glyph_family_indices + updated_equipment + (Struct.Character.set_base_character + (BattleCharacters.Struct.Character.set_equipment + updated_equipment + base_char ) - base_char + char ) - char ) ), ui = diff --git a/src/roster-editor/src/Update/SetGlyphBoard.elm b/src/roster-editor/src/Update/SetGlyphBoard.elm index ac03e53..70a7fd6 100644 --- a/src/roster-editor/src/Update/SetGlyphBoard.elm +++ b/src/roster-editor/src/Update/SetGlyphBoard.elm @@ -30,21 +30,28 @@ apply_to model ref = ( case (model.edited_char, (Dict.get ref model.glyph_boards)) of ((Just char), (Just glyph_board)) -> - let base_char = (Struct.Character.get_base_character char) in + let + base_char = (Struct.Character.get_base_character char) + updated_equipment = + (BattleCharacters.Struct.Equipment.set_glyph_board + glyph_board + (BattleCharacters.Struct.Character.get_equipment + base_char + ) + ) + in {model | edited_char = (Just - (Struct.Character.set_base_character - (BattleCharacters.Struct.Character.set_equipment - (BattleCharacters.Struct.Equipment.set_glyph_board - glyph_board - (BattleCharacters.Struct.Character.get_equipment - base_char - ) + (Struct.Character.set_invalid_glyph_family_indices + updated_equipment + (Struct.Character.set_base_character + (BattleCharacters.Struct.Character.set_equipment + updated_equipment + base_char ) - base_char + char ) - char ) ) } diff --git a/src/roster-editor/src/View/CharacterCard.elm b/src/roster-editor/src/View/CharacterCard.elm index 0a37317..e462de9 100644 --- a/src/roster-editor/src/View/CharacterCard.elm +++ b/src/roster-editor/src/View/CharacterCard.elm @@ -5,6 +5,8 @@ module View.CharacterCard exposing ) -- Elm ------------------------------------------------------------------------- +import Set + import List import Html @@ -300,13 +302,21 @@ get_armor_details current_tab armor = ) get_glyph_board_details : ( + Bool -> BattleCharacters.Struct.GlyphBoard.Type -> (Html.Html Struct.Event.Type) ) -get_glyph_board_details board = +get_glyph_board_details has_no_invalid_glyphs board = (Html.div [ - (Html.Attributes.class "character-card-glyph-board") + (Html.Attributes.class "character-card-glyph-board"), + (Html.Attributes.class + ( + if (has_no_invalid_glyphs) + then "roster-editor-glyph-board-no-problem" + else "roster-editor-glyph-board-problem" + ) + ) ] [ (Html.div @@ -505,6 +515,9 @@ get_full_html current_tab char = (BattleCharacters.Struct.Equipment.get_armor equipment) ), (get_glyph_board_details + (Set.isEmpty + (Struct.Character.get_invalid_glyph_family_indices char) + ) (BattleCharacters.Struct.Equipment.get_glyph_board equipment) ), (get_relevant_atts omnimods char_attributes) diff --git a/src/roster-editor/src/View/GlyphManagement.elm b/src/roster-editor/src/View/GlyphManagement.elm index 072dca3..6216b2c 100644 --- a/src/roster-editor/src/View/GlyphManagement.elm +++ b/src/roster-editor/src/View/GlyphManagement.elm @@ -3,12 +3,14 @@ module View.GlyphManagement exposing (get_html) -- Elm ------------------------------------------------------------------------- import Array +import Set + import Html import Html.Attributes import Html.Events -- Battle ---------------------------------------------------------------------- -import Battle.Struct.Omnimods +import Battle.View.Omnimods -- Battle Characters ----------------------------------------------------------- import BattleCharacters.Struct.Glyph @@ -41,15 +43,27 @@ get_mod_html mod = ) get_glyph_html : ( + (Set.Set BattleCharacters.Struct.Glyph.Ref) -> Int -> (Int, BattleCharacters.Struct.Glyph.Type) -> (Html.Html Struct.Event.Type) ) -get_glyph_html modifier (index, glyph) = +get_glyph_html invalid_family_ids modifier (index, glyph) = (Html.div [ (Html.Attributes.class "character-card-glyph"), (Html.Attributes.class "clickable"), + (Html.Attributes.class + ( + if + (Set.member + (BattleCharacters.Struct.Glyph.get_family_id glyph) + invalid_family_ids + ) + then "roster-editor-invalid-glyph" + else "roster-editor-valid-glyph" + ) + ), (Html.Events.onClick (Struct.Event.ClickedOnGlyph index)) ] [ @@ -61,15 +75,8 @@ get_glyph_html modifier (index, glyph) = ++ "%)" ) ), - (Html.div - [ - ] - (List.map - (get_mod_html) - (Battle.Struct.Omnimods.get_all_mods - (BattleCharacters.Struct.Glyph.get_omnimods glyph) - ) - ) + (Battle.View.Omnimods.get_html + (BattleCharacters.Struct.Glyph.get_omnimods glyph) ) ] ) @@ -100,7 +107,11 @@ get_html model = (Html.Attributes.class "selection-window-listing") ] (List.map2 - (get_glyph_html) + (get_glyph_html + (Struct.Character.get_invalid_glyph_family_indices + char + ) + ) (BattleCharacters.Struct.GlyphBoard.get_slots (BattleCharacters.Struct.Equipment.get_glyph_board equipment diff --git a/src/roster-editor/src/View/GlyphSelection.elm b/src/roster-editor/src/View/GlyphSelection.elm index e7b1da8..d1125f6 100644 --- a/src/roster-editor/src/View/GlyphSelection.elm +++ b/src/roster-editor/src/View/GlyphSelection.elm @@ -38,7 +38,7 @@ get_glyph_html : ( BattleCharacters.Struct.Glyph.Type -> (Html.Html Struct.Event.Type) ) -get_glyph_html glyph = +get_glyph_html glyph = (Html.div [ (Html.Attributes.class "character-card-glyph"), diff --git a/src/shared/elm/Util/List.elm b/src/shared/elm/Util/List.elm index 1f914b1..829dd3e 100644 --- a/src/shared/elm/Util/List.elm +++ b/src/shared/elm/Util/List.elm @@ -1,5 +1,7 @@ module Util.List exposing (..) +import Set + import List pop : List a -> (Maybe (a, List a)) @@ -34,3 +36,18 @@ product_map_rec product_fun list_a list_b result = ) ) +duplicates : (List comparable) -> (Set.Set comparable) +duplicates list = + let + (encountered, final_result) = + (List.foldl + (\elem (met, result) -> + if (Set.member elem met) + then (met, (Set.insert elem result)) + else ((Set.insert elem met), result) + ) + ((Set.empty), (Set.empty)) + list + ) + in + final_result |