|
@@ -1,9 +1,9 @@
|
|
|
module Database exposing (Database, decode, decoder, encode, fromCardData, get, getAll)
|
|
module Database exposing (Database, decode, decoder, encode, fromCardData, get, getAll)
|
|
|
|
|
|
|
|
-import Card exposing (CardData, CardDetails, CardPerformanceData, CardType(..), ManaColor(..), Power(..), parseManaCost)
|
|
|
|
|
|
|
+import Card exposing (CardData, CardDetails, CardPerformanceData, CardType(..), ManaColor(..), Power(..), parseManaCost, parsePower)
|
|
|
import Dict exposing (Dict)
|
|
import Dict exposing (Dict)
|
|
|
import Json.Decode as Decode exposing (Decoder, decodeString)
|
|
import Json.Decode as Decode exposing (Decoder, decodeString)
|
|
|
-import Json.Decode.Pipeline exposing (optional, required)
|
|
|
|
|
|
|
+import Json.Decode.Pipeline exposing (custom, optional, required)
|
|
|
import Json.Encode as Encode
|
|
import Json.Encode as Encode
|
|
|
import Tuple exposing (pair)
|
|
import Tuple exposing (pair)
|
|
|
|
|
|
|
@@ -122,10 +122,20 @@ decodeCardPerformance =
|
|
|
|> required "ATA" decodeMaybeFloatString
|
|
|> required "ATA" decodeMaybeFloatString
|
|
|
|> required "ALSA" decodeMaybeFloatString
|
|
|> required "ALSA" decodeMaybeFloatString
|
|
|
|> required "GIH WR" decodeMaybePercentageString
|
|
|> required "GIH WR" decodeMaybePercentageString
|
|
|
- |> required "IWD" decodeImprovementWhenDrawn
|
|
|
|
|
|
|
+ -- The improvement when drawn changed to improvement in hand in newer set data
|
|
|
|
|
+ -- from 17lands
|
|
|
|
|
+ |> custom decodeIIHOrIWD
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+decodeIIHOrIWD : Decoder (Maybe Float)
|
|
|
|
|
+decodeIIHOrIWD =
|
|
|
|
|
+ Decode.oneOf
|
|
|
|
|
+ [ Decode.at [ "IIH" ] decodeImprovementWhenDrawn
|
|
|
|
|
+ , Decode.at [ "IWD" ] decodeImprovementWhenDrawn
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
decodeImprovementWhenDrawn : Decoder (Maybe Float)
|
|
decodeImprovementWhenDrawn : Decoder (Maybe Float)
|
|
|
decodeImprovementWhenDrawn =
|
|
decodeImprovementWhenDrawn =
|
|
|
Decode.string
|
|
Decode.string
|
|
@@ -277,6 +287,9 @@ encodePower p =
|
|
|
Just (ConstantPower i) ->
|
|
Just (ConstantPower i) ->
|
|
|
Encode.string (String.fromInt i)
|
|
Encode.string (String.fromInt i)
|
|
|
|
|
|
|
|
|
|
+ Just (ConstantPlusVariablePower i) ->
|
|
|
|
|
+ Encode.string (String.fromInt i ++ "+*")
|
|
|
|
|
+
|
|
|
Just VariablePower ->
|
|
Just VariablePower ->
|
|
|
Encode.string "*"
|
|
Encode.string "*"
|
|
|
|
|
|
|
@@ -289,16 +302,12 @@ decodePower =
|
|
|
Decode.string
|
|
Decode.string
|
|
|
|> Decode.andThen
|
|
|> Decode.andThen
|
|
|
(\s ->
|
|
(\s ->
|
|
|
- if s == "*" then
|
|
|
|
|
- Decode.succeed VariablePower
|
|
|
|
|
|
|
+ case parsePower s of
|
|
|
|
|
+ Just p ->
|
|
|
|
|
+ Decode.succeed p
|
|
|
|
|
|
|
|
- else
|
|
|
|
|
- case String.toInt s of
|
|
|
|
|
- Just i ->
|
|
|
|
|
- Decode.succeed (ConstantPower i)
|
|
|
|
|
-
|
|
|
|
|
- Nothing ->
|
|
|
|
|
- Decode.fail "Invalid integer"
|
|
|
|
|
|
|
+ Nothing ->
|
|
|
|
|
+ Decode.fail ("Could not parse power: " ++ s)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|