2013-12-05 18:53:35 +00:00
#!/usr/bin/perl -w
#author: North
use strict ;
2014-01-19 08:52:21 +00:00
use Scalar::Util qw( looks_like_number ) ;
2013-12-05 18:53:35 +00:00
my $ dataFile = "mtg-cards-data.txt" ;
my $ setsFile = "mtg-sets-data.txt" ;
my $ knownSetsFile = "known-sets.txt" ;
my % sets ;
my % knownSets ;
my @ setCards ;
2016-09-17 02:39:40 +00:00
open ( DATA , $ knownSetsFile ) || die "can't open $knownSetsFile" ;
while ( my $ line = <DATA> ) {
my @ data = split ( '\\|' , $ line ) ;
$ knownSets { $ data [ 0 ] } = $ data [ 1 ] ;
#print ("$data[0] ===> $data[1]\n");
}
close ( DATA ) ;
2013-12-05 18:53:35 +00:00
# gets the set name
my $ setName = $ ARGV [ 0 ] ;
if ( ! $ setName ) {
print 'Enter a set name: ' ;
$ setName = <STDIN> ;
chomp $ setName ;
2016-09-17 02:39:40 +00:00
$ setName = $ setName ;
}
while ( ! defined ( $ knownSets { $ setName } ) )
{
print ( "Invalid set - '$setName'\n" ) ;
print ( " Possible sets you meant:\n" ) ;
my $ origSetName = $ setName ;
$ setName =~ s/^(.).*/$1/ ;
my $ key ;
foreach $ key ( sort keys ( % knownSets ) )
{
if ( $ key =~ m/^$setName/img )
{
print ( " '$key'\n" ) ;
}
}
print 'Enter a set name: ' ;
$ setName = <STDIN> ;
$ setName = $ setName ;
chomp $ setName ;
2013-12-05 18:53:35 +00:00
}
open ( DATA , $ dataFile ) || die "can't open $dataFile" ;
while ( my $ line = <DATA> ) {
my @ data = split ( '\\|' , $ line ) ;
if ( $ data [ 1 ] eq $ setName ) {
push ( @ setCards , \ @ data ) ;
}
}
close ( DATA ) ;
open ( DATA , $ setsFile ) || die "can't open $setsFile" ;
while ( my $ line = <DATA> ) {
my @ data = split ( '\\|' , $ line ) ;
$ sets { $ data [ 0 ] } = $ data [ 1 ] ;
}
close ( DATA ) ;
sub cardSort {
2014-01-19 08:52:21 +00:00
if ( ! looks_like_number ( @ { $ a } [ 2 ] ) ) { return - 1 ; }
if ( ! looks_like_number ( @ { $ b } [ 2 ] ) ) { return 1 ; }
2013-12-05 18:53:35 +00:00
if ( @ { $ a } [ 2 ] < @ { $ b } [ 2 ] ) { return - 1 ; }
elsif ( @ { $ a } [ 2 ] == @ { $ b } [ 2 ] ) { return 0 ; }
elsif ( @ { $ a } [ 2 ] > @ { $ b } [ 2 ] ) { return 1 ; }
}
sub toCamelCase {
my $ string = $ _ [ 0 ] ;
$ string =~ s/\b([\w']+)\b/ucfirst($1)/ge ;
$ string =~ s/[-,\s\']//g ;
$ string ;
}
2015-01-21 13:40:05 +00:00
# TODO: check for basic lands with ending 1,2,3,4,5 ...
2016-09-17 02:39:40 +00:00
my % cardNames ;
2013-12-05 18:53:35 +00:00
my $ toPrint = '' ;
foreach my $ card ( sort cardSort @ setCards ) {
my $ className = toCamelCase ( @ { $ card } [ 0 ] ) ;
2016-09-17 02:39:40 +00:00
$ cardNames { @ { $ card } [ 0 ] } = 1 ;
2017-04-10 05:39:52 +00:00
my $ currentFileName = "../Mage.Sets/src/mage/cards/" . lc ( substr ( $ className , 0 , 1 ) ) . "/" . $ className . ".java" ;
2013-12-05 18:53:35 +00:00
if ( ! - e $ currentFileName ) {
2016-09-17 02:39:40 +00:00
$ cardNames { @ { $ card } [ 0 ] } = 0 ;
2013-12-05 18:53:35 +00:00
if ( $ toPrint ) {
$ toPrint . = "\n" ;
2018-05-08 21:46:34 +00:00
}
my $ cardName = @ { $ card } [ 0 ] ;
$ cardName =~ s/ /+/g ;
$ toPrint . = "@{$card}[2]|[@{$card}[0]](https://magiccards.info/query?q=!$cardName)" ;
2013-12-05 18:53:35 +00:00
}
}
2014-02-19 18:48:33 +00:00
2014-01-19 08:52:21 +00:00
open CARD , "> " . lc ( $ sets { $ setName } ) . "_unimplemented.txt" ;
2013-12-05 18:53:35 +00:00
print CARD $ toPrint ;
close CARD ;
2016-09-17 02:39:40 +00:00
print ( "Unimplemented cards are here: " . lc ( $ sets { $ setName } ) . "_unimplemented.txt\n" ) ;
open ISSUE_TRACKER , "> " . lc ( $ sets { $ setName } ) . "_issue_tracker.txt" ;
2017-06-03 14:09:06 +00:00
print ISSUE_TRACKER "# Cards in set:\n" ;
2016-09-17 02:39:40 +00:00
my $ cn ;
foreach $ cn ( sort keys ( % cardNames ) )
{
my $ x_or_not = "[ ]" ;
if ( $ cardNames { $ cn } == 1 )
{
$ x_or_not = "[x]" ;
}
my $ cn2 = $ cn ;
$ cn2 =~ s/ /+/g ;
2018-05-08 21:46:34 +00:00
print ISSUE_TRACKER "- $x_or_not [$cn](https://magiccards.info/query?q=!$cn2)\n" ;
2016-09-17 02:39:40 +00:00
}
close ISSUE_TRACKER ;
print ( "Tracking Issue text for a new Github issue (similar to https://github.com/magefree/mage/issues/2215): " . lc ( $ sets { $ setName } ) . "_issue_tracker.txt\n" ) ;