summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-03-15 18:16:55 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-03-15 18:16:55 +0100 |
commit | 6678cfe464ed9ee595f4f3dd7398dec1416454c9 (patch) | |
tree | 2700668874e13a81ec7467dcf26a1d246caa23ff /src/shared/battle-characters | |
parent | 24efb898f526e0aa02a0e15b74436da8ba166cac (diff) |
[Broken] Starting a code refactoring...
Diffstat (limited to 'src/shared/battle-characters')
4 files changed, 263 insertions, 0 deletions
diff --git a/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm b/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm new file mode 100644 index 0000000..a9c848b --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Comm/AddPortrait.elm @@ -0,0 +1,24 @@ +module Comm.AddPortrait exposing (decode) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode + +-- BattleCharacters ------------------------------------------------------------ +import Struct.Portrait +import Struct.ServerReply + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +internal_decoder : Struct.Portrait.Type -> Struct.ServerReply.Type +internal_decoder pt = (Struct.ServerReply.AddPortrait pt) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decode : (Json.Decode.Decoder Struct.ServerReply.Type) +decode = (Json.Decode.map (internal_decoder) (Struct.Portrait.decoder)) diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm b/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm new file mode 100644 index 0000000..5cb99d6 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Armor.elm @@ -0,0 +1,74 @@ +module BattleCharacters.Struct.Armor exposing + ( + Type, + Ref, + new, + get_id, + get_name, + get_image_id, + get_omnimods, + decoder, + default, + none + ) + +-- 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 -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : String -> String -> Battle.Struct.Omnimods.Type -> Type +new id name omnimods = + { + id = id, + name = name, + omnimods = omnimods + } + +get_id : Type -> Ref +get_id ar = ar.id + +get_name : Type -> String +get_name ar = ar.name + +get_image_id : Type -> String +get_image_id ar = ar.id + +get_omnimods : Type -> Battle.Struct.Omnimods.Type +get_omnimods ar = ar.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 = (new "0" "None" (Battle.Struct.Omnimods.none)) + +default : Type +default = (none) diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm b/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm new file mode 100644 index 0000000..35f5260 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Portrait.elm @@ -0,0 +1,66 @@ +module BattleCharacters.Struct.Portrait exposing + ( + Type, + Ref, + default, + get_id, + get_name, + get_body_id, + get_icon_id, + decoder + ) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode +import Json.Decode.Pipeline + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + id : String, + name : String, + body_id : String, + icon_id : String + } + +type alias Ref = String + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +default : Type +default = + { + id = "cat", + name = "Black Cat", + body_id = "mammal", + icon_id = "cat" + } + +get_id : Type -> String +get_id p = p.id + +get_name : Type -> String +get_name p = p.name + +get_body_id : Type -> String +get_body_id p = p.body_id + +get_icon_id : Type -> String +get_icon_id p = p.icon_id + +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 "bid" Json.Decode.string) + |> (Json.Decode.Pipeline.required "iid" Json.Decode.string) + ) diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm b/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm new file mode 100644 index 0000000..0aff932 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Struct/Weapon.elm @@ -0,0 +1,99 @@ +module BattleCharacters.Struct.Weapon exposing + ( + Type, + Ref, + get_id, + get_name, + get_is_primary, + get_attack_range, + get_defense_range, + get_omnimods, + get_damage_sum, + decoder, + default, + none + ) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode +import Json.Decode.Pipeline + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Omnimods + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + id : String, + name : String, + is_primary : Bool, + def_range : Int, + atk_range : Int, + omnimods : Battle.Struct.Omnimods.Type, + damage_sum : Int + } + +type alias Ref = String + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_id : Type -> String +get_id wp = wp.id + +get_name : Type -> String +get_name wp = wp.name + +get_is_primary : Type -> Bool +get_is_primary wp = wp.is_primary + +get_attack_range : Type -> Int +get_attack_range wp = wp.atk_range + +get_defense_range : Type -> Int +get_defense_range wp = wp.def_range + +get_omnimods : Type -> Battle.Struct.Omnimods.Type +get_omnimods wp = wp.omnimods + +get_damage_sum : Type -> Int +get_damage_sum wp = wp.damage_sum + +decoder : (Json.Decode.Decoder Type) +decoder = + (Json.Decode.map + (\e -> + {e | damage_sum = (Battle.Struct.Omnimods.get_damage_sum e.omnimods)} + ) + (Json.Decode.succeed + Type + |> (Json.Decode.Pipeline.required "id" Json.Decode.string) + |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) + |> (Json.Decode.Pipeline.required "pri" Json.Decode.bool) + |> (Json.Decode.Pipeline.required "rmi" Json.Decode.int) + |> (Json.Decode.Pipeline.required "rma" Json.Decode.int) + |> (Json.Decode.Pipeline.required "omni" Battle.Struct.Omnimods.decoder) + |> (Json.Decode.Pipeline.hardcoded 0) + ) + ) + +none : Type +none = + { + id = "", + name = "None", + is_primary = False, + def_range = 0, + atk_range = 0, + omnimods = (Battle.Struct.Omnimods.none), + damage_sum = 0 + } + +default : Type +default = (none) |