summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-03-22 19:02:58 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-03-22 19:02:58 +0100 |
commit | caf0e9497229abb56a7428e60b19ee3d05fa7e9c (patch) | |
tree | 21272443e733fb9396947f969e01cfe85e6481bd /src/roster-editor | |
parent | 397e54affd6d434ea5d055f34cbac637867cde0a (diff) |
[Broken] More factoring in progress...
Diffstat (limited to 'src/roster-editor')
-rw-r--r-- | src/roster-editor/src/Struct/Character.elm | 146 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Glyph.elm | 66 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/GlyphBoard.elm | 100 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Inventory.elm | 80 | ||||
-rw-r--r-- | src/roster-editor/src/View/Character.elm | 91 | ||||
-rw-r--r-- | src/roster-editor/src/View/CharacterCard.elm | 4 |
6 files changed, 113 insertions, 374 deletions
diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm index e6ef776..2b64322 100644 --- a/src/roster-editor/src/Struct/Character.elm +++ b/src/roster-editor/src/Struct/Character.elm @@ -7,29 +7,18 @@ module Struct.Character exposing set_battle_index, get_name, set_name, - get_portrait, - set_portrait, - get_armor, - set_armor, + get_equipment, + set_equipment, get_current_omnimods, get_attributes, get_statistics, - get_primary_weapon, - set_primary_weapon, - get_secondary_weapon, - set_secondary_weapon, get_is_using_secondary, - get_glyph_board, - set_glyph_board, - get_glyphs, - set_glyph, set_was_edited, get_was_edited, switch_weapons ) -- Elm ------------------------------------------------------------------------- -import Array -- Battle ---------------------------------------------------------------------- import Battle.Struct.Omnimods @@ -38,12 +27,9 @@ import Battle.Struct.Statistics -- Battle Characters ----------------------------------------------------------- import BattleCharacters.Struct.Armor -import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Equipment import BattleCharacters.Struct.Weapon - --- Local Module ---------------------------------------------------------------- -import Struct.Glyph -import Struct.GlyphBoard +import BattleCharacters.Struct.GlyphBoard -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -53,15 +39,10 @@ type alias Type = ix : Int, battle_ix : Int, name : String, - portrait : BattleCharacters.Struct.Portrait.Type, + equipment : BattleCharacters.Struct.Equipment, attributes : Battle.Struct.Attributes.Type, statistics : Battle.Struct.Statistics.Type, - primary_weapon : BattleCharacters.Struct.Weapon.Type, - secondary_weapon : BattleCharacters.Struct.Weapon.Type, is_using_secondary : Bool, - armor : BattleCharacters.Struct.Armor.Type, - glyph_board : Struct.GlyphBoard.Type, - glyphs : (Array.Array Struct.Glyph.Type), current_omnimods : Battle.Struct.Omnimods.Type, was_edited : Bool } @@ -72,21 +53,28 @@ type alias Type = refresh_omnimods : Type -> Type refresh_omnimods char = let + equipment = char.equipment current_omnimods = (Battle.Struct.Omnimods.merge (Battle.Struct.Omnimods.merge (BattleCharacters.Struct.Weapon.get_omnimods ( if (char.is_using_secondary) - then char.secondary_weapon - else char.primary_weapon + then + (BattleCharacters.Struct.Equipment.get_secondary_weapon + equipment + ) + else + (BattleCharacters.Struct.Equipment.get_primary_weapon + equipment + ) ) ) (BattleCharacters.Struct.Armor.get_omnimods char.armor) ) - (Struct.GlyphBoard.get_omnimods_with_glyphs - char.glyphs - char.glyph_board + (BattleCharacters.Struct.GlyphBoard.get_omnimods_with_glyphs + (BattleCharacters.Struct.Equipment.get_glyphs equipment) + (BattleCharacters.Struct.Equipment.get_glyph_board equipment) ) ) current_attributes = @@ -113,66 +101,21 @@ refresh_omnimods char = new : ( Int -> String -> - (Maybe BattleCharacters.Struct.Portrait.Type) -> - (Maybe BattleCharacters.Struct.Weapon.Type) -> - (Maybe BattleCharacters.Struct.Weapon.Type) -> - (Maybe BattleCharacters.Struct.Armor.Type) -> - (Maybe Struct.GlyphBoard.Type) -> - (List (Maybe Struct.Glyph.Type)) -> + BattleCharacters.Struct.Equipment.Type -> Type ) -new index name m_portrait m_main_wp m_sec_wp m_armor m_board m_glyphs = +new index name equipment = (refresh_omnimods { ix = index, battle_ix = -1, name = name, - portrait = - ( - case m_portrait of - (Just portrait) -> portrait - Nothing -> (BattleCharacters.Struct.Portrait.default) - ), + equipment = equipment, attributes = (Battle.Struct.Attributes.default), statistics = (Battle.Struct.Statistics.new_raw (Battle.Struct.Attributes.default) ), - primary_weapon = - ( - case m_main_wp of - (Just w) -> w - Nothing -> (BattleCharacters.Struct.Weapon.default) - ), - secondary_weapon = - ( - case m_sec_wp of - (Just w) -> w - Nothing -> (BattleCharacters.Struct.Weapon.default) - ), - armor = - ( - case m_armor of - (Just armor) -> armor - Nothing -> (BattleCharacters.Struct.Armor.default) - ), - glyph_board = - ( - case m_board of - (Just board) -> board - Nothing -> (Struct.GlyphBoard.default) - ), - glyphs = - (Array.fromList - (List.map - (\m_g -> - case m_g of - (Just g) -> g - Nothing -> (Struct.Glyph.default) - ) - m_glyphs - ) - ), is_using_secondary = False, current_omnimods = (Battle.Struct.Omnimods.none), was_edited = False @@ -194,11 +137,11 @@ get_name c = c.name set_name : String -> Type -> Type set_name name char = {char | name = name} -get_portrait : Type -> BattleCharacters.Struct.Portrait.Type -get_portrait c = c.portrait +get_equipment : Type -> BattleCharacters.Struct.Equipment.Type +get_equipment c = c.equipment -set_portrait : BattleCharacters.Struct.Portrait.Type -> Type -> Type -set_portrait portrait char = {char | portrait = portrait} +set_equipment : BattleCharacters.Struct.Equipment.Type -> Type -> Type +set_equipment equipment char = (refresh_omnimods {char | equipment = equipment}) get_current_omnimods : Type -> Battle.Struct.Omnimods.Type get_current_omnimods c = c.current_omnimods @@ -209,50 +152,9 @@ get_attributes char = char.attributes get_statistics : Type -> Battle.Struct.Statistics.Type get_statistics char = char.statistics -get_primary_weapon : Type -> BattleCharacters.Struct.Weapon.Type -get_primary_weapon char = char.primary_weapon - -set_primary_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type -set_primary_weapon wp char = (refresh_omnimods {char | primary_weapon = wp}) - -get_secondary_weapon : Type -> BattleCharacters.Struct.Weapon.Type -get_secondary_weapon char = char.secondary_weapon - -set_secondary_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type -set_secondary_weapon wp char = (refresh_omnimods {char | secondary_weapon = wp}) - get_is_using_secondary : Type -> Bool get_is_using_secondary char = char.is_using_secondary -get_armor : Type -> BattleCharacters.Struct.Armor.Type -get_armor char = char.armor - -set_armor : BattleCharacters.Struct.Armor.Type -> Type -> Type -set_armor armor char = (refresh_omnimods {char | armor = armor}) - -get_glyph_board : Type -> Struct.GlyphBoard.Type -get_glyph_board char = char.glyph_board - -set_glyph_board : Struct.GlyphBoard.Type -> Type -> Type -set_glyph_board glyph_board char = - (refresh_omnimods - {char | - glyph_board = glyph_board, - glyphs = - (Array.repeat - (List.length (Struct.GlyphBoard.get_slots glyph_board)) - (Struct.Glyph.none) - ) - } - ) - -get_glyphs : Type -> (Array.Array Struct.Glyph.Type) -get_glyphs char = char.glyphs - -set_glyph : Int -> Struct.Glyph.Type -> Type -> Type -set_glyph index glyph char = - (refresh_omnimods {char | glyphs = (Array.set index glyph char.glyphs)}) - get_was_edited : Type -> Bool get_was_edited char = char.was_edited diff --git a/src/roster-editor/src/Struct/Glyph.elm b/src/roster-editor/src/Struct/Glyph.elm deleted file mode 100644 index f871d35..0000000 --- a/src/roster-editor/src/Struct/Glyph.elm +++ /dev/null @@ -1,66 +0,0 @@ -module Struct.Glyph exposing - ( - Type, - Ref, - get_name, - get_id, - get_omnimods, - none, - default, - decoder - ) - --- Elm ------------------------------------------------------------------------- -import Json.Decode -import Json.Decode.Pipeline - --- Battle ---------------------------------------------------------------------- -import Battle.Struct.Omnimods - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type alias Type = - { - id : String, - name : String, - omnimods : Battle.Struct.Omnimods.Type - } - -type alias Ref = String - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_id : Type -> String -get_id g = g.id - -get_name : Type -> String -get_name g = g.name - -get_omnimods : Type -> Battle.Struct.Omnimods.Type -get_omnimods g = g.omnimods - -decoder : (Json.Decode.Decoder Type) -decoder = - (Json.Decode.succeed - Type - |> (Json.Decode.Pipeline.required "id" Json.Decode.string) - |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) - |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder) - ) - -none : Type -none = - { - id = "0", - name = "Empty", - omnimods = (Battle.Struct.Omnimods.none) - } - -default : Type -default = (none) diff --git a/src/roster-editor/src/Struct/GlyphBoard.elm b/src/roster-editor/src/Struct/GlyphBoard.elm deleted file mode 100644 index fc848e4..0000000 --- a/src/roster-editor/src/Struct/GlyphBoard.elm +++ /dev/null @@ -1,100 +0,0 @@ -module Struct.GlyphBoard exposing - ( - Type, - Ref, - get_name, - get_id, - get_slots, - get_omnimods, - get_omnimods_with_glyphs, - decoder, - none, - default - ) - --- Elm ------------------------------------------------------------------------- -import Array - -import List - -import Json.Decode -import Json.Decode.Pipeline - --- Battle ---------------------------------------------------------------------- -import Battle.Struct.Omnimods - --- Local Module ---------------------------------------------------------------- -import Struct.Glyph - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type alias Type = - { - id : String, - name : String, - slots : (List Int), - omnimods : Battle.Struct.Omnimods.Type - } - -type alias Ref = String - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_id : Type -> String -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 -> Battle.Struct.Omnimods.Type -get_omnimods g = g.omnimods - -get_omnimods_with_glyphs : ( - (Array.Array Struct.Glyph.Type) -> - Type -> - Battle.Struct.Omnimods.Type - ) -get_omnimods_with_glyphs glyphs board = - (List.foldl - (Battle.Struct.Omnimods.merge) - board.omnimods - (List.map2 - (Battle.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 = - (Json.Decode.succeed - Type - |> (Json.Decode.Pipeline.required "id" Json.Decode.string) - |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) - |> (Json.Decode.Pipeline.required - "slot" - (Json.Decode.list (Json.Decode.int)) - ) - |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder) - ) - -none : Type -none = - { - id = "", - name = "None", - slots = [], - omnimods = (Battle.Struct.Omnimods.none) - } - -default : Type -default = (none) diff --git a/src/roster-editor/src/Struct/Inventory.elm b/src/roster-editor/src/Struct/Inventory.elm index aa0cbeb..063c3ce 100644 --- a/src/roster-editor/src/Struct/Inventory.elm +++ b/src/roster-editor/src/Struct/Inventory.elm @@ -6,26 +6,37 @@ module Struct.Inventory exposing has_glyph_board, has_weapon, has_armor, + allows, empty, decoder ) -- Elm ------------------------------------------------------------------------- +import Array + import Json.Decode import Json.Decode.Pipeline import Set +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Armor +import BattleCharacters.Struct.Equipment +import BattleCharacters.Struct.Glyph +import BattleCharacters.Struct.GlyphBoard +import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Weapon + -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type alias Type = { - portraits : (Set.Set Int), - glyphs : (Set.Set Int), - glyph_boards : (Set.Set Int), - weapons : (Set.Set Int), - armors : (Set.Set Int) + portraits : (Set.Set BattleCharacters.Struct.Portrait.Ref), + glyphs : (Set.Set BattleCharacters.Struct.Glyph.Ref), + glyph_boards : (Set.Set BattleCharacters.Struct.GlyphBoard.Ref), + weapons : (Set.Set BattleCharacters.Struct.Weapon.Ref), + armors : (Set.Set BattleCharacters.Struct.Armor.Ref) } -------------------------------------------------------------------------------- @@ -35,20 +46,59 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -has_portrait : Int -> Type -> Bool -has_portrait id inv = (Set.member id inv.portraits) +has_portrait : Type -> BattleCharacters.Struct.Portrait.Ref -> Bool +has_portrait inv id = (Set.member id inv.portraits) -has_glyph : Int -> Type -> Bool -has_glyph id inv = (Set.member id inv.glyphs) +has_glyph : Type -> BattleCharacters.Struct.Glyph.Ref -> Bool +has_glyph inv id = (Set.member id inv.glyphs) -has_glyph_board : Int -> Type -> Bool -has_glyph_board id inv = (Set.member id inv.glyph_boards) +has_glyph_board : Type -> BattleCharacters.Struct.GlyphBoard.Ref -> Bool +has_glyph_board inv id = (Set.member id inv.glyph_boards) -has_weapon : Int -> Type -> Bool -has_weapon id inv = (Set.member id inv.weapons) +has_weapon : Type -> BattleCharacters.Struct.Weapon.Ref -> Bool +has_weapon inv id = (Set.member id inv.weapons) -has_armor : Int -> Type -> Bool -has_armor id inv = (Set.member id inv.armors) +has_armor : Type -> BattleCharacters.Struct.Armor.Ref -> Bool +has_armor inv id = (Set.member id inv.armors) + +allows : Type -> BattleCharacters.Struct.Equipment.Type -> Bool +allows inv equipment = + (and + (has_weapon + inv + (BattleCharacters.Struct.Weapon.get_id + (BattleCharacters.Struct.Equipment.get_primary_weapon equipment) + ) + ) + (has_weapon + inv + (BattleCharacters.Struct.Weapon.get_id + (BattleCharacters.Struct.Equipment.get_secondary_weapon equipment) + ) + ) + (has_armor + inv + (BattleCharacters.Struct.Armor.get_id + (BattleCharacters.Struct.Equipment.get_armor equipment) + ) + ) + (has_portrait + inv + (BattleCharacters.Struct.Portrait.get_id + (BattleCharacters.Struct.Equipment.get_portrait equipment) + ) + ) + (has_glyph_board + inv + (BattleCharacters.Struct.GlyphBoard.get_id + (BattleCharacters.Struct.Equipment.get_glyph_board equipment) + ) + ) + (List.all + ((BattleCharacters.Struct.Glyph.get_id) |> (has_glyph inv)) + (Array.toList (BattleCharacters.Struct.Equipment.get_glyphs equipment)) + ) + ) empty : Type empty = diff --git a/src/roster-editor/src/View/Character.elm b/src/roster-editor/src/View/Character.elm index abfa557..a19b448 100644 --- a/src/roster-editor/src/View/Character.elm +++ b/src/roster-editor/src/View/Character.elm @@ -16,6 +16,8 @@ import Util.Html import BattleCharacters.Struct.Armor import BattleCharacters.Struct.Portrait +import BattleCharacters.View.Portrait + -- Local Module ---------------------------------------------------------------- import Struct.Character import Struct.Event @@ -53,53 +55,6 @@ get_icon_head_html char = ] ) -get_portrait_body_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) -get_portrait_body_html char = - (Html.div - [ - (Html.Attributes.class "character-portrait-body"), - (Html.Attributes.class - ( - "asset-character-portrait-" - ++ - (BattleCharacters.Struct.Portrait.get_id - (Struct.Character.get_portrait char) - ) - ) - ) - ] - [ - ] - ) - -get_portrait_armor_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) -get_portrait_armor_html char = - (Html.div - [ - (Html.Attributes.class "character-portrait-armor"), - (Html.Attributes.class - ( - "asset-armor-" - ++ - (BattleCharacters.Struct.Armor.get_image_id - (Struct.Character.get_armor char) - ) - ) - ), - (Html.Attributes.class - ( - "asset-armor-variation-" - ++ - (BattleCharacters.Struct.Portrait.get_body_id - (Struct.Character.get_portrait char) - ) - ) - ) - ] - [ - ] - ) - get_battle_index_html : Struct.Character.Type -> (Html.Html Struct.Event.Type) get_battle_index_html char = let battle_ix = (Struct.Character.get_battle_index char) in @@ -121,33 +76,31 @@ get_battle_index_html char = -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- get_portrait_html : ( - Struct.Character.Type -> Bool -> + Struct.Character.Type -> (Html.Html Struct.Event.Type) ) -get_portrait_html char click_to_toggle = +get_portrait_html click_to_toggle char = (Html.div - ( - [ - (Html.Attributes.class "character-portrait"), - (Html.Attributes.class "character-portrait-team-0") - ] - ++ - if (click_to_toggle) - then - [ - (Html.Events.onClick - (Struct.Event.ToggleCharacterBattleIndex - (Struct.Character.get_index char) - ) - ) - ] - else - [] - ) + [] [ - (get_portrait_body_html char), - (get_portrait_armor_html char), + (BattleCharacters.View.Portrait.get_html + ( + if (click_to_toggle) + then + [ + (Html.Events.onClick + (Struct.Event.ToggleCharacterBattleIndex + (Struct.Character.get_index char) + ) + ), + (Html.Attributes.class "character-portrait-team-0") + ] + else + [(Html.Attributes.class "character-portrait-team-0")] + ) + char + ), (get_battle_index_html char) ] ) diff --git a/src/roster-editor/src/View/CharacterCard.elm b/src/roster-editor/src/View/CharacterCard.elm index 0ddc2e6..10d35dd 100644 --- a/src/roster-editor/src/View/CharacterCard.elm +++ b/src/roster-editor/src/View/CharacterCard.elm @@ -462,7 +462,7 @@ get_minimal_html char = (Html.Attributes.class "info-card-picture") ] [ - (View.Character.get_portrait_html char True) + (View.Character.get_portrait_html True char) ] ), (get_health_bar char), @@ -508,7 +508,7 @@ get_full_html char = ) ] [ - (View.Character.get_portrait_html char False) + (View.Character.get_portrait_html False char) ] ), (get_health_bar char), |