jjakkes-fernando-game/check_all_tomls.pl

82 lines
2.2 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
# this 'check_all_tomls.pl' is licensed under the GPL3, see LICENSE file for more details.
# if LICENSE isn't available, see < https://www.gnu.org/licenses/gpl-3.0.en.html >
#
# this just evals every toml file and reports non-compile-able/non-runtime-able/invalid toml files.
# not a perfect solution but will make sure you're shit isn't totally broken
use strict;
use warnings;
use v5.12; # readdir in while-loop
use TOML;
use File::Slurper qw(read_text write_text);
#use Carp::Always;
my ($game_config, $game_items, $battlers, $err);
($game_config, $err) = from_toml(read_text('./game.pl.toml'));
if ($err) {
die $err;
}
($game_items, $err) = from_toml(read_text('./assets/GAME_ITEMS.toml'));
if ($err) {
die $err;
}
($battlers, $err) = from_toml(read_text('./assets/BATTLERS.toml'));
if ($err) {
die $err;
}
# try to load global values by default; some toml scripts might touch them
my $player = $game_config->{newgame_player};
my $f_y = $game_config->{newgame_y};
my $f_x = $game_config->{newgame_x};
my $dialog_mode = 0;
my $menu_mode = 0;
my $battle_mode = 0;
my $hp = $game_config->{newgame_hp};
my $max_hp = $game_config->{newgame_max_hp};
my $atk = $game_config->{newgame_atk};
my $def = $game_config->{newgame_def};
my $lvl = $game_config->{newgame_lvl};
my $class = $game_config->{newgame_class};
my $hands = $game_config->{newgame_hands};
my $armor = $game_config->{newgame_armor};
my $curr_map = $game_config->{newgame_map};
my @inventory = @{ $game_config->{newgame_inventory} };
my %game_vars;
my %npcs;
my %journal;
opendir my $dh, './assets' or die 'lol lmao fucking dumbass';
while (my $file = readdir $dh) {
next if (substr ($file, -4, 4) ne 'toml');
my ($toml, $err) = from_toml(read_text("./assets/$file"));
if ($err) {
say "toml $file error:\n$err";
}
## no critic (eval)
eval $toml->{map_script} if $toml->{map_script};
if ($@) {
say "$file (map_script)\n$@";
}
for (sort keys %{ $toml->{objects} }) {
eval $toml->{objects}->{$_};
if ($@) {
say "$file $_ (object)\n$@";
}
}
}
closedir $dh;
# don't report subroutines that game.pl has
sub teleport {};
sub dialog {};
sub item {};
sub addch {}; # Curses specific subroutine
sub quest {};