#!/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 () { 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> mapping = new HashMap>();\n\n"; print $out "\tstatic {\n\t\tHashMap set;\n"; } sub print_set_start { my ($set) = @_; print $out "\t\tset = new HashMap();\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}"; }