Index: source/tools/entity/Entity.pm =================================================================== --- source/tools/entity/Entity.pm +++ source/tools/entity/Entity.pm @@ -129,17 +129,18 @@ sub find_entities { + my ($modName) = @_; my @files; my $find_process = sub { return $File::Find::prune = 1 if $_ eq '.svn'; my $n = $File::Find::name; return if /~$/; return unless -f $_; - $n =~ s~\Q$vfsroot\E/public/simulation/templates/~~; + $n =~ s~\Q$vfsroot\E/$modName/simulation/templates/~~; $n =~ s/\.xml$//; push @files, $n; }; - find({ wanted => $find_process }, "$vfsroot/public/simulation/templates"); + find({ wanted => $find_process }, "$vfsroot/$modName/simulation/templates"); return @files; } Index: source/tools/entity/checkrefs.pl =================================================================== --- source/tools/entity/checkrefs.pl +++ source/tools/entity/checkrefs.pl @@ -4,12 +4,22 @@ use File::Find; use XML::Simple; use JSON; +use Getopt::Long qw(GetOptions); use Entity; -use constant CHECK_MAPS_XML => 0; -use constant ROOT_ACTORS => 1; +GetOptions ( + '--check-map-xml' => \(my $checkMapXml = 0), + '--check-unused' => \(my $checkUnused = 0), + '--validate-templates' => \(my $validateTemplates = 0), + '--root-actors' => \(my $rootActors = 0), +); +use constant CHECK_MAPS_XML => $checkMapXml; +use constant CHECK_UNUSED => $checkUnused; +use constant VALIDATE_TEMPLATES => $validateTemplates; +use constant ROOT_ACTORS => $rootActors; + my @files; my @roots; my @deps; @@ -29,9 +39,8 @@ sub vfs_to_relative_to_mods { - my ($vfspath) = @_; - my $fn = "public/$vfspath"; - return $fn; + my ($vfsPath) = @_; + return "public/$vfsPath"; } sub find_files @@ -47,7 +56,16 @@ $n =~ s~\Q$vfsroot\E/(public|mod)/~~; push @files, $n; }; - find({ wanted => $find_process }, "$vfsroot/public/$vfspath"); + + if("../../../binaries/data/mods/public/gui/modmod/" eq "$vfsroot/public/$vfspath") + { + find({ wanted => $find_process }, "$vfsroot/mod/$vfspath"); + } + else + { + find({ wanted => $find_process }, "$vfsroot/public/$vfspath"); + } + find({ wanted => $find_process }, "$vfsroot/mod/$vfspath") if -d "$vfsroot/mod/$vfspath"; return @files; @@ -147,6 +165,33 @@ } } + +sub add_variants +{ + print "Loading variants...\n"; + my @variantfiles = find_files('art/variants', 'xml'); + + for my $f (sort @variantfiles) + { + push @files, $f; + push @roots, $f if ROOT_ACTORS; + my $variant = XMLin(vfs_to_physical($f), ForceArray => [qw(texture prop animation)], KeyAttr => []) or die "Failed to parse '$f': $!"; + push @deps, [ $f, "art/meshes/$variant->{mesh}" ] if $variant->{mesh}; + for my $tex (@{$variant->{textures}{texture}}) + { + push @deps, [ $f, "art/textures/skins/$tex->{file}" ] if $tex->{file}; + } + for my $prop (@{$variant->{props}{prop}}) + { + push @deps, [ $f, "art/actors/$prop->{actor}" ] if $prop->{actor}; + } + for my $anim (@{$variant->{animations}{animation}}) + { + push @deps, [ $f, "art/animation/$anim->{file}" ] if $anim->{file}; + } + } +} + sub add_art { print "Loading art files...\n"; @@ -193,10 +238,7 @@ push @mapfiles, find_files('maps/skirmishes', 'xml'); for my $f (sort @mapfiles) { - print " $f\n"; - push @files, $f; - push @roots, $f; my $map = XMLin(vfs_to_physical($f), ForceArray => [qw(Entity)], KeyAttr => []) or die "Failed to parse '$f': $!"; @@ -440,9 +482,11 @@ push @roots, $f; my $rms = parse_json_file($f); + if($rms->{settings}{Script}) + { + push @deps, [ $f, "maps/random/" . $rms->{settings}{Script} ]; + } - push @deps, [ $f, "maps/random/" . $rms->{settings}{Script} ]; - # Map previews push @deps, [ $f, "art/textures/ui/session/icons/mappreview/" . $rms->{settings}{Preview} ] if $rms->{settings}{Preview}; } @@ -536,46 +580,42 @@ last if @newreachable == 0; @reachable{@newreachable} = (); } + my $terrains = "public/art/terrains/"; + my $random = "public/maps/random/"; + my $materials = "public/art/materials/"; for my $f (sort @files) { - next if exists $reachable{$f}; - warn "Unused file '" . vfs_to_relative_to_mods($f) . "'\n"; + my $fullPath = vfs_to_relative_to_mods($f); + next if exists $reachable{$f} || ( + index($fullPath, $terrains) != -1 || + index($fullPath, $random) != -1 || + index($fullPath, $materials) != -1); + warn "Unused file '" . $fullPath . "'\n"; } } add_maps_xml() if CHECK_MAPS_XML; - add_maps_pmp(); - add_entities(); - add_actors(); - +add_variants(); add_art(); - add_materials(); - add_particles(); - add_soundgroups(); add_audio(); - add_gui_xml(); add_gui_data(); - add_civs(); - add_rms(); - add_techs(); - add_terrains(); -# TODO: add non-skin textures, and all the references to them - print "\n"; check_deps(); print "\n"; -check_unused(); +check_unused() if CHECK_UNUSED; +print "\n"; +system("perl ../xmlvalidator/validate.pl") if VALIDATE_TEMPLATES; Index: source/tools/entity/entvalidate.pl =================================================================== --- source/tools/entity/entvalidate.pl +++ source/tools/entity/entvalidate.pl @@ -49,7 +49,7 @@ sub check_all { - my @files = Entity::find_entities(); + my @files = Entity::find_entities("public"); my $count = 0; my $failed = 0;