add script

This commit is contained in:
Loki 2010-11-26 05:56:24 +00:00
parent 3b1696d8f0
commit 621223634c

View file

@ -0,0 +1,60 @@
#!/usr/bin/perl -w
use strict;
opendir SETS, "sets/";
my $out;
open $out, "> ImagesMapping.java";
print_header();
while (readdir SETS) {
my $filename = $_;
if ($filename =~m/s?(.+).txt/) {
my $set = uc($1);
print "processing $set\n";
print_set_start($set);
open FILE, "< sets/$filename";
my $lastcollector = -1;
my $lastimage = -1;
while (<FILE>) {
if (m/image:(\d+)/) {
$lastimage = $1;
} elsif (m/card No:(\d+)/) {
$lastcollector = $1;
} elsif (m/------------------------------/) {
if ($lastcollector != -1) {
print_card($lastcollector, $lastimage);
}
}
}
}
}
print_footer();
close $out;
sub print_header {
print $out "// WARNING! THIS FILE ARE GENERATED BY A SCRIPT\n";
print $out "package mage.client.cards;\n\n";
print $out "import java.util.HashMap;\n";
print $out "public class ImagesMapping {\n";
print $out "\tpublic final static HashMap<String, HashMap<Integer, String>> mapping = new HashMap<String, HashMap<Integer, String>>();\n\n";
print $out "\tstatic {\n\t\tHashMap<Integer, String> set;\n";
}
sub print_set_start {
my ($set) = @_;
print $out "\t\tset = new HashMap<Integer, String>();\n\t\tmapping.put(\"$set\", set);\n";
}
sub print_card {
my ($cid, $mtgo) = @_;
print $out "\t\tset.put($cid, \"" . $mtgo . "_typ_reg_sty_010.jpg\");\n";
}
sub print_footer {
print $out "\t}\n}";
}