mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
310 lines
11 KiB
Perl
Executable file
310 lines
11 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
|
|
#author: North
|
|
|
|
use Text::Template;
|
|
use strict;
|
|
|
|
|
|
my $authorFile = 'author.txt';
|
|
my $dataFile = 'mtg-cards-data.txt';
|
|
my $setsFile = 'mtg-sets-data.txt';
|
|
my $knownSetsFile = 'known-sets.txt';
|
|
my $keywordsFile = 'keywords.txt';
|
|
|
|
my %cards;
|
|
my %sets;
|
|
my %knownSets;
|
|
my %keywords;
|
|
|
|
sub toCamelCase {
|
|
my $string = $_[0];
|
|
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
|
|
$string =~ s/[-,\s\':]//g;
|
|
$string;
|
|
}
|
|
|
|
sub fixCost {
|
|
my $string = $_[0];
|
|
$string =~ s/{([2BUGRW])([2BUGRW])}/{$1\/$2}/g;
|
|
$string;
|
|
}
|
|
|
|
my $author;
|
|
if (-e $authorFile) {
|
|
open (DATA, $authorFile) || die "can't open $authorFile : $!";
|
|
$author = <DATA>;
|
|
chomp $author;
|
|
close(DATA);
|
|
} else {
|
|
$author = 'anonymous';
|
|
}
|
|
|
|
open (DATA, $dataFile) || die "can't open $dataFile : $!";
|
|
while(my $line = <DATA>) {
|
|
my @data = split('\\|', $line);
|
|
$cards{$data[0]}{$data[1]} = \@data;
|
|
}
|
|
close(DATA);
|
|
|
|
open (DATA, $setsFile) || die "can't open $setsFile : $!";
|
|
while(my $line = <DATA>) {
|
|
my @data = split('\\|', $line);
|
|
$sets{$data[0]}= $data[1];
|
|
#print "$data[0]--$data[1]\n"
|
|
}
|
|
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);
|
|
|
|
open (DATA, $keywordsFile) || die "can't open $keywordsFile : $!";
|
|
while(my $line = <DATA>) {
|
|
my @data = split('\\|', $line);
|
|
$keywords{toCamelCase($data[0])}= $data[1];
|
|
}
|
|
close(DATA);
|
|
|
|
my %cardTypes;
|
|
$cardTypes{'Artifact'} = 'CardType.ARTIFACT';
|
|
$cardTypes{'Conspiracy'} = 'CardType.CONSPIRACY';
|
|
$cardTypes{'Creature'} = 'CardType.CREATURE';
|
|
$cardTypes{'Enchantment'} = 'CardType.ENCHANTMENT';
|
|
$cardTypes{'Instant'} = 'CardType.INSTANT';
|
|
$cardTypes{'Land'} = 'CardType.LAND';
|
|
$cardTypes{'Sorcery'} = 'CardType.SORCERY';
|
|
$cardTypes{'Planeswalker'} = 'CardType.PLANESWALKER';
|
|
$cardTypes{'Tribal'} = 'CardType.TRIBAL';
|
|
|
|
my %raritiesConversion;
|
|
$raritiesConversion{'C'} = 'COMMON';
|
|
$raritiesConversion{'U'} = 'UNCOMMON';
|
|
$raritiesConversion{'R'} = 'RARE';
|
|
$raritiesConversion{'M'} = 'MYTHIC';
|
|
$raritiesConversion{'Special'} = 'SPECIAL';
|
|
$raritiesConversion{'Bonus'} = 'BONUS';
|
|
|
|
# Get card name
|
|
my $cardName = $ARGV[0];
|
|
if (!$cardName) {
|
|
print 'Enter a card name: ';
|
|
$cardName = <STDIN>;
|
|
chomp $cardName;
|
|
}
|
|
|
|
|
|
if (!exists $cards{$cardName}) {
|
|
my $possible;
|
|
foreach $possible (sort keys (%cards)) {
|
|
if ($possible =~ m/$cardName/img && $cardName =~ m/..../) {
|
|
print ("Did you mean $possible ?\n");
|
|
}
|
|
}
|
|
die "Card name doesn't exist: $cardName\n";
|
|
}
|
|
|
|
my $cardTemplate = 'cardClass.tmpl';
|
|
my $splitDelimiter = '//';
|
|
my $empty = '';
|
|
my $splitSpell = 'false';
|
|
my $originalName = $cardName;
|
|
|
|
# Remove the // from name of split cards
|
|
if (index($cardName, $splitDelimiter) != -1) {
|
|
$cardName =~ s/$splitDelimiter/$empty/g;
|
|
$cardTemplate = 'cardSplitClass.tmpl';
|
|
$splitSpell = 'true';
|
|
}
|
|
|
|
|
|
# Check if card is already implemented
|
|
my $fileName = "../Mage.Sets/src/mage/cards/".lc(< |