Advertisement
GauHelldragon

Eco Recipe List Maker

Apr 2nd, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.41 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4.  
  5. @directories = ("./Mods/AutoGen/WorldObject","./Mods/AutoGen/Item","./Mods/AutoGen/Recipe");
  6.  
  7.  
  8.  
  9. open(OUTPUT,">EcoRecipeList.txt") or die "Could not open outputfile\n";
  10. foreach $directory ( @directories ) {
  11.     if ( !opendir( DIR, $directory ) ) { die "Could not open $directory"; }
  12.    
  13.    
  14.     while (readdir DIR) {
  15.         if ( $_ =~ /.+\.cs$/ ) { addItemFromFile("$directory/$_"); }   
  16.     }
  17.     closedir DIR;
  18.    
  19. }
  20. close OUTPUT;
  21.  
  22. sub addItemFromFile {
  23.     my ( $fileName ) = @_;
  24.     if ( !open(INPUT,"<$fileName") ) {
  25.         print "Could not open $fileName\n";
  26.         return;
  27.     }
  28.     my @recipe = ();
  29.     my $name = "";
  30.     my $amount = 1;
  31.     my $type;
  32.     while (<INPUT>)
  33.     {
  34.         if ( $_ =~ /this\.Products = new CraftingElement/ ) { $type = "product" }
  35.         if ( $_ =~ /this\.Ingredients = new CraftingElement/ ) { $type = "ingredient" }
  36.         if ( $_ =~ /new CraftingElement<(.+)>\((\d*)\),/ && $type eq "product" && $name eq "" ) { $name = $1; $amount = $2; }
  37.         if ( $_ =~ /new CraftingElement<(.+)>\(typeof\(.+\), (\d+)/ && $type eq "ingredient") { push(@recipe,{'name',$1,'amount',$2}) }
  38.     }
  39.     if ( @recipe > 0 ) {
  40.        
  41.         my $nameStr = $name;
  42.         if ( $amount > 1 ) { $nameStr = "$name($amount)" }
  43.         print "$name - $nameStr\n";
  44.         print OUTPUT "$nameStr -";
  45.         foreach $hashref ( @recipe ) {
  46.             $name = $$hashref{'name'};
  47.             $amount = $$hashref{'amount'};
  48.             print OUTPUT " $name:$amount"
  49.         }
  50.         print OUTPUT "\n";
  51.     }
  52.     close INPUT;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement