Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- @directories = ("./Mods/AutoGen/WorldObject","./Mods/AutoGen/Item","./Mods/AutoGen/Recipe");
- open(OUTPUT,">EcoRecipeList.txt") or die "Could not open outputfile\n";
- foreach $directory ( @directories ) {
- if ( !opendir( DIR, $directory ) ) { die "Could not open $directory"; }
- while (readdir DIR) {
- if ( $_ =~ /.+\.cs$/ ) { addItemFromFile("$directory/$_"); }
- }
- closedir DIR;
- }
- close OUTPUT;
- sub addItemFromFile {
- my ( $fileName ) = @_;
- if ( !open(INPUT,"<$fileName") ) {
- print "Could not open $fileName\n";
- return;
- }
- my @recipe = ();
- my $name = "";
- my $amount = 1;
- my $type;
- while (<INPUT>)
- {
- if ( $_ =~ /this\.Products = new CraftingElement/ ) { $type = "product" }
- if ( $_ =~ /this\.Ingredients = new CraftingElement/ ) { $type = "ingredient" }
- if ( $_ =~ /new CraftingElement<(.+)>\((\d*)\),/ && $type eq "product" && $name eq "" ) { $name = $1; $amount = $2; }
- if ( $_ =~ /new CraftingElement<(.+)>\(typeof\(.+\), (\d+)/ && $type eq "ingredient") { push(@recipe,{'name',$1,'amount',$2}) }
- }
- if ( @recipe > 0 ) {
- my $nameStr = $name;
- if ( $amount > 1 ) { $nameStr = "$name($amount)" }
- print "$name - $nameStr\n";
- print OUTPUT "$nameStr -";
- foreach $hashref ( @recipe ) {
- $name = $$hashref{'name'};
- $amount = $$hashref{'amount'};
- print OUTPUT " $name:$amount"
- }
- print OUTPUT "\n";
- }
- close INPUT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement