Rsaves/populate_moves.pl

55 lines
1.1 KiB
Perl

#!/usr/bin/env perl
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use Path::Tiny;
my $is_on_move = 0;
my $current_directory = path(__FILE__)->parent;
my $output_file = $current_directory->child('lib/Rsaves/Constants/MoveAttributes.pm');
open my $output, '>', $output_file;
open my $fh, '<', '/home/sergio/pokeruby/src/data/battle_moves.c';
my $move;
print $output <<'EOF';
package Rsaves::Constants::MoveAttributes;
use v5.36.0;
use strict;
use warnings;
use Rsaves::Constants::Global;
use parent 'Exporter';
my $move_attributes = [];
EOF
while (my $line = <$fh>) {
if ($line =~ /\[(\w+)\]\s+=\s+\{/) {
$is_on_move = 1;
$move = $1;
next;
}
next if !$is_on_move;
if ($line =~ /\.pp = (\d+)/) {
print $output "\$move_attributes->[\$Rsaves::Constants::Global::${move}]{pp} = $1;\n";
}
}
close $fh;
print $output <<'EOF';
sub get_move_attributes($move_identifier) {
return $move_attributes->[$move_identifier];
}
our @EXPORT_OK = (qw/get_move_attributes/);
EOF
close $output;
system 'perltidy', '-b', $output_file;