From bd7c08562dbe1857df68cf27e6a7069589e6ae02 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jan 2014 08:19:57 +0100 Subject: [PATCH] Added to the perl script "gen-existing-cards-by-set.pl" the generation of basic lands. --- Utils/cardExtendedLandClass.tmpl | 53 ++++++++++++ Utils/gen-existing-cards-by-set.pl | 126 +++++++++++++++++++++-------- 2 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 Utils/cardExtendedLandClass.tmpl diff --git a/Utils/cardExtendedLandClass.tmpl b/Utils/cardExtendedLandClass.tmpl new file mode 100644 index 00000000000..b5aec4b3acc --- /dev/null +++ b/Utils/cardExtendedLandClass.tmpl @@ -0,0 +1,53 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.sets.[=$set=]; + +import java.util.UUID; + +/** + * + * @author [=$author=] + */ + + +public class [=$className=][=$landNr=] extends mage.cards.basiclands.[=$className=] { + + public [=$className=][=$landNr=](UUID ownerId) { + super(ownerId, [=$cardNumber=]); + this.expansionSetCode = "[=$expansionSetCode=]"; + } + + public [=$className=][=$landNr=](final [=$className=][=$landNr=] card) { + super(card); + } + + @Override + public [=$className=][=$landNr=] copy() { + return new [=$className=][=$landNr=](this); + } +} diff --git a/Utils/gen-existing-cards-by-set.pl b/Utils/gen-existing-cards-by-set.pl index afcb90d42d7..b966195a0c4 100644 --- a/Utils/gen-existing-cards-by-set.pl +++ b/Utils/gen-existing-cards-by-set.pl @@ -27,6 +27,7 @@ if(!$setName) { } my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]); +my $templateBasicLand = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardExtendedLandClass.tmpl', DELIMITERS => [ '[=', '=]' ]); sub toCamelCase { my $string = $_[0]; @@ -44,18 +45,24 @@ if (-e $authorFile) { $author = 'anonymous'; } +my $cardsFound = 0; open (DATA, $dataFile) || die "can't open $dataFile"; while(my $line = ) { my @data = split('\\|', $line); $cards{$data[0]}{$data[1]} = \@data; if ($data[1] eq $setName) { - push(@setCards, $data[0]); + my $cardInfo = {$data[0] ,$data[2]}; + my $ref_cardInfo = \$cardInfo; + push(@setCards, $ref_cardInfo); + $cardsFound = $cardsFound + 1; } } close(DATA); +print "Number of cards found for set " . $setName . ": " . $cardsFound . "\n"; open (DATA, $setsFile) || die "can't open $setsFile"; + while(my $line = ) { my @data = split('\\|', $line); $sets{$data[0]}= $data[1]; @@ -82,46 +89,101 @@ $vars{'author'} = $author; $vars{'set'} = $knownSets{$setName}; $vars{'expansionSetCode'} = $sets{$setName}; +my $landForest = 0; +my $landMountain = 0; +my $landSwamp = 0; +my $landPlains = 0; +my $landIsland = 0; + print "Extended cards generated:\n"; -foreach my $cardName (@setCards) { - 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]; +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; + } + if($landNr != "") { + $vars{'landNr'} = $landNr; + my $className = toCamelCase($cardName) . $landNr; + my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java"; - 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 = ) { - if ($line =~ /extends CardImpl<(\w+?)>/) { - $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]};"; + 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 = ) { + if ($line =~ /extends CardImpl<(\w+?)>/ || $line =~ /extends LevelerCard<(\w+?)>/) { + $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; + } } - $found = 1; + close(DATA); } } - close(DATA); + } + + 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; + } } } } - 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; - } - } } }