@@ -7,10 +7,10 @@ package cfg;
7
7
8
8
use File::Basename;
9
9
use Cwd qw/ abs_path/ ;
10
- ( our $script_path = abs_path( $0 ) ) =~ s | ^(.*)(\[\/\] )(.*)| $1$2 | g ;
11
- our $script_dir = dirname( $script_path );
10
+ (our $script_path = abs_path($0 ) ) =~ s | ^(.*)(\[\/\] )(.*)| $1$2 | g ;
11
+ our $script_dir = dirname($script_path );
12
12
13
- our $cachetime = 3600 ;
13
+ our $cachetime = 86400 ;
14
14
15
15
package datacache ;
16
16
@@ -19,33 +19,33 @@ package datacache;
19
19
use DBI;
20
20
use Digest::SHA1 qw( sha1 sha1_hex sha1_base64) ;
21
21
22
- my $dbh = DBI-> connect ( " dbi:SQLite:dbname=${cfg::script_dir} /datacache.sqlitedb" , " " , " " , { RaiseError => 1 } ) or die $DBI::errstr ;
23
- $dbh -> do( " CREATE TABLE IF NOT EXISTS cache (urlhash TEXT PRIMARY KEY, timestamp INTEGER, data TEXT)" );
24
- my $sth = $dbh -> prepare( " DELETE FROM cache WHERE timestamp < ?" );
25
- $sth -> bind_param( 1, time - ${cfg::cachetime} );
22
+ my $dbh = DBI-> connect (" dbi:SQLite:dbname=${cfg::script_dir} /datacache.sqlitedb" , " " , " " , { RaiseError => 1 }) or die $DBI::errstr ;
23
+ $dbh -> do(" CREATE TABLE IF NOT EXISTS cache (urlhash TEXT PRIMARY KEY, timestamp INTEGER, data TEXT)" );
24
+ my $sth = $dbh -> prepare(" DELETE FROM cache WHERE timestamp < ?" );
25
+ $sth -> bind_param(1, time - ${cfg::cachetime} );
26
26
$sth -> execute();
27
27
28
28
sub get_url {
29
- my ( $url ) = @_ ;
30
- my $urlhash = sha1_base64( $url );
31
- my $sth = $dbh -> prepare( " SELECT * FROM cache WHERE urlhash = ? AND timestamp > ?" );
32
- $sth -> bind_param( 1, $urlhash );
33
- $sth -> bind_param( 2, time - ${cfg::cachetime} );
29
+ my ($url ) = @_ ;
30
+ my $urlhash = sha1_base64($url );
31
+ my $sth = $dbh -> prepare(" SELECT * FROM cache WHERE urlhash = ? AND timestamp > ?" );
32
+ $sth -> bind_param(1, $urlhash );
33
+ $sth -> bind_param(2, time - ${cfg::cachetime} );
34
34
$sth -> execute();
35
35
36
36
my $row ;
37
- if ( $row = $sth -> fetchrow_hashref() ) {
37
+ if ( $row = $sth -> fetchrow_hashref()) {
38
38
$sth -> finish();
39
39
return $row -> {data };
40
40
}
41
41
else {
42
42
print " Getting '$url '...\n " ;
43
43
$sth -> finish();
44
- my $data = get( $url );
45
- $sth = $dbh -> prepare( " INSERT OR REPLACE INTO cache (urlhash, timestamp, data) VALUES(?, ?, ?)" );
46
- $sth -> bind_param( 1, $urlhash );
47
- $sth -> bind_param( 2, time );
48
- $sth -> bind_param( 3, $data );
44
+ my $data = get($url );
45
+ $sth = $dbh -> prepare(" INSERT OR REPLACE INTO cache (urlhash, timestamp, data) VALUES(?, ?, ?)" );
46
+ $sth -> bind_param(1, $urlhash );
47
+ $sth -> bind_param(2, time );
48
+ $sth -> bind_param(3, $data );
49
49
$sth -> execute();
50
50
$sth -> finish();
51
51
return $data ;
@@ -58,32 +58,32 @@ package simc;
58
58
our $directory = " ${cfg::script_dir} /simc" ;
59
59
60
60
my $last_branch = ` cd "${directory} " && git rev-parse --abbrev-ref HEAD` ;
61
- die unless ( ( $? >> 8 ) == 0 );
61
+ die unless (( $? >> 8) == 0);
62
62
chomp $last_branch ;
63
63
64
64
sub update {
65
- my ( $requested_branch ) = @_ ;
65
+ my ($requested_branch ) = @_ ;
66
66
$requested_branch = $requested_branch || ${simc::branch} ;
67
67
68
- if ( !-d " ${simc::directory} /.git" ) {
69
- system ( " git clone --depth=1 https://github.com/simulationcraft/simc \" ${simc::directory} \" " );
70
- die unless ( ( $? >> 8 ) == 0 );
68
+ if ( !-d " ${simc::directory} /.git" ) {
69
+ system (" git clone --depth=1 https://github.com/simulationcraft/simc \" ${simc::directory} \" " );
70
+ die unless (( $? >> 8) == 0);
71
71
}
72
72
else {
73
- system ( " cd \" ${simc::directory} \" && git pull" );
74
- die unless ( ( $? >> 8 ) == 0 );
73
+ system (" cd \" ${simc::directory} \" && git pull" );
74
+ die unless (( $? >> 8) == 0);
75
75
}
76
76
77
- if ( $requested_branch ne $last_branch ) {
78
- system ( " cd \" ${simc::directory} \" && git reset --hard HEAD && git clean -xfd && git checkout \" ${requested_branch} \" && git pull" );
79
- die unless ( ( $? >> 8 ) == 0 );
77
+ if ( $requested_branch ne $last_branch ) {
78
+ system (" cd \" ${simc::directory} \" && git reset --hard HEAD && git clean -xfd && git checkout \" ${requested_branch} \" && git pull" );
79
+ die unless (( $? >> 8) == 0);
80
80
$last_branch = ` cd "${simc::directory} " && git rev-parse --abbrev-ref HEAD` ;
81
- die unless ( ( $? >> 8 ) == 0 );
82
- die unless ( $last_branch eq $requested_branch );
81
+ die unless (( $? >> 8) == 0);
82
+ die unless ($last_branch eq $requested_branch );
83
83
}
84
84
85
- system ( " cd \" ${simc::directory} /engine\" && make -j9 OS=UNIX" );
86
- die unless ( ( $? >> 8 ) == 0 );
85
+ system (" cd \" ${simc::directory} /engine\" && make -j9 OS=UNIX" );
86
+ die unless (( $? >> 8) == 0);
87
87
}
88
88
89
89
package generator ;
@@ -155,48 +155,48 @@ package generator;
155
155
};
156
156
157
157
sub create_action_lists {
158
- print ( " \n Pre-creating actions files...\n " );
159
- for my $cls ( sort keys %{$profiles } ) {
158
+ print (" \n Pre-creating actions files...\n " );
159
+ for my $cls (sort keys %{$profiles }) {
160
160
my $class_lua_actions_file = " ${cfg::script_dir} /ActionProfileLists/actions-${cls} .lua" ;
161
- my $bn = basename( $class_lua_actions_file );
162
- print ( " - ${bn} \n " );
163
- open ( my $outfile , " >" , $class_lua_actions_file );
161
+ my $bn = basename($class_lua_actions_file );
162
+ print (" - ${bn} \n " );
163
+ open (my $outfile , " >" , $class_lua_actions_file );
164
164
print {$outfile } " local _, internal = ...\n " ;
165
165
print {$outfile } " internal.apls = internal.apls or {}\n\n " ;
166
- close ( $outfile );
166
+ close ($outfile );
167
167
}
168
168
169
- print ( " \n Generating custom simc profile APLs:\n " );
170
- for my $cls ( sort keys %{$customprofiles } ) {
169
+ print (" \n Generating custom simc profile APLs:\n " );
170
+ for my $cls (sort keys %{$customprofiles }) {
171
171
my $class_lua_actions_file = " ${cfg::script_dir} /ActionProfileLists/actions-${cls} .lua" ;
172
- open ( my $outfile , " >>" , $class_lua_actions_file );
172
+ open (my $outfile , " >>" , $class_lua_actions_file );
173
173
174
- for my $spec ( @{ $customprofiles -> {$cls } } ) {
175
- printf ( " %14s / %s \n " , $cls , $spec );
174
+ for my $spec (@{ $customprofiles -> {$cls } }) {
175
+ printf (" %14s / %s \n " , $cls , $spec );
176
176
177
177
print {$outfile } " internal.apls['custom::${cls} ::${spec} '] = [[\n " ;
178
178
179
179
my $custom_simc_file = " ${cfg::script_dir} /CustomProfiles/${cls} _${spec} .simc" ;
180
- open ( my $infile , " <" , $custom_simc_file );
181
- while ( <$infile > ) {
180
+ open (my $infile , " <" , $custom_simc_file );
181
+ while ( <$infile >) {
182
182
chomp $_ ;
183
183
print {$outfile } " $_ \n " if $_ =~ / ^action/ ;
184
184
}
185
- close ( $infile );
185
+ close ($infile );
186
186
187
187
print {$outfile } " ]]\n\n " ;
188
188
}
189
189
190
- close ( $outfile );
190
+ close ($outfile );
191
191
}
192
192
193
- print ( " \n Generating normal simc APLs:\n " );
194
- for my $cls ( sort keys %{$profiles } ) {
193
+ print (" \n Generating normal simc APLs:\n " );
194
+ for my $cls (sort keys %{$profiles }) {
195
195
my $class_lua_actions_file = " ${cfg::script_dir} /ActionProfileLists/actions-${cls} .lua" ;
196
- open ( my $outfile , " >>" , $class_lua_actions_file );
196
+ open (my $outfile , " >>" , $class_lua_actions_file );
197
197
198
- for my $spec ( sort keys %{ $profiles -> {$cls } } ) {
199
- printf ( " %14s / %s \n " , $cls , $spec );
198
+ for my $spec (sort keys %{ $profiles -> {$cls } }) {
199
+ printf (" %14s / %s \n " , $cls , $spec );
200
200
201
201
print {$outfile } " internal.apls['${simc::branch} ::${cls} ::${spec} '] = [[\n " ;
202
202
@@ -211,138 +211,138 @@ sub create_action_lists {
211
211
212
212
my $new_simc_file = " ${cfg::script_dir} /Temp/${simc::branch} -${cls} _${spec} .simc" ;
213
213
my $simc_cmd = " \" ${simc::directory} /engine/simc\" ${cls} =${cls} _${spec} default_actions=1 level=110 spec=${spec} ${mainhand} ${offhand} ${artifact} \" save=${new_simc_file} \" " ;
214
- system ( " { $simc_cmd ;} >/dev/null 2>&1" );
215
- die unless ( ( $? >> 8 ) == 0 );
214
+ system (" { $simc_cmd ;} >/dev/null 2>&1" );
215
+ die unless (( $? >> 8) == 0);
216
216
217
- open ( my $infile , " <" , $new_simc_file );
218
- while ( <$infile > ) {
217
+ open (my $infile , " <" , $new_simc_file );
218
+ while ( <$infile >) {
219
219
chomp $_ ;
220
220
print {$outfile } " $_ \n " if $_ =~ / ^action/ ;
221
221
}
222
- close ( $infile );
222
+ close ($infile );
223
223
224
224
print {$outfile } " ]]\n\n " ;
225
225
}
226
226
227
- close ( $outfile );
227
+ close ($outfile );
228
228
}
229
229
}
230
230
231
231
sub create_equipped_mapping {
232
- print ( " \n Generating equipped item mapping:\n " );
232
+ print (" \n Generating equipped item mapping:\n " );
233
233
my $equipped_file = " ${cfg::script_dir} /ActionProfileLists/equipped.lua" ;
234
- open ( my $outfile , " >" , $equipped_file );
234
+ open (my $outfile , " >" , $equipped_file );
235
235
print {$outfile } " local _, internal = ...\n " ;
236
236
print {$outfile } " internal.equipped_mapping = internal.equipped_mapping or {}\n\n " ;
237
237
238
238
my @files = <" ${cfg::script_dir} /ActionProfileLists/actions-*.lua" >;
239
239
my %items ;
240
- for my $file ( sort @files ) {
241
- open ( my $infile , " <" , $file );
242
- while ( <$infile > ) {
240
+ for my $file (sort @files ) {
241
+ open (my $infile , " <" , $file );
242
+ while ( <$infile >) {
243
243
chomp $_ ;
244
- while ( $_ =~ m / equipped\. ([a-zA-Z][[:alnum:]_]*)/ g ) {
244
+ while ( $_ =~ m / equipped\. ([a-zA-Z][[:alnum:]_]*)/ g ) {
245
245
$items {$1 } = 1;
246
246
}
247
247
}
248
- close ( $infile );
248
+ close ($infile );
249
249
}
250
250
251
- for my $item ( sort keys %items ) {
252
- print ( " - Item: '${item} '\n " );
251
+ for my $item (sort keys %items ) {
252
+ print (" - Item: '${item} '\n " );
253
253
my $urlitem = $item ;
254
254
$urlitem =~ s / _/ +/ g ;
255
255
my $url = " http://www.wowhead.com/items/name:${urlitem} /slot:16:18:5:8:11:10:1:23:7:21:2:22:13:24:15:28:14:4:3:19:25:12:17:6:9" ;
256
- my $data = datacache::get_url( $url );
256
+ my $data = datacache::get_url($url );
257
257
258
258
my %itemids ;
259
- while ( $data =~ m / _\[ (\d +)\] / g ) {
259
+ while ( $data =~ m / _\[ (\d +)\] / g ) {
260
260
$itemids {$1 } = 1;
261
261
}
262
262
263
263
print {$outfile } " internal.equipped_mapping.${item} = { " ;
264
- for my $itemid ( sort keys %itemids ) {
264
+ for my $itemid (sort keys %itemids ) {
265
265
print " ID: $itemid \n " ;
266
266
print {$outfile } " $itemid , " ;
267
267
}
268
268
print {$outfile } " }\n " ;
269
269
}
270
270
271
- close ( $outfile );
271
+ close ($outfile );
272
272
}
273
273
274
274
sub create_itemset_bonuses {
275
- print ( " \n Generating set bonus listing:\n " );
275
+ print (" \n Generating set bonus listing:\n " );
276
276
my $setbonus_file = " ${cfg::script_dir} /ActionProfileLists/itemsets.lua" ;
277
- open ( my $outfile , " >" , $setbonus_file );
277
+ open (my $outfile , " >" , $setbonus_file );
278
278
print {$outfile } " local _, internal = ...\n " ;
279
279
print {$outfile } " internal.itemsets = internal.itemsets or {}\n\n " ;
280
280
281
- open ( my $infile , " <" , " ${simc::directory} /dbc_extract3/dbc/generator.py" );
281
+ open (my $infile , " <" , " ${simc::directory} /dbc_extract3/dbc/generator.py" );
282
282
my $mode = 0;
283
283
my $text = " " ;
284
- while ( <$infile > ) {
284
+ while ( <$infile >) {
285
285
chomp $_ ;
286
286
next if $_ =~ / ^\s *#/ ;
287
287
$_ =~ s / #.*// g ;
288
288
$_ =~ s / '/ "/ g ;
289
- if ( $mode == 0 && $_ =~ / \s *set_bonus_map/ ) {
289
+ if ( $mode == 0 && $_ =~ / \s *set_bonus_map/ ) {
290
290
$mode = 1;
291
291
$text .= " [\n " ;
292
292
}
293
- elsif ( $mode == 1 && $_ ne " " ) {
293
+ elsif ($mode == 1 && $_ ne " " ) {
294
294
$text .= $_ . " \n " ;
295
295
}
296
- elsif ( $mode == 1 ) {
296
+ elsif ($mode == 1) {
297
297
$mode = 2;
298
298
}
299
299
}
300
300
301
301
# Fixup trailing commas before container terminators
302
302
$text =~ s / ,([\s\r\n ]*[\}\] ])/ $1 / gi ;
303
303
304
- my $bonuses = from_json( $text );
305
- for my $bonus ( sort { $a -> {name } cmp $b -> {name } } @{$bonuses } ) {
304
+ my $bonuses = from_json($text );
305
+ for my $bonus (sort { $a -> {name } cmp $b -> {name } } @{$bonuses }) {
306
306
print " - $bonus ->{name}\n " ;
307
307
308
308
print {$outfile } " internal.itemsets.$bonus ->{name} = { " ;
309
309
310
- for my $itemset ( sort @{ $bonus -> {bonuses } } ) {
310
+ for my $itemset (sort @{ $bonus -> {bonuses } }) {
311
311
my $url = " http://www.wowhead.com/item-set=${itemset} " ;
312
- my $data = datacache::get_url( $url );
312
+ my $data = datacache::get_url($url );
313
313
my %items ;
314
- while ( $data =~ m / g_items\. add\( (\d +)/ g ) {
314
+ while ( $data =~ m / g_items\. add\( (\d +)/ g ) {
315
315
$items {$1 } = 1;
316
316
}
317
- for my $itemid ( sort keys %items ) {
317
+ for my $itemid (sort keys %items ) {
318
318
print {$outfile } " ${itemid} , " ;
319
319
}
320
320
}
321
321
322
322
print {$outfile } " }\n " ;
323
323
}
324
324
325
- close ( $outfile );
325
+ close ($outfile );
326
326
}
327
327
328
328
sub create_xml_wrapper {
329
- my ( $searchdir ) = @_ ;
329
+ my ($searchdir ) = @_ ;
330
330
331
- my $bn = basename( $searchdir );
332
- print ( " \n Generating '${bn} /all.xml'\n " );
333
- open ( my $out , " >" , " ${searchdir} /all.xml" );
331
+ my $bn = basename($searchdir );
332
+ print (" \n Generating '${bn} /all.xml'\n " );
333
+ open (my $out , " >" , " ${searchdir} /all.xml" );
334
334
print {$out } " <Ui xmlns=\" http://www.blizzard.com/wow/ui/\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\" http://www.blizzard.com/wow/ui/\n " ;
335
335
print {$out } " ..\\ FrameXML\\ UI.xsd\" >\n " ;
336
336
337
337
my @actionfiles = <" ${searchdir} /*.lua" >;
338
- for my $actionfile ( sort @actionfiles ) {
339
- $bn = basename( $actionfile );
340
- print ( " - ${bn} \n " );
338
+ for my $actionfile (sort @actionfiles ) {
339
+ $bn = basename($actionfile );
340
+ print (" - ${bn} \n " );
341
341
print {$out } " <Script file=\" ${bn} \" />\n " ;
342
342
}
343
343
344
344
print {$out } " </Ui>\n " ;
345
- close ( $out );
345
+ close ($out );
346
346
}
347
347
348
348
package main ;
@@ -351,5 +351,5 @@ package main;
351
351
generator::create_action_lists();
352
352
generator::create_equipped_mapping();
353
353
generator::create_itemset_bonuses();
354
- generator::create_xml_wrapper( " ${cfg::script_dir} /ActionProfileLists" );
355
- generator::create_xml_wrapper( " ${cfg::script_dir} /Classes" );
354
+ generator::create_xml_wrapper(" ${cfg::script_dir} /ActionProfileLists" );
355
+ generator::create_xml_wrapper(" ${cfg::script_dir} /Classes" );
0 commit comments