From 0e0738794535add036274aa4c43a74f247add899 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 12 Nov 2018 18:38:32 +0100 Subject: More or less working glyph selection. It works, but doesn't enforce the right restrictions yet... --- src/roster-editor/src/ElmModule/Update.elm | 12 +++- src/roster-editor/src/Struct/Character.elm | 6 +- src/roster-editor/src/Struct/Event.elm | 3 +- src/roster-editor/src/Struct/GlyphBoard.elm | 17 ++++- src/roster-editor/src/Struct/Omnimods.elm | 14 ++++ src/roster-editor/src/Struct/UI.elm | 18 ++++- src/roster-editor/src/Update/SetGlyph.elm | 15 +++- src/roster-editor/src/View/CurrentTab.elm | 4 ++ src/roster-editor/src/View/GlyphBoardSelection.elm | 5 +- src/roster-editor/src/View/GlyphManagement.elm | 74 ++++++++++++++++++- src/roster-editor/src/View/GlyphSelection.elm | 84 ++++++++++++++++++++++ 11 files changed, 236 insertions(+), 16 deletions(-) create mode 100644 src/roster-editor/src/View/GlyphSelection.elm diff --git a/src/roster-editor/src/ElmModule/Update.elm b/src/roster-editor/src/ElmModule/Update.elm index 20a4c81..8d46fc6 100644 --- a/src/roster-editor/src/ElmModule/Update.elm +++ b/src/roster-editor/src/ElmModule/Update.elm @@ -89,8 +89,16 @@ update event model = (Struct.Event.SelectedWeapon ref) -> (Update.SetWeapon.apply_to new_model ref) - (Struct.Event.SelectedGlyph (ref, index)) -> - (Update.SetGlyph.apply_to new_model ref index) + (Struct.Event.SelectedGlyph ref) -> + (Update.SetGlyph.apply_to new_model ref) + + (Struct.Event.ClickedOnGlyph index) -> + (Update.SelectTab.apply_to + {model | + ui = (Struct.UI.set_glyph_slot index model.ui) + } + Struct.UI.GlyphSelectionTab + ) (Struct.Event.SelectedGlyphBoard ref) -> (Update.SetGlyphBoard.apply_to new_model ref) diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm index 58d9967..2778b6d 100644 --- a/src/roster-editor/src/Struct/Character.elm +++ b/src/roster-editor/src/Struct/Character.elm @@ -203,7 +203,11 @@ set_glyph_board glyph_board char = (refresh_omnimods {char | glyph_board = glyph_board, - glyphs = (Array.empty) + glyphs = + (Array.repeat + (List.length (Struct.GlyphBoard.get_slots glyph_board)) + (Struct.Glyph.none) + ) } ) diff --git a/src/roster-editor/src/Struct/Event.elm b/src/roster-editor/src/Struct/Event.elm index 570f84b..3ac3715 100644 --- a/src/roster-editor/src/Struct/Event.elm +++ b/src/roster-editor/src/Struct/Event.elm @@ -26,10 +26,11 @@ type Type = | ServerReplied (Result Http.Error (List Struct.ServerReply.Type)) | TabSelected Struct.UI.Tab | ClickedOnWeapon Bool + | ClickedOnGlyph Int | SaveRequest | SelectedArmor Struct.Armor.Ref - | SelectedGlyph (Struct.Glyph.Ref, Int) + | SelectedGlyph Struct.Glyph.Ref | SelectedGlyphBoard Struct.GlyphBoard.Ref | SelectedPortrait Struct.Portrait.Ref | SelectedWeapon Struct.Weapon.Ref diff --git a/src/roster-editor/src/Struct/GlyphBoard.elm b/src/roster-editor/src/Struct/GlyphBoard.elm index a7fa503..9329061 100644 --- a/src/roster-editor/src/Struct/GlyphBoard.elm +++ b/src/roster-editor/src/Struct/GlyphBoard.elm @@ -4,6 +4,7 @@ module Struct.GlyphBoard exposing Ref, get_name, get_id, + get_slots, get_omnimods, get_omnimods_with_glyphs, decoder, @@ -14,6 +15,8 @@ module Struct.GlyphBoard exposing -- Elm ------------------------------------------------------------------------- import Array +import List + import Json.Decode import Json.Decode.Pipeline @@ -47,6 +50,9 @@ get_id g = g.id get_name : Type -> String get_name g = g.name +get_slots : Type -> (List Int) +get_slots g = g.slots + get_omnimods : Type -> Struct.Omnimods.Type get_omnimods g = g.omnimods @@ -55,7 +61,16 @@ get_omnimods_with_glyphs : ( Type -> Struct.Omnimods.Type ) -get_omnimods_with_glyphs glyphs board = board.omnimods +get_omnimods_with_glyphs glyphs board = + (List.foldl + (Struct.Omnimods.merge) + board.omnimods + (List.map2 + (Struct.Omnimods.scale) + (List.map (\e -> ((toFloat e) / 100.0)) board.slots) + (List.map (Struct.Glyph.get_omnimods) (Array.toList glyphs)) + ) + ) decoder : (Json.Decode.Decoder Type) decoder = diff --git a/src/roster-editor/src/Struct/Omnimods.elm b/src/roster-editor/src/Struct/Omnimods.elm index 31ad1ed..68f5233 100644 --- a/src/roster-editor/src/Struct/Omnimods.elm +++ b/src/roster-editor/src/Struct/Omnimods.elm @@ -13,6 +13,7 @@ module Struct.Omnimods exposing get_attack_mods, get_defense_mods, get_all_mods, + scale, decoder ) @@ -77,6 +78,9 @@ merge_mods a_mods b_mods = (Dict.empty) ) +scale_dict_value : Float -> String -> Int -> Int +scale_dict_value modifier entry_name value = + (ceiling ((toFloat value) * modifier)) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -178,6 +182,16 @@ get_attack_damage dmg_modifier atk_omni def_omni = atk_omni.attack ) +scale : Float -> Type -> Type +scale multiplier omnimods = + {omnimods | + attributes = (Dict.map (scale_dict_value multiplier) omnimods.attributes), + statistics = (Dict.map (scale_dict_value multiplier) omnimods.statistics), + attack = (Dict.map (scale_dict_value multiplier) omnimods.attack), + defense = + (Dict.map (scale_dict_value multiplier) omnimods.defense) + } + get_attributes_mods : Type -> (List (String, Int)) get_attributes_mods omnimods = (Dict.toList omnimods.attributes) diff --git a/src/roster-editor/src/Struct/UI.elm b/src/roster-editor/src/Struct/UI.elm index 10b04c6..c128347 100644 --- a/src/roster-editor/src/Struct/UI.elm +++ b/src/roster-editor/src/Struct/UI.elm @@ -9,7 +9,10 @@ module Struct.UI exposing reset_displayed_tab, -- Main or Secondary Weapon? set_is_selecting_main_weapon, - is_selecting_main_weapon + is_selecting_main_weapon, + -- Which glyph slot is being edited? + set_glyph_slot, + get_glyph_slot ) -- Elm ------------------------------------------------------------------------- @@ -25,13 +28,15 @@ type Tab = -- | AccessorySelectionTab | WeaponSelectionTab | ArmorSelectionTab + | GlyphSelectionTab | GlyphBoardSelectionTab | GlyphManagementTab type alias Type = { displayed_tab : Tab, - is_selecting_main_weapon : Bool + is_selecting_main_weapon : Bool, + glyph_slot : Int } -------------------------------------------------------------------------------- @@ -45,7 +50,8 @@ default : Type default = { displayed_tab = CharacterSelectionTab, - is_selecting_main_weapon = False + is_selecting_main_weapon = False, + glyph_slot = -1 } -- Tab ------------------------------------------------------------------------- @@ -63,3 +69,9 @@ set_is_selecting_main_weapon val ui = {ui | is_selecting_main_weapon = val} is_selecting_main_weapon : Type -> Bool is_selecting_main_weapon ui = ui.is_selecting_main_weapon + +get_glyph_slot : Type -> Int +get_glyph_slot ui = ui.glyph_slot + +set_glyph_slot : Int -> Type -> Type +set_glyph_slot tab ui = {ui | glyph_slot = tab} diff --git a/src/roster-editor/src/Update/SetGlyph.elm b/src/roster-editor/src/Update/SetGlyph.elm index c8b979c..3288d18 100644 --- a/src/roster-editor/src/Update/SetGlyph.elm +++ b/src/roster-editor/src/Update/SetGlyph.elm @@ -8,6 +8,7 @@ import Struct.Character import Struct.Event import Struct.Glyph import Struct.Model +import Struct.UI -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- @@ -19,10 +20,9 @@ import Struct.Model apply_to : ( Struct.Model.Type -> Struct.Glyph.Ref -> - Int -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) -apply_to model ref index = +apply_to model ref = ( ( case (model.edited_char, (Dict.get ref model.glyphs)) of @@ -30,7 +30,16 @@ apply_to model ref index = {model | edited_char = (Just - (Struct.Character.set_glyph index glyph char) + (Struct.Character.set_glyph + (Struct.UI.get_glyph_slot model.ui) + glyph + char + ) + ), + ui = + (Struct.UI.set_displayed_tab + Struct.UI.GlyphManagementTab + model.ui ) } diff --git a/src/roster-editor/src/View/CurrentTab.elm b/src/roster-editor/src/View/CurrentTab.elm index 995a5d2..7f0cc2f 100644 --- a/src/roster-editor/src/View/CurrentTab.elm +++ b/src/roster-editor/src/View/CurrentTab.elm @@ -12,6 +12,7 @@ import View.ArmorSelection import View.CharacterSelection import View.GlyphManagement import View.GlyphBoardSelection +import View.GlyphSelection import View.PortraitSelection import View.WeaponSelection @@ -37,6 +38,9 @@ get_html model = Struct.UI.ArmorSelectionTab -> (View.ArmorSelection.get_html model) + Struct.UI.GlyphSelectionTab -> + (View.GlyphSelection.get_html model) + Struct.UI.GlyphBoardSelectionTab -> (View.GlyphBoardSelection.get_html model) diff --git a/src/roster-editor/src/View/GlyphBoardSelection.elm b/src/roster-editor/src/View/GlyphBoardSelection.elm index 756edbf..525ab8d 100644 --- a/src/roster-editor/src/View/GlyphBoardSelection.elm +++ b/src/roster-editor/src/View/GlyphBoardSelection.elm @@ -32,10 +32,7 @@ get_mod_html mod = ] ) -get_glyph_board_html : ( - Struct.GlyphBoard.Type -> - (Html.Html Struct.Event.Type) - ) +get_glyph_board_html : Struct.GlyphBoard.Type -> (Html.Html Struct.Event.Type) get_glyph_board_html glyph_board = (Html.div [ diff --git a/src/roster-editor/src/View/GlyphManagement.elm b/src/roster-editor/src/View/GlyphManagement.elm index bcb8873..c779c7a 100644 --- a/src/roster-editor/src/View/GlyphManagement.elm +++ b/src/roster-editor/src/View/GlyphManagement.elm @@ -1,16 +1,72 @@ module View.GlyphManagement exposing (get_html) -- Elm ------------------------------------------------------------------------- +import Array + import Html import Html.Attributes +import Html.Events -- Roster Editor --------------------------------------------------------------- import Struct.Event +import Struct.Glyph +import Struct.GlyphBoard +import Struct.Omnimods +import Struct.Character 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 ++ ": " ++ (toString value)) + ) + ] + ) + +get_glyph_html : ( + Int -> + (Int, Struct.Glyph.Type) + -> (Html.Html Struct.Event.Type) + ) +get_glyph_html modifier (index, glyph) = + (Html.div + [ + (Html.Attributes.class "character-card-glyph"), + (Html.Attributes.class "clickable"), + (Html.Events.onClick (Struct.Event.ClickedOnGlyph index)) + ] + [ + (Html.text + ( + (Struct.Glyph.get_name glyph) + ++ " (" + ++ (toString modifier) + ++ "%)" + ) + ), + (Html.div + [ + ] + (List.map + (get_mod_html) + (Struct.Omnimods.get_all_mods + (Struct.Glyph.get_omnimods glyph) + ) + ) + ) + ] + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -23,6 +79,22 @@ get_html model = (Html.Attributes.class "glyph-management") ] [ - (Html.text "Glyph Management") + (Html.text "Glyph Management"), + (case model.edited_char of + Nothing -> (Html.div [] [(Html.text "No character selected")]) + (Just char) -> + (Html.div + [ + (Html.Attributes.class "selection-window-listing") + ] + (List.map2 + (get_glyph_html) + (Struct.GlyphBoard.get_slots + (Struct.Character.get_glyph_board char) + ) + (Array.toIndexedList (Struct.Character.get_glyphs char)) + ) + ) + ) ] ) diff --git a/src/roster-editor/src/View/GlyphSelection.elm b/src/roster-editor/src/View/GlyphSelection.elm new file mode 100644 index 0000000..8631a0d --- /dev/null +++ b/src/roster-editor/src/View/GlyphSelection.elm @@ -0,0 +1,84 @@ +module View.GlyphSelection exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import Dict + +import Html +import Html.Attributes +import Html.Events + +-- Roster Editor --------------------------------------------------------------- +import Struct.Event +import Struct.Glyph +import Struct.Omnimods +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 ++ ": " ++ (toString value)) + ) + ] + ) + +get_glyph_html : Struct.Glyph.Type -> (Html.Html Struct.Event.Type) +get_glyph_html glyph = + (Html.div + [ + (Html.Attributes.class "character-card-glyph"), + (Html.Attributes.class "clickable"), + (Html.Events.onClick + (Struct.Event.SelectedGlyph + (Struct.Glyph.get_id glyph) + ) + ) + ] + [ + (Html.text (Struct.Glyph.get_name glyph)), + (Html.div + [ + ] + (List.map + (get_mod_html) + (Struct.Omnimods.get_all_mods + (Struct.Glyph.get_omnimods glyph) + ) + ) + ) + ] + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type) +get_html model = + (Html.div + [ + (Html.Attributes.class "selection-window"), + (Html.Attributes.class "glyph-management") + ] + [ + (Html.text "Glyph Selection"), + (Html.div + [ + (Html.Attributes.class "selection-window-listing") + ] + (List.map + (get_glyph_html) + (Dict.values model.glyphs) + ) + ) + ] + ) -- cgit v1.2.3-70-g09d2