Advertisement
the-vindex

Convert BM ingame docs into readable txt script

Jun 3rd, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.10 KB | None | 0 0
  1. #https://github.com/WayofTime/BloodMagic/blob/master/src/main/resources/assets/alchemicalwizardryBooks/lang/en_US.lang
  2. #!/usb/bin/perl
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6.  
  7. open(F, '<en_US.lang') or die;
  8.  
  9. #structure: {category => $category, entryName=> $entryName, ordinal => $entryNumber, text => $entryText, categoryStart => $categoryStart}
  10. my @entryList;
  11.  
  12. my %translations;
  13. my %categories;
  14.  
  15. my $printEveryLine = 0;
  16. my $printErrors = 0;
  17.  
  18. while(<F>){
  19.     chomp;
  20.     my $line = $_;
  21.     if ( $line eq "" ) {
  22.         next;
  23.     }
  24.     if ($line =~ /^aw\.entries\.([a-zA-Z]*)\.([a-zA-Z0-9]*)(\.(\d*))?=(.*?)$/) {
  25.         my ($category,$entryName,$entryNumber,$entryText) = ($1,$2,$4,$5);
  26.         my $categoryStart = 0;
  27.        
  28.         $entryNumber = 0 if not $entryNumber;
  29.         print "[$category][$entryName].[$entryNumber]=$entryText\n" if $printEveryLine;
  30.        
  31.         if (not $categories{$category}){
  32.             $categoryStart = 1;
  33.             $categories{$category} = 1;
  34.         }
  35.         push @entryList, {category => $category, entryName=> $entryName, ordinal => $entryNumber, text => $entryText, categoryStart => $categoryStart};
  36.     } elsif ($line =~ /^guide\.BloodMagic\.entryName\.([a-zA-Z]*\.[a-zA-Z0-9]*)=(.*)/){
  37.         my ($key,$value) = ($1,$2);
  38.         $translations{$key} = $value;
  39.         print "Translation: $key=$value\n"  if $printEveryLine;
  40.     } elsif ($line =~ /^guide\.BloodMagic\.category\.([a-zA-Z]*)=(.*)/){
  41.         my ($categoryKey,$categoryValue) = ($1,$2);
  42.         $categories{$categoryKey} = $categoryValue;
  43.         print "Category: $categoryKey=$categoryValue\n"  if $printEveryLine;
  44.     }
  45.     else{      
  46.         print "Not matched: $line\n" if $printErrors;
  47.     }
  48. }
  49. close(F);
  50.  
  51. my $categoryDelim = ("=" x 10);
  52.  
  53.  
  54. for my $entry (@entryList){
  55.  
  56.     if ($entry->{categoryStart}){
  57.         my $categoryName = $categories{$entry->{category}};
  58.         print ("\n\n\n$categoryDelim $categoryName $categoryDelim\n");
  59.     }
  60.  
  61.     if (not ($entry->{category}) or not ($entry->{entryName})) {
  62.         print Dumper($entry)  if $printErrors;
  63.     }
  64.     my $entryKey = $entry->{category}.".".$entry->{entryName};
  65.     print "\n\n$translations{$entryKey}\n\n" if ($entry->{ordinal} == 1 || $entry->{ordinal} == 0 );
  66.  
  67.     print "$entry->{text}\n";
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement