Advertisement
GauHelldragon

Avorion Goods HTMLmaker

Dec 24th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 10.07 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use warnings;
  3. use YAML;
  4.  
  5. my %hardCoded = (
  6.     "Shipyard" => [ "Energy Tube",
  7.                   "Steel",
  8.                   "Aluminium",
  9.                   "Display",
  10.                   "Metal Plate",
  11.                   "Power Unit",
  12.                   "Antigrav Unit",
  13.                   "Fusion Core",
  14.                   "Wire",
  15.                   "Solar Cell",
  16.                   "Solar Panel",
  17.                   "Plastic" ],
  18.     "Equipment Dock" => [ "Fuel",
  19.                   "Rocket",
  20.                   "Tools",
  21.                   "Laser Compressor",
  22.                   "Display",
  23.                   "Laser Head",
  24.                   "Power Unit",
  25.                   "Antigrav Unit",
  26.                   "Fusion Core",
  27.                   "Wire",
  28.                   "Drill",
  29.                   "Warhead",
  30.                   "Plastic"],
  31.     "Repair Dock" => [ "Energy Tube",
  32.                   "Fuel",
  33.                   "Steel",
  34.                   "Fusion Core",
  35.                   "Display",
  36.                   "Metal Plate",
  37.                   "Power Unit",
  38.                   "Antigrav Unit",
  39.                   "Nanobot",
  40.                   "Processor",
  41.                   "Solar Cell",
  42.                   "Solar Panel",
  43.                   "Plastic"],
  44.     "Military Outpost" => [ "War Robot",
  45.                   "Body Armor",
  46.                   "Vehicle",
  47.                   "Gun",
  48.                   "Ammunition",
  49.                   "Ammunition S",
  50.                   "Ammunition M",
  51.                   "Ammunition L",
  52.                   "Medical Supplies",
  53.                   "Explosive Charge",
  54.                   "Food Bar",
  55.                   "Targeting System"],
  56.     "Research Station" => [ "Turbine",
  57.                   "High Capacity Lens",
  58.                   "Neutron Accelerator",
  59.                   "Electron Accelerator",
  60.                   "Proton Accelerator",
  61.                   "Fusion Generator",
  62.                   "Anti-Grav Generator",
  63.                   "Force Generator",
  64.                   "Teleporter",
  65.                   "Drill",
  66.                   "Satellite"],
  67.     "Biotope" => [
  68.                 "Food",
  69.                 "Food Bar",
  70.                 "Fungus",
  71.                 "Wood",
  72.                 "Glass",
  73.                 "Sheep",
  74.                 "Cattle",
  75.                 "Wheat",
  76.                 "Corn",
  77.                 "Rice",
  78.                 "Vegetable",
  79.                 "Water",
  80.                 "Coal",
  81.                 ],
  82.     "Casino" => [
  83.                 "Beer",
  84.                 "Wine",
  85.                 "Liquor",
  86.                 "Food",
  87.                 "Luxury Food",
  88.                 "Water",
  89.                 "Medical Supplies",
  90.                 ],
  91.     "Habitat" => [
  92.                 "Beer",
  93.                 "Wine",
  94.                 "Liquor",
  95.                 "Food",
  96.                 "Tea",
  97.                 "Luxury Food",
  98.                 "Spices",
  99.                 "Vegetable",
  100.                 "Fruit",
  101.                 "Cocoa",
  102.                 "Coffee",
  103.                 "Wood",
  104.                 "Meat",
  105.                 "Water",
  106.                 ],
  107.     "Turret Factory: Mining Laser" => [
  108.                 "Laser Compressor",
  109.                 "Laser Modulator",
  110.                 "High Capacity Lens",
  111.                 "Conductor",
  112.                 "Steel",
  113.                 ],
  114.     "Turret Factory: Lightning Gun" => [
  115.                 "Military Tesla Coil",
  116.                 "High Capacity Lens",
  117.                 "Electromagnetic Charge",
  118.                 "Conductor",
  119.                 "Copper",
  120.                 "Energy Cell",
  121.                 "Servo",
  122.                 ],
  123.     "Turret Factory: Plasma Gun" => [
  124.                 "Plasma Cell",
  125.                 "Energy Tube",
  126.                 "Conductor",
  127.                 "Energy Container",
  128.                 "Steel",
  129.                 "Crystal",
  130.                 ],
  131.     "Turret Factory: Salvaging Laser" => [
  132.                 "Laser Compressor",
  133.                 "Laser Modulator",
  134.                 "High Capacity Lens",
  135.                 "Conductor",
  136.                 "Steel",
  137.                 ],
  138.     "Turret Factory: Cannon" => [
  139.                 "Servo",
  140.                 "Warhead",
  141.                 "High Pressure Tube",
  142.                 "Explosive Charge",
  143.                 "Steel",
  144.                 "Wire",
  145.                 ],
  146.     "Turret Factory: Chain Gun" => [
  147.                 "Servo",
  148.                 "Steel Tube",
  149.                 "Ammunition S",
  150.                 "Steel",
  151.                 "Aluminium",
  152.                 "Lead",
  153.                 ],
  154.     "Turret Factory: Force Gun" => [
  155.                 "Force Generator",
  156.                 "Energy Inverter",
  157.                 "Energy Tube",
  158.                 "Conductor",
  159.                 "Steel",
  160.                 "Zinc",
  161.                 ],
  162.     "Turret Factory: Rocket Launcher" => [
  163.                 "Servo",
  164.                 "Rocket",
  165.                 "High Pressure Tube",
  166.                 "Fuel",
  167.                 "Targeting Card",
  168.                 "Steel",
  169.                 "Wire",
  170.                 ],
  171.     "Turret Factory: Bolter" => [
  172.                 "Servo",
  173.                 "High Pressure Tube",
  174.                 "Ammunition M",
  175.                 "Explosive Charge",
  176.                 "Steel",
  177.                 "Aluminium",
  178.                 ],
  179.     "Turret Factory: Laser" => [
  180.                 "Laser Head",
  181.                 "Laser Compressor",
  182.                 "High Capacity Lens",
  183.                 "Laser Modulator",
  184.                 "Steel",
  185.                 "Crystal",
  186.                 ],
  187.     "Turret Factory: Rail Gun" => [
  188.                 "Servo",
  189.                 "Electromagnetic Charge",
  190.                 "Electro Magnet",
  191.                 "Gauss Rail",
  192.                 "High Pressure Tube",
  193.                 "Steel",
  194.                 "Copper",
  195.                 ],
  196.     "Turret Factory: Repair Beam" => [
  197.                 "Nanobot",
  198.                 "Transformator",
  199.                 "Laser Modulator",
  200.                 "Conductor",
  201.                 "Gold",
  202.                 "Steel",
  203.                 ],
  204.     "Turret Factory: Tesla Gun" => [
  205.                 "Industrial Tesla Coil",
  206.                 "Electromagnetic Charge",
  207.                 "Energy Inverter",
  208.                 "Conductor",
  209.                 "Copper",
  210.                 "Energy Cell",
  211.                 ]
  212.  
  213. );
  214.  
  215.  
  216.  
  217.  
  218. open(my $DB, "<", "productionsindex.lua") or die "Cannot open DB";
  219.  
  220.  
  221. while ( <$DB> )
  222. {
  223.  
  224.     if ( $_ =~ /factory="(.+)", ingredients=\{(.*)\}, results=\{(.*)\}, garbages=\{(.*)\}\}\)/ ) {
  225.         #$factoryString = $1;
  226.         $ingString = $2;
  227.         #$resultString = $3;
  228.         #$garbageString = $4;
  229.        
  230.         if ( $ingString eq "" ) { next; }
  231.         my (@goods,@ings);
  232.        
  233.         @goods = SepString($3);
  234.         @ings = SepString($2);
  235.         push(@goods,SepString($4));
  236.         my $factoryName = GetName($1,$goods[0]);
  237.         my $htmlName = GetHTMLName($1,$goods[0]);
  238.        
  239.  
  240.        
  241.         foreach $good (@goods) {           
  242.            
  243.             foreach $ing (@ings) {
  244.                 my @fact;
  245.                 if ( ref $goodsList{$good}{"MadeBy"}{$factoryName} ) {
  246.                     @fact = @{$goodsList{$good}{"MadeBy"}{$factoryName}}
  247.                 }
  248.                 push(@fact,$ing);
  249.                 $goodsList{$good}{"MadeBy"}{$factoryName} = \@fact;
  250.             }
  251.             #$goodsList{$good}{"MadeBy"}{$factoryName} = \@ings;
  252.         }
  253.         foreach $good (@ings) {
  254.             my @usedBy;
  255.            
  256.             if ( ref $goodsList{$good}{"UsedBy"} ) {
  257.                 @usedBy = @{$goodsList{$good}{"UsedBy"}};
  258.             }
  259.            
  260.             if ( !grep( /^$htmlName$/, @usedBy ) ) {
  261.                 push(@usedBy,$htmlName);
  262.             }
  263.             $goodsList{$good}{"UsedBy"} = \@usedBy;
  264.         }
  265.        
  266.        
  267.        
  268.         #print( $1 . " *** " . $2 . " *** " . $3 . " *** " . $4 . "\n" );
  269.         #return
  270.     }
  271. }
  272. close($DB);
  273.  
  274.  
  275.  
  276.  
  277. foreach $place ( keys %hardCoded ) {
  278.     print "Adding $place\n";
  279.     foreach $good (@{$hardCoded{$place}}) {
  280.         my @usedBy;
  281.         if ( ref $goodsList{$good}{"UsedBy"} ) {
  282.             @usedBy = @{$goodsList{$good}{"UsedBy"}};
  283.         }
  284.         push(@usedBy,"<b>" . $place . "</b>");
  285.         $goodsList{$good}{"UsedBy"} = \@usedBy;
  286.     }
  287. }
  288.  
  289. open(my $ITEMS, "<", "C:/Program Files (x86)/Steam/SteamApps/common/Avorion/data/scripts/lib/goodsindex.lua") or die ("could not open goodsindex");
  290. while ( <$ITEMS> ) {
  291.     if ( /goods\["(.+?)"\] = .+description="(.*?)".+price=(.+?),.*size=(.+?),.*level=(.+?),/ ) {
  292.         my ($name,$desc,$price,$size,$level) = ($1, $2, $3, $4, $5);
  293.         if ( exists $goodsList{$name} ) {
  294.             $goodsList{$name}{"description"} = $desc;
  295.             $goodsList{$name}{"price"} = $price;
  296.             $goodsList{$name}{"size"} = $size;
  297.             $goodsList{$name}{"level"} = $level;
  298.         }
  299.     }
  300. }
  301. close $ITEMS;
  302.  
  303.  
  304.  
  305. my @sortedGoods = sort { getDensity($a) <=> getDensity($b) } keys(%goodsList);
  306.  
  307. open(my $OUT, ">", "sortgoods.html") or die "Cannot open output";
  308.  
  309. print $OUT "<style> .good {border-style:solid; padding-left:20px;overflow:hidden;}\n";
  310. print $OUT ".info {max-width:250px; margin:0; padding 1em; float:left;}\n";
  311. print $OUT ".production {margin-left:260; padding: 1em;overflow:hidden}\n";
  312. print $OUT "</style>\n";
  313.  
  314. foreach $good (@sortedGoods) {
  315.     print $OUT "<div class=\"good\">\n";
  316.    
  317.    
  318.    
  319.     my $desc = $goodsList{$good}{"description"};
  320.     my $price = $goodsList{$good}{"price"};
  321.     my $size = $goodsList{$good}{"size"};
  322.     my $level = $goodsList{$good}{"level"};
  323.     print $OUT "<div class=\"info\">\n";
  324.     print $OUT "<h3 id=\"$good\">$good</h3>\n";
  325.    
  326.     if ( $desc ) { print $OUT "<p>$desc</p>\n"; }
  327.     else { print "$good has no desc\n"; }
  328.     if ( $level ) { print $OUT "<p><b>Production Tier:</b> $level</p>\n"; }
  329.     if ( $price ) { print $OUT "<p><b>Price:</b> $price</p>\n"; }
  330.     if ( $size ) { print $OUT "<p><b>Volume:</b> $size</p>\n"; }
  331.     if ( $size && $price ) {
  332.         my $per = sprintf("%.1f",$price / $size);
  333.         print $OUT "<p><b>P/V:</b> $per</p>\n";
  334.     }
  335.     print $OUT "</div>\n";
  336.     print $OUT "<div class=\"production\">\n";
  337.    
  338.     if ( exists $goodsList{$good}{"MadeBy"} ) {
  339.         print $OUT "<h4>Made By:</h4>\n<ul>";
  340.         foreach $factory (sort keys %{$goodsList{$good}{"MadeBy"}}) {
  341.             print $OUT "<li>$factory (";
  342.             my ( @ingList, $ing );
  343.             foreach $ing (@{$goodsList{$good}{"MadeBy"}{$factory}}) {
  344.                 push(@ingList,"<a href=\"#$ing\">$ing</a>" )
  345.             }
  346.             print $OUT join(", ",@ingList);
  347.             print $OUT ")</li>\n";
  348.         }
  349.         print $OUT "</ul>\n";
  350.     }
  351.     if ( exists $goodsList{$good}{"UsedBy"} ) {
  352.         print $OUT "<h4>Used By:</h4>\n<ul>";
  353.         foreach $factory ( @{$goodsList{$good}{"UsedBy"}} ) {
  354.             print $OUT "<li>$factory</li>\n";
  355.         }
  356.         print $OUT "</ul>\n";
  357.     }
  358.    
  359.    
  360.     print $OUT "</div></div>\n";
  361.    
  362. }
  363. #print Dump(%hardCoded);
  364. close($OUT);
  365.  
  366.  
  367.  
  368. sub getDensity {
  369.     (my $good) = @_;
  370.     my $price = $goodsList{$good}{"price"};
  371.     my $size = $goodsList{$good}{"size"};
  372.  
  373.     if ( !$price|| !$size ) { return 0; }
  374.     return $price / $size;
  375.  
  376. }
  377.  
  378. sub SepString {
  379.     (my $string) = @_;
  380.     my @retArray;
  381.     while( $string =~ /name=['"](.+?)['"]/g ) {
  382.         push(@retArray,$1);
  383.     }
  384.     return @retArray;
  385. }
  386.  
  387. sub GetName {
  388.     (my $string, my $goodName) = @_;
  389.    
  390.    
  391.    
  392.    
  393.     $string =~ s/ \$\{size\}//;
  394.     $string =~ s/\$\{good\}/$goodName/;
  395.    
  396.    
  397.     if ( exists $goodsList{$goodName}{"MadeBy"}{$string} ) {
  398.         my $newName = $string . " 2";
  399.         my $num = 2;
  400.         while ( exists $goodsList{$goodName}{"MadeBy"}{$newName} ) {
  401.             $num++;
  402.             $newName = $string . " " . $num;
  403.         }
  404.         $string = $newName;
  405.     }
  406.     return $string;
  407. }
  408.  
  409. sub GetHTMLName {
  410.     (my $string, my $goodName) = @_;
  411.     $string =~ s/ \$\{size\}//;
  412.     $string = "<a href=\"#$goodName\">" . $string;
  413.     #$htmlString = "<a href=\"#$goodName\">$goodName";
  414.    
  415.     $string =~ s/\$\{good\}/$goodName/;
  416.     $string = $string . "</a>";
  417.     return $string;
  418.  
  419. }
  420.    
  421. # table.insert(productions, {factory="${good} Manufacturer ${size}", ingredients={{name="Steel", amount=1, optional=0}, {name="Silicium", amount=1, optional=0}, {name="Gold", amount=1, optional=0}, {name="Energy Cell", amount=1, optional=1}}, results={{name="Semi Conductor", amount=15}}, garbages={}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement