aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-09-09 17:57:36 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-09-09 17:57:36 +0200
commitc2f3e908511cdf782f4a324002a15b607ffbd125 (patch)
tree6c29ab9362106fb75ba361deee5240f1cda0a97c
parent1eaca6c3fcd4b36b38a51d639341179ce3858eba (diff)
downloadtacticians-client-c2f3e908511cdf782f4a324002a15b607ffbd125.zip
tacticians-client-c2f3e908511cdf782f4a324002a15b607ffbd125.tar.bz2
Highlights invalid glyphs.
-rw-r--r--src/css/src/roster-editor/controlled-panel.scss6
-rw-r--r--src/roster-editor/src/Struct/Character.elm53
-rw-r--r--src/roster-editor/src/Update/SetGlyph.elm29
-rw-r--r--src/roster-editor/src/Update/SetGlyphBoard.elm27
-rw-r--r--src/roster-editor/src/View/CharacterCard.elm17
-rw-r--r--src/roster-editor/src/View/GlyphManagement.elm35
-rw-r--r--src/roster-editor/src/View/GlyphSelection.elm2
-rw-r--r--src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm7
-rw-r--r--src/shared/elm/Util/List.elm17
9 files changed, 155 insertions, 38 deletions
diff --git a/src/css/src/roster-editor/controlled-panel.scss b/src/css/src/roster-editor/controlled-panel.scss
index c5a8030..385f3be 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;
@@ -34,7 +35,8 @@
}
.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 1f64f38..81e4e9f 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
@@ -502,6 +512,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/battle-characters/BattleCharacters/Struct/Glyph.elm b/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm
index 9a86fb4..2a5054d 100644
--- a/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm
+++ b/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm
@@ -5,6 +5,7 @@ module BattleCharacters.Struct.Glyph exposing
find,
get_name,
get_id,
+ get_family_id,
get_omnimods,
none,
default,
@@ -27,6 +28,7 @@ type alias Type =
{
id : String,
name : String,
+ family_id : String,
omnimods : Battle.Struct.Omnimods.Type
}
@@ -48,6 +50,9 @@ find dict ref =
get_id : Type -> Ref
get_id g = g.id
+get_family_id : Type -> Ref
+get_family_id g = g.family_id
+
get_name : Type -> String
get_name g = g.name
@@ -60,6 +65,7 @@ decoder =
Type
|> (Json.Decode.Pipeline.required "id" Json.Decode.string)
|> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "fam" Json.Decode.string)
|> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder)
)
@@ -68,6 +74,7 @@ none =
{
id = "0",
name = "Empty",
+ family_id = "0",
omnimods = (Battle.Struct.Omnimods.none)
}
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