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;
|
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) {
|
2014-01-02 07:19:57 +00:00
|
|
|
my $cardInfo = {$data[0] ,$data[2]};
|
|
|
|
my $ref_cardInfo = \$cardInfo;
|
|
|
|
push(@setCards, $ref_cardInfo);
|
|
|
|
$cardsFound = $cardsFound + 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
|
|
|
|
|
|
|
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';
|
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;
|
|
|
|
|
2011-07-17 08:01:04 +00:00
|
|
|
print "Extended cards generated:\n";
|
2014-01-02 07:19:57 +00:00
|
|
|
|
|
|
|
while ( my ($key, $value) = each(@setCards) ) {
|
|
|
|
while ( my ($cardName, $cardNr) = each($$value) ) {
|
|
|
|
if($cardName eq "Forest" || $cardName eq "Island" || $cardName eq "Plains" || $cardName eq "Swamp" || $cardName eq "Mountain") {
|
|
|
|
my $found = 0;
|
|
|
|
my $landNr = "";
|
|
|
|
if ($cardName eq "Forest") {
|
|
|
|
$landForest++;
|
|
|
|
$landNr = $landForest;
|
|
|
|
}
|
|
|
|
if ($cardName eq "Mountain") {
|
|
|
|
$landMountain++;
|
|
|
|
$landNr = $landMountain;
|
|
|
|
}
|
|
|
|
if ($cardName eq "Swamp") {
|
|
|
|
$landSwamp++;
|
|
|
|
$landNr = $landSwamp;
|
|
|
|
}
|
|
|
|
if ($cardName eq "Plains") {
|
|
|
|
$landPlains++;
|
|
|
|
$landNr = $landPlains;
|
|
|
|
}
|
|
|
|
if ($cardName eq "Island") {
|
|
|
|
$landIsland++;
|
|
|
|
$landNr = $landIsland;
|
|
|
|
}
|
2014-01-04 12:59:55 +00:00
|
|
|
if(!($landNr eq "")) {
|
2014-01-02 07:19:57 +00:00
|
|
|
$vars{'landNr'} = $landNr;
|
|
|
|
my $className = toCamelCase($cardName) . $landNr;
|
|
|
|
my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java";
|
|
|
|
|
|
|
|
if(! -e $currentFileName) {
|
|
|
|
|
|
|
|
$vars{'className'} = toCamelCase($cardName);
|
|
|
|
$vars{'cardNumber'} = $cardNr;
|
|
|
|
|
|
|
|
my $result = $templateBasicLand->fill_in(HASH => \%vars);
|
|
|
|
if (defined($result)) {
|
|
|
|
print $vars{'set'} . "." . $vars{'className'} . " cardNr = " . $cardNr . "\n";
|
|
|
|
open CARD, "> $currentFileName";
|
|
|
|
print CARD $result;
|
|
|
|
close CARD;
|
|
|
|
} else {
|
|
|
|
print "Error while creating " . $vars{'className'} ."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my $className = toCamelCase($cardName);
|
|
|
|
my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java";
|
|
|
|
if(! -e $currentFileName) {
|
|
|
|
$vars{'className'} = $className;
|
|
|
|
$vars{'cardNumber'} = $cards{$cardName}{$setName}[2];
|
|
|
|
|
|
|
|
my $found = 0;
|
|
|
|
foreach my $keySet (keys %{$cards{$cardName}}) {
|
|
|
|
if (exists $knownSets{$keySet} && $found eq 0) {
|
|
|
|
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$keySet} . "/" . $className . ".java";
|
|
|
|
if(-e $fileName) {
|
|
|
|
open (DATA, $fileName);
|
|
|
|
while(my $line = <DATA>) {
|
2014-06-23 13:58:07 +00:00
|
|
|
if ($line =~ /extends CardImpl / || $line =~ /extends LevelerCard /) {
|
2014-01-02 07:19:57 +00:00
|
|
|
$vars{'baseClassName'} = $1;
|
|
|
|
$vars{'baseSet'} = $knownSets{$keySet};
|
|
|
|
|
|
|
|
$vars{'rarityExtended'} = '';
|
|
|
|
if ($cards{$cardName}{$setName}[3] ne $cards{$cardName}{$keySet}[3]) {
|
|
|
|
$vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};";
|
|
|
|
}
|
|
|
|
$found = 1;
|
|
|
|
}
|
2011-07-14 20:44:56 +00:00
|
|
|
}
|
2014-01-02 07:19:57 +00:00
|
|
|
close(DATA);
|
2011-07-11 18:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-02 07:19:57 +00:00
|
|
|
if($found eq 1) {
|
|
|
|
my $result = $template->fill_in(HASH => \%vars);
|
|
|
|
if (defined($result)) {
|
|
|
|
print $vars{'set'} . "." . $vars{'className'} . "\n";
|
|
|
|
open CARD, "> $currentFileName";
|
|
|
|
print CARD $result;
|
|
|
|
close CARD;
|
|
|
|
}
|
|
|
|
}
|
2011-07-11 18:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-02 07:19:57 +00:00
|
|
|
|
2011-07-11 18:26:55 +00:00
|
|
|
}
|
2011-07-13 20:29:20 +00:00
|
|
|
}
|