Advertisement
GauHelldragon

Eco Furniture List Maker

Apr 2nd, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.66 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4.  
  5. $directory = "./Mods/AutoGen/WorldObject";
  6. if ( !opendir( DIR, $directory ) ) { die "Could not open $directory"; }
  7.  
  8. while (readdir DIR) {
  9.     if ( $_ =~ /.+\.cs$/ ) { checkFile("$directory/$_"); } 
  10. }
  11. closedir DIR;
  12.  
  13. @items = sort {
  14.  
  15.     return  $a->{'Category'} cmp $b->{'Category'} ||
  16.             $a->{'TypeForRoomLimit'} cmp $b->{'TypeForRoomLimit'} ||
  17.             $b->{'Val'} <=> $a->{'Val'} ;
  18. } @items;
  19.  
  20. open(OUTPUT,">EcoFurniture.csv") or die "Could not open outputfile\n";
  21. print OUTPUT "Item Type,Name,Value,Diminish\n";
  22. foreach $itemRef ( @items ) {
  23.     %item = %$itemRef;
  24.     if ( $item{'Category'} ne $current ) { print OUTPUT "\n$item{'Category'}\n"; $current = $item{'Category'} }
  25.     print OUTPUT"$item{'TypeForRoomLimit'},$item{'name'},$item{'Val'},$item{'DiminishingReturnPercent'}\n";
  26.    
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. sub checkFile {
  38.     my ( $fileName ) = @_;
  39.     if ( !open(INPUT,"<$fileName") ) {
  40.         print "Could not open $fileName\n";
  41.         return;
  42.     }
  43.     my $isHouseItem = 0;
  44.     my %item = ();
  45.     while (<INPUT>)
  46.     {
  47.         if ( $_ =~ /HousingVal/ ) { $isHouseItem = 1 }
  48.         if ( $_ =~ /public override string FriendlyName \{ get \{ return "(.+)";/ ) { $item{'name'} = $1; }
  49.         if ( $_ =~ /Category = "(.+)"/ ) { $item{'Category'} = $1; }
  50.         if ( $_ =~ /TypeForRoomLimit = "(.+)"/ ) { $item{'TypeForRoomLimit'} = $1; }
  51.         if ( $_ =~ /DiminishingReturnPercent = (.+)f/ ) { $item{'DiminishingReturnPercent'} = $1; }
  52.         if ( $_ =~ /Val = (.+?)f?,/ ) { $item{'Val'} = $1; }
  53.        
  54.        
  55.     }
  56.     #if ( $isHouseItem ) { print "$item{'name'} $item{'Val'} $item{'Category'} $item{'TypeForRoomLimit'} $item{'DiminishingReturnPercent'}\n"; }
  57.     if ( $isHouseItem ) { push(@items,\%item); }
  58.     close INPUT;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement