Merge pull request #2455 from Styxo/master

Fixed gen-card to work after reorg
This commit is contained in:
LevelX2 2016-10-11 22:59:15 +02:00 committed by GitHub
commit 51f2d991ac
2 changed files with 138 additions and 147 deletions

View file

@ -25,7 +25,7 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.sets.[=$set=]; package mage.cards.[=$cardNameFirstLetter=];
import java.util.UUID;[= import java.util.UUID;[=
if ($power || $power eq 0) { if ($power || $power eq 0) {
@ -33,8 +33,8 @@ if ($power || $power eq 0) {
} }
=][=$abilitiesImports=] =][=$abilitiesImports=]
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity;
/** /**
* *
@ -42,9 +42,9 @@ import mage.constants.Rarity;
*/ */
public class [=$className=] extends CardImpl { public class [=$className=] extends CardImpl {
public [=$className=](UUID ownerId) { public [=$className=](UUID ownerId, CardSetInfo setInfo) {
super(ownerId, [=$cardNumber=], "[=$name=]", Rarity.[=$rarity=], new CardType[]{[=$type=]}, "[=$manaCost=]"); super(ownerId, setInfo, new CardType[]{[=$type=]}, "[=$manaCost=]");
this.expansionSetCode = "[=$expansionSetCode=]";[=$subType=][=$colors=][= [=$subType=][=$colors=][=
if ($power || $power eq 0) { if ($power || $power eq 0) {
$OUT .= "\n this.power = new MageInt($power);"; $OUT .= "\n this.power = new MageInt($power);";
$OUT .= "\n this.toughness = new MageInt($toughness);"; $OUT .= "\n this.toughness = new MageInt($toughness);";

View file

@ -12,7 +12,6 @@ my $setsFile = 'mtg-sets-data.txt';
my $knownSetsFile = 'known-sets.txt'; my $knownSetsFile = 'known-sets.txt';
my $keywordsFile = 'keywords.txt'; my $keywordsFile = 'keywords.txt';
my %cards; my %cards;
my %sets; my %sets;
my %knownSets; my %knownSets;
@ -21,7 +20,7 @@ my %keywords;
sub toCamelCase { sub toCamelCase {
my $string = $_[0]; my $string = $_[0];
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge; $string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
$string =~ s/[-,\s\']//g; $string =~ s/[-,\s\':]//g;
$string; $string;
} }
@ -102,154 +101,146 @@ if (!exists $cards{$cardName}) {
} }
# Check if card is already implemented # Check if card is already implemented
foreach my $setName (keys %{$cards{$cardName}}) { my $fileName = "../Mage.Sets/src/mage/cards/".substr($cardName, 0, 1)."/".toCamelCase($cardName).".java";
if (exists $knownSets{$setName}) { if(-e $fileName) {
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java"; die "$cardName is already implemented.\n";
print "gvim $fileName\n";
my $fileName2 = $fileName;
$fileName2 =~ s/\//\\/img;
print "gvim $fileName2\n";
if(-e $fileName) {
die "$cardName is already implemented (set found in: $setName).\n";
}
}
} }
# Generate the cards # Generate lines to corresponding sets
my $simpleOnly = $ARGV[1] || 'false';
my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
my $templateExtended = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
my %vars; my %vars;
$vars{'author'} = $author;
$vars{'name'} = $cardName;
$vars{'className'} = toCamelCase($cardName); $vars{'className'} = toCamelCase($cardName);
$vars{'cardNameFirstLetter'} = lc substr($cardName, 0, 1);
my @card;
if ($simpleOnly ne 'true') {
print "Files generated:\n";
}
my $baseRarity = '';
foreach my $setName (keys %{$cards{$cardName}}) { foreach my $setName (keys %{$cards{$cardName}}) {
if (exists $knownSets{$setName}) { my $setFileName = "../Mage.Sets/src/mage/sets/".toCamelCase($setName).".java";
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java"; @card = @{${cards{$cardName}{$setName}}};
print "gvim $fileName\n"; my $line = "\tcards.add(new SetCardInfo(\"".$card[0]."\", ".$card[2].", Rarity.".$raritiesConversion{$card[3]}.", mage.cards.".$vars{'cardNameFirstLetter'}.".".$vars{'className'}.".class));\n";
my $fileName2 = $fileName;
$fileName2 =~ s/\//\\/img;
print "gvim $fileName2\n";
my $result;
$vars{'set'} = $knownSets{$setName}; @ARGV = ($setFileName);
$vars{'expansionSetCode'} = $sets{$setName}; $^I = '.bak';
$vars{'cardNumber'} = $cards{$cardName}{$setName}[2]; my $last;
$vars{'rarity'} = $raritiesConversion{$cards{$cardName}{$setName}[3]}; my $lastName;
my $currName;
while (<>) {
if ($_ !~ m/cards.add/) {
if (defined($last)) {
print $last;
}
# print card line as last
if (defined($currName) && ($cardName cmp $currName) > 0) {
print $line;
undef $currName;
}
$last = $_;
print $last if eof;
next;
}
if (!$baseRarity) { ($lastName) = $last =~ m/"(.*?)"/;
$baseRarity = $cards{$cardName}{$setName}[3]; ($currName) = $_ =~ m/"(.*?)"/;
print $last;
$last = $_;
# print card line as first
if (!defined($lastName) && defined($currName) && ($currName cmp $cardName) > 0) {
print $line;
}
# print card line in the middle
if (defined($lastName) && defined($currName) && ($cardName cmp $lastName) > 0 && ($currName cmp $cardName) > 0) {
print $line;
}
}
$vars{'manaCost'} = fixCost($cards{$cardName}{$setName}[4]); unlink $setFileName.".bak";
$vars{'power'} = $cards{$cardName}{$setName}[6]; print "$setFileName\n";
$vars{'toughness'} = $cards{$cardName}{$setName}[7]; }
my @types; # Generate the the card
$vars{'subType'} = ''; my $result;
my $type = $cards{$cardName}{$setName}[5]; my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
while ($type =~ m/([a-zA-Z]+)( )*/g) { $vars{'author'} = $author;
if (exists($cardTypes{$1})) { $vars{'manaCost'} = fixCost($card[4]);
push(@types, $cardTypes{$1}); $vars{'power'} = $card[6];
} else { $vars{'toughness'} = $card[7];
if (@types) {
$vars{'subType'} .= "\n this.subtype.add(\"$1\");";
} else {
$vars{'subType'} .= "\n this.supertype.add(\"$1\");";
}
}
}
$vars{'type'} = join(', ', @types);
$vars{'abilitiesImports'} = ''; my @types;
$vars{'abilities'} = ''; $vars{'subType'} = '';
my $type = $card[5];
my @abilities = split('\$', $cards{$cardName}{$setName}[8]); while ($type =~ m/([a-zA-Z]+)( )*/g) {
foreach my $ability (@abilities) { if (exists($cardTypes{$1})) {
$ability =~ s/ <i>.+?<\/i>//g; push(@types, $cardTypes{$1});
my $notKeyWord;
foreach my $keyword (keys %keywords) {
if (toCamelCase($ability) =~ m/^$keyword(?=[A-Z{\d]|$)/g) {
$notKeyWord = 'false';
my @ka = split(', ', $ability);
foreach my $kw (@ka) {
my $kwUnchanged = $kw;
foreach my $kk (keys %keywords) {
if (toCamelCase($kw) =~ m/^$kk(?=[A-Z{\d]|$)/g) {
$kw = $kk;
}
}
if ($keywords{$kw}) {
$vars{'abilities'} .= "\n // " . ucfirst($kwUnchanged);
if ($keywords{$kw} eq 'instance') {
$vars{'abilities'} .= "\n this.addAbility(" . $kw . "Ability.getInstance());";
} elsif ($keywords{$kw} eq 'new') {
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . "Ability());";
} elsif ($keywords{$kw} eq 'color') {
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . "Ability(this.color));";
} elsif ($keywords{$kw} eq 'number') {
$ability =~ m/(\b\d+?\b)/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(' . $1 . '));';
} elsif ($keywords{$kw} eq 'cost') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(new ManaCostsImpl("' . fixCost($1) . '")));';
$vars{'abilitiesImports'} .= "\nimport mage.abilities.costs.mana.ManaCostsImpl;";
} elsif ($keywords{$kw} eq 'card, manaString') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(this, "' . fixCost($1) . '"));';
} elsif ($keywords{$kw} eq 'card, cost') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(this, new ManaCostsImpl("' . fixCost($1) . '")));';
$vars{'abilitiesImports'} .= "\nimport mage.abilities.costs.mana.ManaCostsImpl;";
}
$vars{'abilitiesImports'} .= "\nimport mage.abilities.keyword." . $kw . "Ability;";
} else {
$vars{'abilities'} .= "\n // $kwUnchanged";
if ($simpleOnly eq 'true') {
exit 0;
}
}
}
}
}
if (!$notKeyWord) {
$vars{'abilities'} .= "\n // $ability";
if ($simpleOnly eq 'true') {
exit 0;
}
}
}
if ($vars{'abilities'}) {
$vars{'abilities'} = "\n" . $vars{'abilities'};
}
$vars{'baseSet'} = $vars{'set'};
$vars{'baseClassName'} = $vars{'className'};
$result = $template->fill_in(HASH => \%vars);
} else {
$vars{'rarityExtended'} = '';
if ($baseRarity ne $cards{$cardName}{$setName}[3]) {
$vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};";
}
$result = $templateExtended->fill_in(HASH => \%vars);
}
open CARD, "> $fileName";
print CARD $result;
close CARD;
print "$vars{'set'}.$vars{'className'}\n";
} else { } else {
print "Set not found in known sets: $setName\n"; if (@types) {
$vars{'subType'} .= "\n this.subtype.add(\"$1\");";
} else {
$vars{'subType'} .= "\n this.supertype.add(\"$1\");";
}
} }
} }
$vars{'type'} = join(', ', @types);
$vars{'abilitiesImports'} = '';
$vars{'abilities'} = '';
my @abilities = split('\$', $card[8]);
foreach my $ability (@abilities) {
$ability =~ s/ <i>.+?<\/i>//g;
my $notKeyWord;
foreach my $keyword (keys %keywords) {
if (toCamelCase($ability) =~ m/^$keyword(?=[A-Z{\d]|$)/g) {
$notKeyWord = 'false';
my @ka = split(', ', $ability);
foreach my $kw (@ka) {
my $kwUnchanged = $kw;
foreach my $kk (keys %keywords) {
if (toCamelCase($kw) =~ m/^$kk(?=[A-Z{\d]|$)/g) {
$kw = $kk;
}
}
if ($keywords{$kw}) {
$vars{'abilities'} .= "\n // " . ucfirst($kwUnchanged);
if ($keywords{$kw} eq 'instance') {
$vars{'abilities'} .= "\n this.addAbility(" . $kw . "Ability.getInstance());";
} elsif ($keywords{$kw} eq 'new') {
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . "Ability());";
} elsif ($keywords{$kw} eq 'color') {
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . "Ability(this.color));";
} elsif ($keywords{$kw} eq 'number') {
$ability =~ m/(\b\d+?\b)/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(' . $1 . '));';
} elsif ($keywords{$kw} eq 'cost') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(new ManaCostsImpl("' . fixCost($1) . '")));';
$vars{'abilitiesImports'} .= "\nimport mage.abilities.costs.mana.ManaCostsImpl;";
} elsif ($keywords{$kw} eq 'card, manaString') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(this, "' . fixCost($1) . '"));';
} elsif ($keywords{$kw} eq 'card, cost') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(this, new ManaCostsImpl("' . fixCost($1) . '")));';
$vars{'abilitiesImports'} .= "\nimport mage.abilities.costs.mana.ManaCostsImpl;";
}
$vars{'abilitiesImports'} .= "\nimport mage.abilities.keyword." . $kw . "Ability;";
} else {
$vars{'abilities'} .= "\n // $kwUnchanged";
}
}
}
}
if (!$notKeyWord) {
$vars{'abilities'} .= "\n // $ability";
}
}
if ($vars{'abilities'}) {
$vars{'abilities'} = "\n" . $vars{'abilities'};
}
$result = $template->fill_in(HASH => \%vars);
open CARD, "> $fileName";
print CARD $result;
close CARD;
print "$fileName\n";