2011-07-11 18:26:55 +00:00
#!/usr/bin/perl -w
2011-07-17 08:01:04 +00:00
#author: North
2011-07-11 18:26:55 +00:00
use Text::Template ;
use strict ;
2011-07-13 20:29:20 +00:00
my $ authorFile = 'author.txt' ;
2011-07-11 18:26:55 +00:00
my $ dataFile = "mtg-cards-data.txt" ;
my $ setsFile = "mtg-sets-data.txt" ;
my $ knownSetsFile = "known-sets.txt" ;
2011-07-16 20:39:57 +00:00
2011-07-11 18:26:55 +00:00
my % cards ;
my % sets ;
my % knownSets ;
2011-07-13 20:29:20 +00:00
2011-07-11 18:26:55 +00:00
my @ setCards ;
2011-07-17 08:01:04 +00:00
# gets the set name
my $ setName = $ ARGV [ 0 ] ;
if ( ! $ setName ) {
print 'Enter a set name: ' ;
$ setName = <STDIN> ;
chomp $ setName ;
}
2011-07-11 18:26:55 +00:00
2011-07-17 08:01:04 +00:00
my $ template = Text::Template - > new ( TYPE = > 'FILE' , SOURCE = > 'cardExtendedClass.tmpl' , DELIMITERS = > [ '[=' , '=]' ] ) ;
2014-01-02 07:19:57 +00:00
my $ templateBasicLand = Text::Template - > new ( TYPE = > 'FILE' , SOURCE = > 'cardExtendedLandClass.tmpl' , DELIMITERS = > [ '[=' , '=]' ] ) ;
2011-07-11 18:26:55 +00:00
2011-07-16 20:39:57 +00:00
sub toCamelCase {
2011-07-11 18:26:55 +00:00
my $ string = $ _ [ 0 ] ;
2011-07-13 20:29:20 +00:00
$ string =~ s/\b([\w']+)\b/ucfirst($1)/ge ;
2011-07-12 20:38:39 +00:00
$ string =~ s/[-,\s\']//g ;
2011-07-11 18:26:55 +00:00
$ string ;
}
2011-07-13 20:29:20 +00:00
my $ author ;
if ( - e $ authorFile ) {
open ( DATA , $ authorFile ) ;
$ author = <DATA> ;
close ( DATA ) ;
} else {
$ author = 'anonymous' ;
}
2014-01-02 07:19:57 +00:00
my $ cardsFound = 0 ;
2016-11-01 22:07:43 +00:00
my % all_sets ;
2016-10-29 07:31:08 +00:00
print ( "Opening $dataFile\n" ) ;
2011-07-11 18:26:55 +00:00
open ( DATA , $ dataFile ) || die "can't open $dataFile" ;
while ( my $ line = <DATA> ) {
2011-07-13 20:29:20 +00:00
my @ data = split ( '\\|' , $ line ) ;
$ cards { $ data [ 0 ] } { $ data [ 1 ] } = \ @ data ;
2011-07-14 20:44:56 +00:00
2011-07-13 20:29:20 +00:00
if ( $ data [ 1 ] eq $ setName ) {
2016-10-29 07:31:08 +00:00
my $ cardInfo = "$data[0],,,$data[2]" ;
push ( @ setCards , $ cardInfo ) ;
2014-01-02 07:19:57 +00:00
$ cardsFound = $ cardsFound + 1 ;
2016-11-01 22:07:43 +00:00
} else {
$ all_sets { $ data [ 1 ] } = 1 ;
2011-07-11 18:26:55 +00:00
}
}
close ( DATA ) ;
2014-01-02 07:19:57 +00:00
print "Number of cards found for set " . $ setName . ": " . $ cardsFound . "\n" ;
2011-07-11 18:26:55 +00:00
2016-11-01 22:07:43 +00:00
if ( $ cardsFound == 0 ) {
$ setName =~ s/^(...).*/$1/ ;
my $ poss ;
foreach $ poss ( sort keys ( % all_sets ) ) {
if ( $ poss =~ m/^$setName/i ) {
print ( "Did you possibly mean: $poss ?\n" ) ;
}
}
exit ;
}
2011-07-11 18:26:55 +00:00
open ( DATA , $ setsFile ) || die "can't open $setsFile" ;
2014-01-02 07:19:57 +00:00
2011-07-11 18:26:55 +00:00
while ( my $ line = <DATA> ) {
2011-07-13 20:29:20 +00:00
my @ data = split ( '\\|' , $ line ) ;
$ sets { $ data [ 0 ] } = $ data [ 1 ] ;
2011-07-11 18:26:55 +00:00
}
close ( DATA ) ;
open ( DATA , $ knownSetsFile ) || die "can't open $knownSetsFile" ;
while ( my $ line = <DATA> ) {
2011-07-13 20:29:20 +00:00
my @ data = split ( '\\|' , $ line ) ;
$ knownSets { $ data [ 0 ] } = $ data [ 1 ] ;
2011-07-11 18:26:55 +00:00
}
close ( DATA ) ;
2011-07-14 20:44:56 +00:00
my % raritiesConversion ;
$ raritiesConversion { 'C' } = 'COMMON' ;
$ raritiesConversion { 'U' } = 'UNCOMMON' ;
$ raritiesConversion { 'R' } = 'RARE' ;
$ raritiesConversion { 'M' } = 'MYTHIC' ;
2014-06-25 08:37:07 +00:00
$ raritiesConversion { 'Special' } = 'SPECIAL' ;
$ raritiesConversion { 'Bonus' } = 'BONUS' ;
2016-10-29 07:31:08 +00:00
sub getRarity
{
my $ val = $ _ [ 0 ] ;
if ( exists ( $ raritiesConversion { $ val } ) )
{
return $ raritiesConversion { $ val } ;
}
2016-11-01 22:07:43 +00:00
print ( "ERROR DETECTED! - Incorrect rarity.. --- $val,,,$_[1]\n" ) ;
2016-10-29 07:31:08 +00:00
sleep ( 10 ) ;
2016-11-01 22:07:43 +00:00
exit ;
2016-10-29 07:31:08 +00:00
}
2011-07-14 20:44:56 +00:00
2011-07-13 20:29:20 +00:00
# Generate the cards
2011-07-11 18:26:55 +00:00
my % vars ;
2011-07-13 20:29:20 +00:00
$ vars { 'author' } = $ author ;
2011-07-11 18:26:55 +00:00
$ vars { 'set' } = $ knownSets { $ setName } ;
2011-07-13 20:29:20 +00:00
$ vars { 'expansionSetCode' } = $ sets { $ setName } ;
2011-07-11 18:26:55 +00:00
2014-01-02 07:19:57 +00:00
my $ landForest = 0 ;
my $ landMountain = 0 ;
my $ landSwamp = 0 ;
my $ landPlains = 0 ;
my $ landIsland = 0 ;
2016-10-29 07:31:08 +00:00
print ( "Reading in existing cards in set\n" ) ;
open ( SET_FILE , "../../mage/Mage.Sets/src/mage/sets/$knownSets{$setName}.java" ) || die "can't open $dataFile" ;
my % alreadyIn ;
while ( <SET_FILE> ) {
my $ line = $ _ ;
if ( $ line =~ m/SetCardInfo.*\("(.*)", (\d+).*/ )
{
$ alreadyIn { $ 2 } = $ 1 ;
}
}
close SET_FILE ;
my $ name_collectorid ;
my % implemented ;
my % implementedButNotInSetYet ;
my % unimplemented ;
2016-10-30 01:20:55 +00:00
my % githubTask ;
2016-10-29 07:31:08 +00:00
foreach $ name_collectorid ( sort @ setCards )
{
my $ cardName ;
my $ cardNr ;
$ name_collectorid =~ m/^(.*),,,(.*)$/ ;
$ cardName = $ 1 ;
$ cardNr = $ 2 ;
{
2014-01-02 07:19:57 +00:00
if ( $ cardName eq "Forest" || $ cardName eq "Island" || $ cardName eq "Plains" || $ cardName eq "Swamp" || $ cardName eq "Mountain" ) {
my $ found = 0 ;
if ( $ cardName eq "Forest" ) {
$ landForest + + ;
}
if ( $ cardName eq "Mountain" ) {
$ landMountain + + ;
}
if ( $ cardName eq "Swamp" ) {
$ landSwamp + + ;
}
if ( $ cardName eq "Plains" ) {
$ landPlains + + ;
}
if ( $ cardName eq "Island" ) {
$ landIsland + + ;
}
2016-10-29 07:31:08 +00:00
if ( ! exists ( $ alreadyIn { $ cardNr } ) ) {
print ( " cards.add(new SetCardInfo(\"$cardName\", $cardNr, Rarity.LAND, mage.cards.basiclands.$cardName.class, new CardGraphicInfo(null, true)));\n" ) ;
2014-01-02 07:19:57 +00:00
}
2016-10-29 07:31:08 +00:00
}
else {
2014-01-02 07:19:57 +00:00
my $ className = toCamelCase ( $ cardName ) ;
2016-10-29 07:31:08 +00:00
my $ setId = lc ( $ cardName ) ;
$ setId =~ s/^(.).*/$1/ ;
2017-01-07 01:55:09 +00:00
my $ googleSetName = $ setName ;
$ googleSetName =~ s/ /+/img ;
2016-10-29 07:31:08 +00:00
my $ fn = "..\\Mage.Sets\\src\\mage\\cards\\$setId\\$className.java" ;
my $ str = " cards.add(new SetCardInfo(\"$cardName\", $cardNr, Rarity." . getRarity ( $ cards { $ cardName } { $ setName } [ 3 ] , $ cardName ) . ", mage.cards.$setId.$className.class));\n" ;
2016-10-30 01:20:55 +00:00
my $ plus_cardName = $ cardName ;
$ plus_cardName =~ s/ /+/img ;
2016-10-30 05:50:54 +00:00
$ plus_cardName =~ s/,/+/img ;
$ plus_cardName = "intext:\"$plus_cardName\"" ;
2016-10-30 01:20:55 +00:00
2016-10-29 07:31:08 +00:00
if ( ! exists ( $ alreadyIn { $ cardNr } ) ) {
# Go Looking for the existing implementation..
if ( - e $ fn ) {
2016-10-29 07:39:46 +00:00
$ implementedButNotInSetYet { $ str } = 1 ;
2017-01-07 01:55:09 +00:00
$ githubTask { "- [ ] Implemented but have to add to set -- [$cardName](https://www.google.com.au/search?q=$plus_cardName+$googleSetName+mtg&source=lnms&tbm=isch)\n" } = 1 ;
2016-10-29 07:31:08 +00:00
} else {
$ unimplemented { "$str" } = 1 ;
2017-01-07 01:55:09 +00:00
$ githubTask { "- [ ] Not done -- [$cardName](https://www.google.com.au/search?q=$plus_cardName+$googleSetName+mtg&source=lnms&tbm=isch)\n" } = 1 ;
2011-07-11 18:26:55 +00:00
}
2016-10-29 07:31:08 +00:00
} else {
if ( - e $ fn ) {
2016-10-29 07:39:46 +00:00
$ implemented { $ str } = 1 ;
2017-01-07 01:55:09 +00:00
$ githubTask { "- [x] Done -- [$cardName](https://www.google.com.au/search?q=$plus_cardName+$googleSetName+mtg&source=lnms&tbm=isch)\n" } = 1 ;
2016-10-29 07:31:08 +00:00
} else {
$ unimplemented { $ str } = 1 ;
2017-01-07 01:55:09 +00:00
$ githubTask { "- [ ] Not Done -- [$cardName](https://www.google.com.au/search?q=$plus_cardName+$googleSetName+mtg&source=lnms&tbm=isch)\n" } = 1 ;
2014-01-02 07:19:57 +00:00
}
2011-07-11 18:26:55 +00:00
}
}
}
2011-07-13 20:29:20 +00:00
}
2016-10-29 07:31:08 +00:00
print "Implemented cards:\n" ;
print ( join ( "" , sort keys ( % implemented ) ) ) ;
print "\n\n\nImplemented but-not-yet-added-to-set cards:\n" ;
print ( join ( "" , sort keys ( % implementedButNotInSetYet ) ) ) ;
print "\n\n\nUnimplemented cards:\n" ;
print ( join ( "" , sort keys ( % unimplemented ) ) ) ;
2016-10-30 01:20:55 +00:00
print "\n\n\nGithub Task:\n" ;
print ( join ( "" , sort keys ( % githubTask ) ) ) ;
2016-10-29 07:35:04 +00:00
print ( "\nData from reading: ../../mage/Mage.Sets/src/mage/sets/$knownSets{$setName}.java\n" ) ;