| 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/shared | |
| parent | 397e54affd6d434ea5d055f34cbac637867cde0a (diff) | |
[Broken] More factoring in progress...
Diffstat (limited to 'src/shared')
4 files changed, 459 insertions, 0 deletions
| diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm b/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm new file mode 100644 index 0000000..8782397 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Equipment.elm @@ -0,0 +1,192 @@ +module BattleCharacters.Struct.Equipment exposing +   ( +      get_primary_weapon, +      get_secondary_weapon, +      get_armor, +      get_portrait, +      get_glyph_board, +      get_glyphs, +      set_primary_weapon, +      set_secondary_weapon, +      set_armor, +      set_portrait, +      set_glyph_board, +      set_glyphs, +      set_glyph, +      ref_decoder, +      ref_encoder, +      resolve, +      to_ref +   ) + +-- Elm ------------------------------------------------------------------------- +import Array + +import List + +import Json.Decode +import Json.Decode.Pipeline + +import Json.Encode + +-- Battle ---------------------------------------------------------------------- +import BattleCharacters.Struct.Weapon +import BattleCharacters.Struct.Armor +import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Glyph +import BattleCharacters.Struct.GlyphBoard + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = +   { +      primary : BattleCharacters.Struct.Weapon.Type, +      secondary : BattleCharacters.Struct.Weapon.Type, +      armor : BattleCharacters.Struct.Armor.Type, +      portrait : BattleCharacters.Struct.Portrait.Type, +      glyph_board : BattleCharacters.Struct.GlyphBoard.Type, +      glyphs : (Array.Array BattleCharacters.Struct.Glyph.Type) +   } + +type alias Ref = +   { +      primary : BattleCharacters.Struct.Weapon.Ref, +      secondary : BattleCharacters.Struct.Weapon.Ref, +      armor : BattleCharacters.Struct.Armor.Ref, +      portrait : BattleCharacters.Struct.Portrait.Ref, +      glyph_board : BattleCharacters.Struct.GlyphBoard.Ref, +      glyphs : (Array.Array BattleCharacters.Struct.Glyph.Ref) +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_primary_weapon : Type -> BattleCharacters.Struct.Weapon.Type +get_primary_weapon equipment = equipment.primary + +get_secondary_weapon : Type -> BattleCharacters.Struct.Weapon.Type +get_secondary_weapon equipment = equipment.secondary + +get_armor : Type -> BattleCharacters.Struct.Armor.Type +get_armor equipment = equipment.armor + +get_portrait : Type -> BattleCharacters.Struct.Portrait.Type +get_portrait equipment = equipment.portrait + +get_glyph_board : Type -> BattleCharacters.Struct.GlyphBoard.Type +get_glyph_board equipment = equipment.glyph_board + +get_glyphs : Type -> (Array.Array BattleCharacters.Struct.Glyph.Type) +get_glyphs equipment = equipment.glyphs + +set_primary_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type +set_primary_weapon wp equipment = { equipment | primary = wp } + +set_secondary_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type +set_secondary_weapon wp equipment = { equipment | secondary = wp } + +set_armor : BattleCharacters.Struct.Armor.Type -> Type -> Type +set_armor ar equipment = { equipment | armor = ar } + +set_portrait : BattleCharacters.Struct.Portrait.Type -> Type -> Type +set_portrait pt equipment = { equipment | portrait = pt } + +set_glyph_board : BattleCharacters.Struct.GlyphBoard.Type -> Type -> Type +set_glyph_board gb equipment = +   {equipment | +      glyph_board = gb, +      glyphs = +         (Array.repeat +            (List.length (BattleCharacters.Struct.GlyphBoard.get_slots gb)) +            (BattleCharacters.Struct.Glyph.none) +         ) +   } + +set_glyphs : (Array.Array BattleCharacters.Struct.Glyph.Type) -> Type -> Type +set_glyphs gl equipment = { equipment | glyphs = gl } + +set_glyph : Int -> BattleCharacters.Struct.Glyph.Type -> Type -> Type +set_glyph index glyph equipment = +   { equipment | glyphs = (Array.set index glyph equipment.glyphs) } + +ref_decoder : (Json.Decode.Decoder Type) +ref_decoder = +   (Json.Decode.succeed +      Ref +      |> (Json.Decode.Pipeline.required "pr" Json.Decode.string) +      |> (Json.Decode.Pipeline.required "sc" Json.Decode.string) +      |> (Json.Decode.Pipeline.required "ar" Json.Decode.string) +      |> (Json.Decode.Pipeline.required "pt" Json.Decode.string) +      |> (Json.Decode.Pipeline.required "gb" Json.Decode.string) +      |> +         (Json.Decode.Pipeline.required +            "gl" +            (Json.Decode.array (Json.Decode.string)) +         ) +   ) + +ref_encoder : Ref -> Json.Encode.Value +ref_encoder ref = +   (Json.Encode.object +      [ +         ("pr", (Json.Encode.string ref.primary)), +         ("sc", (Json.Encode.string ref.secondary)), +         ("ar", (Json.Encode.string ref.armor)), +         ("pt", (Json.Encode.string ref.portrait)), +         ("gb", (Json.Encode.string ref.glyph_board)), +         ("gl", (Json.Encode.array (Array.map (Json.Encode.string) ref.gl))) +      ] +   ) + +resolve : ( +      ( +         BattleCharacters.Struct.Weapon.Ref -> +         BattleCharacters.Struct.Weapon.Type +      ) -> +      ( +         BattleCharacters.Struct.Armor.Ref -> +         BattleCharacters.Struct.Armor.Type +      ) -> +      ( +         BattleCharacters.Struct.Portrait.Ref -> +         BattleCharacters.Struct.Portrait.Type +      ) -> +      ( +         BattleCharacters.Struct.GlyphBoard.Ref -> +         BattleCharacters.Struct.GlyphBoard.Type +      ) -> +      ( +         BattleCharacters.Struct.Glyph.Ref -> +         BattleCharacters.Struct.Glyph.Type +      ) -> +      Ref -> +      Type +   ) +resolve resolve_wp resolve_ar resolve_pt resolve_gb resolve_gl ref = +   { +      primary = (resolve_wp ref.primary), +      secondary = (resolve_wp ref.secondary), +      armor = (resolve_ar ref.armor), +      portrait = (resolve_pt ref.portrait), +      glyph_board = (resolve_gb ref.glyph_board), +      glyphs = (Array.map (resolve_gl) ref.glyphs) +   } + +to_ref : Type -> Ref +to_ref equipment = +   { +      primary = (BattleCharacters.Struct.Weapon.get_id equipment.primary), +      secondary = (BattleCharacters.Struct.Weapon.get_id equipment.secondary), +      armor = (BattleCharacters.Struct.Armor.get_id equipment.armor), +      portrait = (BattleCharacters.Struct.Portrait.get_id equipment.portrait), +      glyph_board = +         (BattleCharacters.Struct.GlyphBoard.get_id equipment.glyph_board), +      glyphs = +         (Array.map (BattleCharacters.Struct.Glyph.get_id) equipment.glyphs) +   } + diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm b/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm new file mode 100644 index 0000000..c277b20 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Glyph.elm @@ -0,0 +1,66 @@ +module BattleCharacters.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/shared/battle-characters/BattleCharacters/Struct/GlyphBoard.elm b/src/shared/battle-characters/BattleCharacters/Struct/GlyphBoard.elm new file mode 100644 index 0000000..7d08ec0 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/GlyphBoard.elm @@ -0,0 +1,102 @@ +module BattleCharacters.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 + +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.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 BattleCharacters.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 +            (BattleCharacters.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/shared/battle-characters/BattleCharacters/View/Portrait.elm b/src/shared/battle-characters/BattleCharacters/View/Portrait.elm new file mode 100644 index 0000000..50c5c4c --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/View/Portrait.elm @@ -0,0 +1,99 @@ +module BattleCharacters.View.Portrait exposing +   ( +      get_html +   ) + +-- Elm ------------------------------------------------------------------------- +import Html +import Html.Attributes +import Html.Events + +-- Shared ---------------------------------------------------------------------- +import Util.Html + +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Armor +import BattleCharacters.Struct.Equipment +import BattleCharacters.Struct.Portrait + +-- Local Module ---------------------------------------------------------------- +import Struct.Event + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_portrait_body_html : ( +      BattleCharacters.Struct.Equipment.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_portrait_body_html equipment = +   (Html.div +      [ +         (Html.Attributes.class "character-portrait-body"), +         (Html.Attributes.class +            ( +               "asset-character-portrait-" +               ++ +               (BattleCharacters.Struct.Portrait.get_id +                  (BattleCharacters.Struct.Equipment.get_portrait equipment) +               ) +            ) +         ) +      ] +      [ +      ] +   ) + +get_portrait_armor_html : ( +      BattleCharacters.Struct.Equipment.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_portrait_armor_html equipment = +   (Html.div +      [ +         (Html.Attributes.class "character-portrait-armor"), +         (Html.Attributes.class +            ( +               "asset-armor-" +               ++ +               (BattleCharacters.Struct.Armor.get_image_id +                  (BattleCharacters.Equipment.get_armor equipment) +               ) +            ) +         ), +         (Html.Attributes.class +            ( +               "asset-armor-variation-" +               ++ +               (BattleCharacters.Struct.Portrait.get_body_id +                  (BattleCharacters.Struct.Equipment.get_portrait equipment) +               ) +            ) +         ) +      ] +      [ +      ] +   ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : ( +      (List (Html.Attribute Struct.Event.Type)) -> +      BattleCharacters.Equipment.Type -> +      (Html.Html Struct.Event.Type) +   ) +get_html extra_attributes equipment = +   (Html.div +      ( +         [ +            (Html.Attributes.class "character-portrait") +         ] +         ++ +         extra_attributes +      ) +      [ +         (get_portrait_body_html equipment), +         (get_portrait_armor_html equipment) +      ] +   ) | 


