Skip to content

Commit

Permalink
scryfall: parse mtga deck format
Browse files Browse the repository at this point in the history
  • Loading branch information
erg committed Apr 17, 2024
1 parent 11e3185 commit 8b61f72
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions extra/scryfall/scryfall.factor
Expand Up @@ -611,6 +611,28 @@ CONSTANT: rarity-to-number H{
: cards-by-name ( seq name -- seq' ) filter-by-name-itext sort-by-release ;
: cards-by-name. ( seq name -- ) cards-by-name [ "name" of ] sort-by normal-cards. ;

: parse-cards ( strings -- seq )
[
[ blank? ] trim
" " split1
[ string>number ]
[ standard-cards swap cards-by-name first ] bi* <array>
] map concat ;

: parse-mtga-deck ( string -- deck sideboard )
[ blank? ] trim
"Deck" ?head drop
string-lines
"Sideboard" split1
[ parse-cards ] bi@ ;

: sort-by-deck-order ( seq -- seq' )
[ "Land" any-type? not ] partition
[ sort-by-set-colors ] bi@ append ;

: deck. ( seq -- )
sort-by-deck-order normal-cards. ;

: filter-mtg-cheat-sheet ( seq -- seq' )
[
{
Expand Down

0 comments on commit 8b61f72

Please sign in to comment.