83 lines
2.1 KiB
Perl
83 lines
2.1 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
use v5.16.1;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Path::Tiny;
|
|
use Data::Dumper;
|
|
|
|
my $output_file = path('lib/Rsaves/Constants/Emerald/SpeciesData.pm');
|
|
my $input_file = path('pokeemerald/src/data/pokemon/species_info.h');
|
|
my $fh_output = $output_file->openw;
|
|
open my $fh_input, '-|', 'cpp', $input_file;
|
|
|
|
print $fh_output <<'EOF';
|
|
package Rsaves::Constants::Emerald::SpeciesData;
|
|
|
|
use v5.16.3;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
EOF
|
|
|
|
$Data::Dumper::Terse = 1;
|
|
|
|
my %all_species_data;
|
|
{
|
|
my $species;
|
|
my %species_data;
|
|
while (defined (my $line = <$fh_input>)) {
|
|
if ($line =~ /^\s*\[SPECIES_(\w+)\]\s*=/) {
|
|
if (defined $species) {
|
|
$all_species_data{$species} = {%species_data};
|
|
}
|
|
%species_data = ();
|
|
$species = $1;
|
|
if ($species eq 'NONE') {
|
|
$species = undef;
|
|
}
|
|
}
|
|
if (defined $species) {
|
|
if ($line =~ /\.growthRate\s*=\s*(\w+)/) {
|
|
my $growth_rate = $1;
|
|
$species_data{growth_rate} = $1;
|
|
}
|
|
if ($line =~ /\.genderRatio\s*=\s*(\w+)/) {
|
|
my $gender_ratio = $1;
|
|
if ($gender_ratio eq 'min' && $line =~ /(\w+) \* 255/) {
|
|
$gender_ratio = $1;
|
|
$gender_ratio *= 255 / 100;
|
|
$gender_ratio = int($gender_ratio);
|
|
if ($gender_ratio > 254) {
|
|
$gender_ratio = 254;
|
|
}
|
|
}
|
|
if ($gender_ratio eq 'MON_FEMALE') {
|
|
$gender_ratio = 254;
|
|
}
|
|
if ($gender_ratio eq 'MON_MALE') {
|
|
$gender_ratio = 0;
|
|
}
|
|
if ($gender_ratio eq 'MON_GENDERLESS') {
|
|
$gender_ratio = 255;
|
|
}
|
|
$species_data{gender_ratio} = $gender_ratio
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
print $fh_output 'our %SPECIES_DATA = %{';
|
|
my $dumper = Data::Dumper::Dumper \%all_species_data;
|
|
chomp($dumper);
|
|
print $fh_output $dumper;
|
|
say $fh_output '};';
|
|
|
|
say $fh_output '1;';
|
|
system 'perltidy', '-b', $output_file;
|
|
1;
|