mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Merge pull request #2455 from Styxo/master
Fixed gen-card to work after reorg
This commit is contained in:
commit
51f2d991ac
2 changed files with 138 additions and 147 deletions
|
@ -25,7 +25,7 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.sets.[=$set=];
|
||||
package mage.cards.[=$cardNameFirstLetter=];
|
||||
|
||||
import java.util.UUID;[=
|
||||
if ($power || $power eq 0) {
|
||||
|
@ -33,8 +33,8 @@ if ($power || $power eq 0) {
|
|||
}
|
||||
=][=$abilitiesImports=]
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -42,9 +42,9 @@ import mage.constants.Rarity;
|
|||
*/
|
||||
public class [=$className=] extends CardImpl {
|
||||
|
||||
public [=$className=](UUID ownerId) {
|
||||
super(ownerId, [=$cardNumber=], "[=$name=]", Rarity.[=$rarity=], new CardType[]{[=$type=]}, "[=$manaCost=]");
|
||||
this.expansionSetCode = "[=$expansionSetCode=]";[=$subType=][=$colors=][=
|
||||
public [=$className=](UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{[=$type=]}, "[=$manaCost=]");
|
||||
[=$subType=][=$colors=][=
|
||||
if ($power || $power eq 0) {
|
||||
$OUT .= "\n this.power = new MageInt($power);";
|
||||
$OUT .= "\n this.toughness = new MageInt($toughness);";
|
||||
|
|
|
@ -12,7 +12,6 @@ my $setsFile = 'mtg-sets-data.txt';
|
|||
my $knownSetsFile = 'known-sets.txt';
|
||||
my $keywordsFile = 'keywords.txt';
|
||||
|
||||
|
||||
my %cards;
|
||||
my %sets;
|
||||
my %knownSets;
|
||||
|
@ -21,7 +20,7 @@ my %keywords;
|
|||
sub toCamelCase {
|
||||
my $string = $_[0];
|
||||
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
|
||||
$string =~ s/[-,\s\']//g;
|
||||
$string =~ s/[-,\s\':]//g;
|
||||
$string;
|
||||
}
|
||||
|
||||
|
@ -102,58 +101,72 @@ if (!exists $cards{$cardName}) {
|
|||
}
|
||||
|
||||
# Check if card is already implemented
|
||||
foreach my $setName (keys %{$cards{$cardName}}) {
|
||||
if (exists $knownSets{$setName}) {
|
||||
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java";
|
||||
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";
|
||||
}
|
||||
}
|
||||
my $fileName = "../Mage.Sets/src/mage/cards/".substr($cardName, 0, 1)."/".toCamelCase($cardName).".java";
|
||||
if(-e $fileName) {
|
||||
die "$cardName is already implemented.\n";
|
||||
}
|
||||
|
||||
# Generate the cards
|
||||
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 => [ '[=', '=]' ]);
|
||||
# Generate lines to corresponding sets
|
||||
my %vars;
|
||||
|
||||
$vars{'author'} = $author;
|
||||
$vars{'name'} = $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}}) {
|
||||
if (exists $knownSets{$setName}) {
|
||||
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java";
|
||||
print "gvim $fileName\n";
|
||||
my $fileName2 = $fileName;
|
||||
$fileName2 =~ s/\//\\/img;
|
||||
print "gvim $fileName2\n";
|
||||
my $result;
|
||||
my $setFileName = "../Mage.Sets/src/mage/sets/".toCamelCase($setName).".java";
|
||||
@card = @{${cards{$cardName}{$setName}}};
|
||||
my $line = "\tcards.add(new SetCardInfo(\"".$card[0]."\", ".$card[2].", Rarity.".$raritiesConversion{$card[3]}.", mage.cards.".$vars{'cardNameFirstLetter'}.".".$vars{'className'}.".class));\n";
|
||||
|
||||
$vars{'set'} = $knownSets{$setName};
|
||||
$vars{'expansionSetCode'} = $sets{$setName};
|
||||
$vars{'cardNumber'} = $cards{$cardName}{$setName}[2];
|
||||
$vars{'rarity'} = $raritiesConversion{$cards{$cardName}{$setName}[3]};
|
||||
@ARGV = ($setFileName);
|
||||
$^I = '.bak';
|
||||
my $last;
|
||||
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) {
|
||||
$baseRarity = $cards{$cardName}{$setName}[3];
|
||||
($lastName) = $last =~ m/"(.*?)"/;
|
||||
($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]);
|
||||
$vars{'power'} = $cards{$cardName}{$setName}[6];
|
||||
$vars{'toughness'} = $cards{$cardName}{$setName}[7];
|
||||
unlink $setFileName.".bak";
|
||||
print "$setFileName\n";
|
||||
}
|
||||
|
||||
my @types;
|
||||
$vars{'subType'} = '';
|
||||
my $type = $cards{$cardName}{$setName}[5];
|
||||
while ($type =~ m/([a-zA-Z]+)( )*/g) {
|
||||
# Generate the the card
|
||||
my $result;
|
||||
my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
|
||||
$vars{'author'} = $author;
|
||||
$vars{'manaCost'} = fixCost($card[4]);
|
||||
$vars{'power'} = $card[6];
|
||||
$vars{'toughness'} = $card[7];
|
||||
|
||||
my @types;
|
||||
$vars{'subType'} = '';
|
||||
my $type = $card[5];
|
||||
while ($type =~ m/([a-zA-Z]+)( )*/g) {
|
||||
if (exists($cardTypes{$1})) {
|
||||
push(@types, $cardTypes{$1});
|
||||
} else {
|
||||
|
@ -163,14 +176,14 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
$vars{'subType'} .= "\n this.supertype.add(\"$1\");";
|
||||
}
|
||||
}
|
||||
}
|
||||
$vars{'type'} = join(', ', @types);
|
||||
}
|
||||
$vars{'type'} = join(', ', @types);
|
||||
|
||||
$vars{'abilitiesImports'} = '';
|
||||
$vars{'abilities'} = '';
|
||||
$vars{'abilitiesImports'} = '';
|
||||
$vars{'abilities'} = '';
|
||||
|
||||
my @abilities = split('\$', $cards{$cardName}{$setName}[8]);
|
||||
foreach my $ability (@abilities) {
|
||||
my @abilities = split('\$', $card[8]);
|
||||
foreach my $ability (@abilities) {
|
||||
$ability =~ s/ <i>.+?<\/i>//g;
|
||||
|
||||
my $notKeyWord;
|
||||
|
@ -208,14 +221,9 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,33 +231,16 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
|
||||
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 {
|
||||
print "Set not found in known sets: $setName\n";
|
||||
}
|
||||
}
|
||||
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";
|
||||
|
|
Loading…
Reference in a new issue