From caf0e9497229abb56a7428e60b19ee3d05fa7e9c Mon Sep 17 00:00:00 2001 From: nsensfel Date: Fri, 22 Mar 2019 19:02:58 +0100 Subject: [Broken] More factoring in progress... --- .../BattleCharacters/Struct/GlyphBoard.elm | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/shared/battle-characters/BattleCharacters/Struct/GlyphBoard.elm (limited to 'src/shared/battle-characters/BattleCharacters/Struct/GlyphBoard.elm') 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) -- cgit v1.2.3-70-g09d2