forked from magefree/mage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_list_duplicate_collector_ids.pl
159 lines (135 loc) · 3.76 KB
/
gen_list_duplicate_collector_ids.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/perl -w
##
# File: gen_list_duplicate_collector_ids.pl
# Author: spjspj
# Purpose: To open all card java files and work out if any have duplicate cardNumber / expansionSetCode
##
use strict;
use Scalar::Util qw(looks_like_number);
my $dataFile = "mtg-cards-data.txt";
my $setsFile = "mtg-sets-data.txt";
my $knownSetsFile = "known-sets.txt";
my %sets;
my %knownSets;
my @setCards;
my %nameSetNumber;
my %setNumber;
open (DATA, $setsFile) || die "can't open $setsFile";
while(my $line = <DATA>)
{
my @data = split('\\|', $line);
$sets{$data[0]}= $data[1];
}
close(DATA);
sub toCamelCase
{
my $string = $_[0];
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
$string =~ s/[-,\s\']//g;
$string;
}
open (DATA, $dataFile) || die "can't open $dataFile";
open (FILES_TO_CHECK, ">files_to_check.bat");
print FILES_TO_CHECK "\@echo off\n";
print FILES_TO_CHECK "find \"super(ownerId\" ";
print ("Looking at data in $dataFile\n");
my %transformNames;
while (<DATA>)
{
chomp;
my $line = $_;
my $addDay = "";
my $transformable = 0;
if ($line =~ m/(transform|transformed under)/img)
{
$addDay = "-day";
$transformable = 1;
}
if ($line =~ m/(meld them|melds with)/img)
{
$addDay = "-day";
$transformable = 1;
}
$line =~ s/^(([^\|]+)\|([^\|]+)\|([^\|]+))\|.*/$1/;
my $name = $2;
my $set = $3;
my $number = $4;
$nameSetNumber {$line . $addDay} ++;
my $sn = "$set...$number$addDay";
if (!defined ($setNumber {$sn}))
{
$setNumber {$sn} = $name;
}
elsif ($setNumber {$sn} ne $name)
{
print ("Problem -> '$name' has the same collectorID/Set Name as ::: $setNumber{$sn} ($sn)\n");
$sn =~ s/\.\.\..*//;
my $trigraph = lc($sn);
$trigraph =~ s/[^a-z]//img;
print FILES_TO_CHECK " ..\\Mage.Sets\\src\\mage\\sets\\" , $trigraph, "\\", toCamelCase($name), ".java";
}
if ($transformable)
{
$transformNames {$name} = 1;
}
}
close(DATA);
print FILES_TO_CHECK "\n";
close (FILES_TO_CHECK);
my $dir_listing = "dir \/a \/b \/s ..\\Mage.Sets\\ | find \".java\" |";
my %find_info;
my %files_from_key;
open (DIR_LISTING, "$dir_listing");
while (<DIR_LISTING>)
{
chomp;
my $file = $_;
# Example:
# super(ownerId, 133, "Witch Hunt", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{R}");
# or
# super(ownerId);
# this.cardNumber = "100";
# this.expansionSetCode = "C13";
# or
# super(ownerId, 99, "Brine Elemental", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{4}{U}{U}");
# this.expansionSetCode = "C14";
my $name = "";
my $cardNum = "";
open (JAVA_FILE, "$file");
my $fileKey = $file;
$fileKey =~ s/^.*[\/\\]//;
if ($file !~ m/\.java$/)
{
next;
}
while (<JAVA_FILE>)
{
chomp;
#cards.add(new SetCardInfo("Bonds of Quicksilver", 102, Rarity.COMMON, mage.cards.b.BondsOfQuicksilver.class));
my $line = $_;
if ($line =~ m/SetCardInfo\("([^"]+)",([^,]+),/img)
{
$name = $1;
if (defined ($transformNames{$name}))
{
next;
}
$cardNum = $2;
$name =~ s/[^a-z0-9]//img;
$cardNum =~ s/[^a-z0-9]//img;
my $val = "$name($file),$fileKey,$cardNum";
my $key = "$fileKey,$cardNum";
#print ("$key >>> $val\n");
if (!defined ($find_info {$key}))
{
$find_info {$key} = $val;
$files_from_key {$key} = $file;
}
elsif ($key ne ",.")
{
print ("========\n$val\n Has the same key $key as\n$find_info{$key}\n");
}
}
}
close (JAVA_FILE);
}