home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 January / GSSH0104TT.iso / Extras / Tron20 / tron_tools.exe / TRON_Tools / Tools / AssetLists / createAssetLists.pl < prev    next >
Perl Script  |  2003-03-10  |  2KB  |  125 lines

  1. #! /usr/bin/perl
  2. use File::Find;
  3. use File::Path;
  4. use File::Copy;
  5. use Cwd;
  6.  
  7. $ROOT             = "c:/proj/TRON/tools/assetlists";
  8. $ASSETLISTS        = "$ROOT/processing";
  9. $COMPLETE        = "$ROOT/final";
  10.  
  11. # set output to not line-buffered
  12. $| = 1;
  13.  
  14. # Edit the following RegExps to finetune things to filterout
  15. sub filterout {
  16.     my $pat = shift;
  17.  
  18.     # list of rejections
  19.     return 1 if $pat =~ m%^stream/%i;
  20.  
  21.     return 0;
  22. }
  23.  
  24. #
  25. # method for processing each lta file
  26. #
  27. sub process_file {
  28.  
  29.     # return if this is not an log file
  30.     return if ! /\.out$/;
  31.  
  32.     # save so that we can copy it later
  33.     $fileName = $_;
  34.  
  35.     # pull out the worldname
  36.     /^(.*)\.out/;
  37.     $worldName = lc($1);
  38.  
  39.     # clear asset list
  40.     undef @sounds;
  41.     undef @models;
  42.     undef @textures;
  43.     undef @sprites;
  44.  
  45.     # open up this data file
  46.     open (INFILE, "< $File::Find::name") || 
  47.         die "Can't open log file: $File::Find::name\n";
  48.  
  49.     # go through log and generate the per level data
  50.     while (<INFILE>) {
  51.         chop;
  52.  
  53.         # if this is in the filter-out list, then don't add
  54.         next if filterout ($_);
  55.  
  56.         # model
  57.         if (/\.ltb/) {
  58.             push @models, $_;
  59.  
  60.         # sprite
  61.         } elsif (/\.spr/) {
  62.             push @sprites, $_;
  63.  
  64.         # texture
  65.         } elsif (/\.dtx/) {
  66.             push @textures, $_;
  67.  
  68.         # sound
  69.         } elsif (/\.wav/) {
  70.             push @sounds, $_;
  71.         }
  72.     }
  73.     close INFILE;
  74.  
  75.     # open the file for output now
  76.     open (OUTFILE, ">$COMPLETE/$worldName.txt") || 
  77.         die "Can't open output asset list: $worldname\n";
  78.  
  79.     print OUTFILE "/*\n * IMPORTANT: DO NOT EDIT\n";
  80.     print OUTFILE " * these files are automatically generated\n */\n";
  81.  
  82.  
  83.     # output sounds
  84.     print OUTFILE "\n[Sounds]\n";
  85.     $i=0;
  86.     foreach (@sounds) {
  87.         printf( OUTFILE "Sound%03d\t= \"%s\"\n", $i, $_ );
  88.         ++$i;
  89.     }
  90.  
  91.     # output models
  92.     $i=0;
  93.     print OUTFILE "\n[Models]\n";
  94.     foreach (@models) {
  95.         printf( OUTFILE "Model%03d\t= \"%s\"\n", $i, $_ );
  96.         ++$i;
  97.     }
  98.  
  99.     # output textures
  100.     $i=0;
  101.     print OUTFILE "\n[Textures]\n";
  102.     foreach (@textures) {
  103.         printf( OUTFILE "Texture%03d\t= \"%s\"\n", $i, $_ );
  104.         ++$i;
  105.     }
  106.  
  107.     # output sprites
  108.     $i=0;
  109.     print OUTFILE "\n[Sprites]\n";
  110.     foreach (@sprites) {
  111.         printf( OUTFILE "Sprite%03d\t= \"%s\"\n", $i, $_ );
  112.         ++$i;
  113.     }
  114.  
  115.     close OUTFILE;
  116. }
  117.  
  118.  
  119. ###
  120. ### MAIN
  121. ###
  122.  
  123. # find and process all assetlists files
  124. find (\&process_file, $ASSETLISTS);
  125.