mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Added script to generate cards that can be completely generated.
Fixed issue in gen-card.pl
This commit is contained in:
parent
c8885e3fcd
commit
4e4b71d2f1
3 changed files with 100 additions and 15 deletions
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
#author: North
|
||||
|
||||
use Text::Template;
|
||||
use strict;
|
||||
|
||||
|
@ -83,30 +85,40 @@ $manaToColor{'W'} = 'White';
|
|||
|
||||
|
||||
# Get card name
|
||||
print 'Enter a card name: ';
|
||||
my $cardName = <STDIN>;
|
||||
chomp $cardName;
|
||||
my $cardName = $ARGV[0];
|
||||
if(!$cardName) {
|
||||
print 'Enter a card name: ';
|
||||
$cardName = <STDIN>;
|
||||
chomp $cardName;
|
||||
}
|
||||
|
||||
if (!exists $cards{$cardName}) {
|
||||
die "Card name doesn't exist: $cardName\n";
|
||||
}
|
||||
|
||||
# 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";
|
||||
if(-e $fileName) {
|
||||
die "$cardName is already implemented (set found: $setName).\n";
|
||||
die "$cardName is already implemented (set found in: $setName).\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Generate the cards
|
||||
my $template = Text::Template->new(SOURCE => 'cardClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
|
||||
my $templateExtended = Text::Template->new(SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
|
||||
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;
|
||||
|
||||
$vars{'author'} = $author;
|
||||
$vars{'name'} = $cardName;
|
||||
$vars{'className'} = toCamelCase($cardName);
|
||||
|
||||
print "Files generated:\n";
|
||||
if ($simpleOnly ne 'true') {
|
||||
print "Files generated:\n";
|
||||
}
|
||||
my $baseRarity = '';
|
||||
foreach my $setName (keys %{$cards{$cardName}}) {
|
||||
if (exists $knownSets{$setName}) {
|
||||
|
@ -168,8 +180,11 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
my @ka = split(', ', $ability);
|
||||
foreach my $kw (@ka) {
|
||||
my $kwUnchanged = $kw;
|
||||
$kw = toCamelCase($kw);
|
||||
|
||||
foreach my $keyword (keys %keywords) {
|
||||
if (index(toCamelCase($kw), $keyword) eq 0) {
|
||||
$kw = $keyword;
|
||||
}
|
||||
}
|
||||
if ($keywords{$kw}) {
|
||||
if ($keywords{$kw} eq 'instance') {
|
||||
$vars{'abilities'} .= "\n this.addAbility(" . $kw . "Ability.getInstance());";
|
||||
|
@ -187,6 +202,9 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
$vars{'abilitiesImports'} .= "\nimport mage.abilities.keyword." . $kw . "Ability;";
|
||||
} else {
|
||||
$vars{'abilities'} .= "\n // $kwUnchanged";
|
||||
if ($simpleOnly eq 'true') {
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +212,9 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
|
||||
if (!$notKeyWord) {
|
||||
$vars{'abilities'} .= "\n // $ability";
|
||||
if ($simpleOnly eq 'true') {
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($vars{'abilities'}) {
|
||||
|
@ -216,6 +237,6 @@ foreach my $setName (keys %{$cards{$cardName}}) {
|
|||
print CARD $result;
|
||||
close CARD;
|
||||
|
||||
print "$fileName\n";
|
||||
print "$vars{'set'}.$vars{'className'}\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
#author: North
|
||||
|
||||
use Text::Template;
|
||||
use strict;
|
||||
|
||||
|
@ -16,11 +18,15 @@ my %knownSets;
|
|||
|
||||
my @setCards;
|
||||
|
||||
print "Enter a set name: ";
|
||||
my $setName = <STDIN>;
|
||||
chomp $setName;
|
||||
# gets the set name
|
||||
my $setName = $ARGV[0];
|
||||
if(!$setName) {
|
||||
print 'Enter a set name: ';
|
||||
$setName = <STDIN>;
|
||||
chomp $setName;
|
||||
}
|
||||
|
||||
my $template = Text::Template->new(SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
|
||||
my $template = Text::Template->new(TYPE => 'FILE', SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
|
||||
|
||||
sub toCamelCase {
|
||||
my $string = $_[0];
|
||||
|
@ -76,7 +82,7 @@ $vars{'author'} = $author;
|
|||
$vars{'set'} = $knownSets{$setName};
|
||||
$vars{'expansionSetCode'} = $sets{$setName};
|
||||
|
||||
print "Files generated:\n";
|
||||
print "Extended cards generated:\n";
|
||||
foreach my $cardName (@setCards) {
|
||||
my $className = toCamelCase($cardName);
|
||||
my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java";
|
||||
|
|
58
Utils/gen-simple-cards-by-set.pl
Normal file
58
Utils/gen-simple-cards-by-set.pl
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
#author: North
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
my $dataFile = 'mtg-cards-data.txt';
|
||||
my $knownSetsFile = "known-sets.txt";
|
||||
|
||||
my %knownSets;
|
||||
my @setCards;
|
||||
|
||||
sub toCamelCase {
|
||||
my $string = $_[0];
|
||||
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
|
||||
$string =~ s/[-,\s\']//g;
|
||||
$string;
|
||||
}
|
||||
|
||||
print 'Enter a set name: ';
|
||||
my $setName = <STDIN>;
|
||||
chomp $setName;
|
||||
|
||||
|
||||
open (DATA, $dataFile) || die "can't open $dataFile";
|
||||
while(my $line = <DATA>) {
|
||||
my @data = split('\\|', $line);
|
||||
if ($data[1] eq $setName) {
|
||||
push(@setCards, \@data);
|
||||
}
|
||||
}
|
||||
close(DATA);
|
||||
|
||||
open (DATA, $knownSetsFile) || die "can't open $knownSetsFile";
|
||||
while(my $line = <DATA>) {
|
||||
my @data = split('\\|', $line);
|
||||
$knownSets{$data[0]}= $data[1];
|
||||
}
|
||||
close(DATA);
|
||||
|
||||
if(!exists $knownSets{$setName}) {
|
||||
die "You must add the set to known-sets.txt\n";
|
||||
}
|
||||
|
||||
my $packageName = $knownSets{$setName};
|
||||
|
||||
$setName =~ s/"/\\"/g;
|
||||
system("gen-existing-cards-by-set.pl \"$setName\"");
|
||||
|
||||
# Generate missing simple cards
|
||||
print "Simple cards generated: \n";
|
||||
foreach my $cardName (@setCards) {
|
||||
my $fileName = "../Mage.Sets/src/mage/sets/" . $packageName . "/" . toCamelCase(${$cardName}[0]) . ".java";
|
||||
if(!-e $fileName) {
|
||||
system("gen-card.pl \"${$cardName}[0]\" true");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue