Compare commits

..

No commits in common. "1610194d4ce9663650fee20c2f60a6345e7990d0" and "c75989fd170cb26679c95c98c0e60d7ea5771046" have entirely different histories.

4 changed files with 64 additions and 26 deletions

View file

@ -17,6 +17,7 @@
"elm/parser": "1.1.0", "elm/parser": "1.1.0",
"elm/regex": "1.0.0", "elm/regex": "1.0.0",
"elm/url": "1.0.0", "elm/url": "1.0.0",
"elm-community/list-extra": "8.7.0",
"elm-community/maybe-extra": "5.2.0", "elm-community/maybe-extra": "5.2.0",
"mdgriffith/elm-ui": "1.1.8" "mdgriffith/elm-ui": "1.1.8"
}, },

View file

@ -16,8 +16,8 @@ type alias Prices =
type alias Oracle = type alias Oracle =
{ oracleId : String { oracleId : String
, name : String , name : String
, manaCost : String
, cmc : Float , cmc : Float
, manaCost : String
, typeLine : String , typeLine : String
, oracleText : String , oracleText : String
} }
@ -28,8 +28,8 @@ type alias Card =
, name : String , name : String
, setCode : String , setCode : String
, rarity : String , rarity : String
, manaCost : String
, cmc : Float , cmc : Float
, manaCost : String
, typeLine : String , typeLine : String
, oracleText : String , oracleText : String
, prices : Prices , prices : Prices
@ -48,11 +48,11 @@ decodeOracle =
Json.Decode.succeed Oracle Json.Decode.succeed Oracle
|> JDP.required "oracle_id" Json.Decode.string |> JDP.required "oracle_id" Json.Decode.string
|> JDP.required "name" Json.Decode.string |> JDP.required "name" Json.Decode.string
|> JDP.required "cmc" Json.Decode.float
|> JDP.required "mana_cost" |> JDP.required "mana_cost"
(Json.Decode.nullable Json.Decode.string (Json.Decode.nullable Json.Decode.string
|> Json.Decode.map (Maybe.withDefault "") |> Json.Decode.map (Maybe.withDefault "")
) )
|> JDP.required "cmc" Json.Decode.float
|> JDP.required "type_line" Json.Decode.string |> JDP.required "type_line" Json.Decode.string
|> JDP.required "oracle_text" |> JDP.required "oracle_text"
(Json.Decode.nullable Json.Decode.string (Json.Decode.nullable Json.Decode.string
@ -67,11 +67,11 @@ decode =
|> JDP.required "name" Json.Decode.string |> JDP.required "name" Json.Decode.string
|> JDP.required "set_code" Json.Decode.string |> JDP.required "set_code" Json.Decode.string
|> JDP.required "rarity" Json.Decode.string |> JDP.required "rarity" Json.Decode.string
|> JDP.required "cmc" Json.Decode.float
|> JDP.required "mana_cost" |> JDP.required "mana_cost"
(Json.Decode.nullable Json.Decode.string (Json.Decode.nullable Json.Decode.string
|> Json.Decode.map (Maybe.withDefault "") |> Json.Decode.map (Maybe.withDefault "")
) )
|> JDP.required "cmc" Json.Decode.float
|> JDP.required "type_line" Json.Decode.string |> JDP.required "type_line" Json.Decode.string
|> JDP.required "oracle_text" |> JDP.required "oracle_text"
(Json.Decode.nullable Json.Decode.string (Json.Decode.nullable Json.Decode.string

View file

@ -9,6 +9,7 @@ import Element.Background as Background
import Element.Events as Events import Element.Events as Events
import Element.Font as Font import Element.Font as Font
import Http import Http
import List.Extra
import Paginated import Paginated
import Route import Route
import Spinner import Spinner
@ -76,10 +77,11 @@ groups cards =
isEmpty : Group -> Bool isEmpty : Group -> Bool
isEmpty group = isEmpty group =
List.isEmpty group.cards List.isEmpty group.cards
gather : String -> String -> Group gather : String -> String -> Group
gather groupName typeName = gather groupName typeName =
List.filter (isA typeName) cards List.filter (isA typeName) cards
|> List.sortBy (\dc ->(dc.card.cmc, dc.card.name)) |> List.sortBy (\x -> ( x.card.cmc, x.card.name ))
|> Group groupName |> Group groupName
in in
List.filter (\l -> not <| isEmpty l) List.filter (\l -> not <| isEmpty l)
@ -129,30 +131,65 @@ update msg model =
( { model | symbols = symbols }, Cmd.none ) ( { model | symbols = symbols }, Cmd.none )
viewDeck : Symbol.Table -> Deck.Deck -> E.Element Msg viewDeck : E.Device -> Symbol.Table -> Deck.Deck -> E.Element Msg
viewDeck symbols deck = viewDeck device symbols deck =
let let
viewGroup group = columns : Int
E.column [ E.spacing 10 ] columns =
[ E.paragraph [ Font.heavy ] [ UI.title group.label ] if UI.isMobile device then
, E.wrappedRow [ E.spacing 10 ] <| 1
List.map
(\dc -> else
4
ensureColumns : Int -> List (List a) -> List (List a)
ensureColumns numCols xs =
let
current =
List.length xs
in
if current < numCols then
List.append xs <| List.repeat (numCols - current) []
else
xs
splitIntoColumns : Int -> List a -> List (List a)
splitIntoColumns numCols xs =
let
cardsPerColumn =
ceiling (toFloat (List.length xs) / toFloat numCols)
in
List.Extra.greedyGroupsOf cardsPerColumn xs
|> ensureColumns numCols
viewCard dc =
UI.cardRow UI.cardRow
{ foil = False { foil = False
, subtitle = "x" ++ String.fromInt dc.quantity , subtitle = "x" ++ String.fromInt dc.quantity
} }
[ E.width <| E.px 400, E.clipX, Background.color UI.colors.background ] [ Background.color UI.colors.background ]
symbols symbols
dc.card dc.card
)
group.cards viewCardColumn cards =
E.column [ E.spacing 10, E.alignTop, E.width <| E.fillPortion 1 ] <|
List.map viewCard cards
viewGroup group =
E.column
[ E.spacing 10, E.width E.fill ]
[ E.paragraph [ Font.heavy ] [ UI.title group.label ]
, E.row [ E.spacing 10, E.width E.fill ] <|
List.map viewCardColumn <|
splitIntoColumns columns group.cards
] ]
in in
E.column [ E.height E.fill, E.centerX, E.spacing 5 ] <| E.column [ E.height E.fill, E.width E.fill, E.spacing 5 ] <|
[ E.paragraph [ Font.heavy, Font.size 24, Font.center ] [ UI.title deck.name ] [ E.paragraph [ Font.heavy, Font.size 24, Font.center ] [ UI.title deck.name ]
, E.column , E.column
[ E.height E.fill [ E.height E.fill
, E.width E.fill
, E.spacing 10 , E.spacing 10
, Background.color UI.colors.sidebar , Background.color UI.colors.sidebar
, E.scrollbarY , E.scrollbarY
@ -172,7 +209,7 @@ view model =
] ]
[ case model.deck of [ case model.deck of
Ready deck -> Ready deck ->
viewDeck model.symbols deck viewDeck model.device model.symbols deck
Failed -> Failed ->
E.none E.none

View file

@ -188,7 +188,7 @@ priceBadge { currency, amount } =
E.el E.el
[ Border.rounded 5 [ Border.rounded 5
, Border.color colors.text , Border.color colors.text
, E.width <| E.px 60 , E.width E.fill
, E.padding 2 , E.padding 2
, Font.family [ Font.typeface "sans" ] , Font.family [ Font.typeface "sans" ]
, Font.size 10 , Font.size 10
@ -208,7 +208,7 @@ cardRow options attributes symbols card =
[ Border.rounded 5 [ Border.rounded 5
, Border.color color , Border.color color
, Border.width 1 , Border.width 1
, E.width <| E.px 60 , E.width E.fill
, Font.family [ Font.typeface "sans" ] , Font.family [ Font.typeface "sans" ]
, Font.size 10 , Font.size 10
, Font.color colors.title , Font.color colors.title
@ -291,12 +291,12 @@ cardRow options attributes symbols card =
] ]
, description = card.name , description = card.name
} }
, E.column [ E.centerY, E.height E.fill, E.width E.fill, E.clipX ] , E.column [ E.alignTop, E.width E.fill, E.clipX ]
[ Symbol.text symbols 12 card.manaCost [ Symbol.text symbols 12 card.manaCost
, E.el [ Font.color colors.title ] <| E.text card.name , E.el [ Font.color colors.title ] <| E.text card.name
, E.el [ Font.size 16, Font.italic, Font.color colors.subtitle ] <| E.text options.subtitle , E.el [ Font.size 16, Font.italic, Font.color colors.subtitle ] <| E.text options.subtitle
] ]
, E.column [ E.alignRight, E.height E.fill ] <| , E.column [ E.width <| E.px 70, E.alignTop, E.alignRight ] <|
setBadge options.foil setBadge options.foil
:: List.map priceBadge prices :: List.map priceBadge prices
] ]