diff --git a/Utils/gen-card.pl b/Utils/gen-card.pl index ddb9d4d253..59c2c92594 100755 --- a/Utils/gen-card.pl +++ b/Utils/gen-card.pl @@ -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 = ; -chomp $cardName; +my $cardName = $ARGV[0]; +if(!$cardName) { + print 'Enter a card name: '; + $cardName = ; + 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"; } } diff --git a/Utils/gen-existing-cards-by-set.pl b/Utils/gen-existing-cards-by-set.pl index daab6c5506..afcb90d42d 100644 --- a/Utils/gen-existing-cards-by-set.pl +++ b/Utils/gen-existing-cards-by-set.pl @@ -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 = ; -chomp $setName; +# gets the set name +my $setName = $ARGV[0]; +if(!$setName) { + print 'Enter a set name: '; + $setName = ; + 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"; diff --git a/Utils/gen-simple-cards-by-set.pl b/Utils/gen-simple-cards-by-set.pl new file mode 100644 index 0000000000..f0dc6779ae --- /dev/null +++ b/Utils/gen-simple-cards-by-set.pl @@ -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 = ; +chomp $setName; + + +open (DATA, $dataFile) || die "can't open $dataFile"; +while(my $line = ) { + 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 = ) { + 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"); + } +} \ No newline at end of file