Compare commits

..

2 commits

Author SHA1 Message Date
1610194d4c Sort deck cards by cmc 2023-01-11 21:37:52 -05:00
dc284833bc Revert "Show deck cards in columns"
This reverts commit c75989fd17.
2023-01-11 21:19:22 -05:00
4 changed files with 26 additions and 64 deletions

View file

@ -17,7 +17,6 @@
"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
, cmc : Float
, manaCost : String , manaCost : String
, cmc : Float
, 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
, cmc : Float
, manaCost : String , manaCost : String
, cmc : Float
, 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,7 +9,6 @@ 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
@ -77,11 +76,10 @@ 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 (\x -> ( x.card.cmc, x.card.name )) |> List.sortBy (\dc ->(dc.card.cmc, dc.card.name))
|> Group groupName |> Group groupName
in in
List.filter (\l -> not <| isEmpty l) List.filter (\l -> not <| isEmpty l)
@ -131,65 +129,30 @@ update msg model =
( { model | symbols = symbols }, Cmd.none ) ( { model | symbols = symbols }, Cmd.none )
viewDeck : E.Device -> Symbol.Table -> Deck.Deck -> E.Element Msg viewDeck : Symbol.Table -> Deck.Deck -> E.Element Msg
viewDeck device symbols deck = viewDeck symbols deck =
let let
columns : Int
columns =
if UI.isMobile device then
1
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
{ foil = False
, subtitle = "x" ++ String.fromInt dc.quantity
}
[ Background.color UI.colors.background ]
symbols
dc.card
viewCardColumn cards =
E.column [ E.spacing 10, E.alignTop, E.width <| E.fillPortion 1 ] <|
List.map viewCard cards
viewGroup group = viewGroup group =
E.column E.column [ E.spacing 10 ]
[ E.spacing 10, E.width E.fill ]
[ E.paragraph [ Font.heavy ] [ UI.title group.label ] [ E.paragraph [ Font.heavy ] [ UI.title group.label ]
, E.row [ E.spacing 10, E.width E.fill ] <| , E.wrappedRow [ E.spacing 10 ] <|
List.map viewCardColumn <| List.map
splitIntoColumns columns group.cards (\dc ->
UI.cardRow
{ foil = False
, subtitle = "x" ++ String.fromInt dc.quantity
}
[ E.width <| E.px 400, E.clipX, Background.color UI.colors.background ]
symbols
dc.card
)
group.cards
] ]
in in
E.column [ E.height E.fill, E.width E.fill, E.spacing 5 ] <| E.column [ E.height E.fill, E.centerX, 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
@ -209,7 +172,7 @@ view model =
] ]
[ case model.deck of [ case model.deck of
Ready deck -> Ready deck ->
viewDeck model.device model.symbols deck viewDeck 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.fill , E.width <| E.px 60
, 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.fill , E.width <| E.px 60
, 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.alignTop, E.width E.fill, E.clipX ] , E.column [ E.centerY, E.height E.fill, 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.width <| E.px 70, E.alignTop, E.alignRight ] <| , E.column [ E.alignRight, E.height E.fill ] <|
setBadge options.foil setBadge options.foil
:: List.map priceBadge prices :: List.map priceBadge prices
] ]