Quick push.

This commit is contained in:
Phil Bajsicki 2023-08-24 17:34:51 +02:00
parent 11683ae175
commit db7086f3f8
9 changed files with 12328 additions and 5769 deletions

View file

@ -141,6 +141,7 @@ For each line:
2. Insert second header 2. Insert second header
3. Insert each ingredient and its amount as a separate item 3. Insert each ingredient and its amount as a separate item
**** Parse the output.org file, filling it out recursively **** Parse the output.org file, filling it out recursively
/Note: copied over to another section, this stays here for later./
1. Open .org (output file) 1. Open .org (output file)
2. Loop over output.org: 2. Loop over output.org:
1. Find *product section.* 1. Find *product section.*
@ -220,21 +221,58 @@ This needs to be run manually rn, will figure out an automatic way later? Maybe?
/c /c
local recipes = {} local recipes = {}
for name, recipe in pairs(game.recipe_prototypes) do for name, recipe in pairs(game.recipe_prototypes) do
local products = {}
local ingredients = {} local ingredients = {}
for _, product in pairs(recipe.products) do
local amount = product.amount or product.amount_min .. "-" .. product.amount_max
products[#products+1] = product.name .. ">" .. amount
end
for _, ingredient in pairs(recipe.ingredients) do for _, ingredient in pairs(recipe.ingredients) do
ingredients[#ingredients+1] = ingredient.amount .. "," .. ingredient.name ingredients[#ingredients+1] = ingredient.name .. "<" .. ingredient.amount
end end
recipes[#recipes+1] = "," .. name .. "," .. recipe.subgroup.name .. "," .. table.concat(ingredients, ",") recipes[#recipes+1] = "," .. table.concat(products, "+") .. "," .. name .. "," .. recipe.subgroup.name .. "," .. table.concat(ingredients, "+")
end end
game.write_file("recipes-all.csv", table.concat(recipes, "\n"), false) game.write_file("products-all.csv", table.concat(recipes, "\n"), false)
#+end_src #+end_src
This outputs the following format of csvfile:
#+begin_example
prod1>amt1+prod2>amt2, recipe.name, recipe.subgroup, ingr1<amt1+ingr2<amt2...
#+end_example
#+RESULTS: lua-to-org: Lua script generating a csv file containing all available recipes and their ingredients.
*** Example outputs that we could use:
**** Sorted by recipes:
| Galdoc's groups | recipe-name | subgroup | prod1 | prod2 | prod... | ingr1 | ingr2 | ingr... | | | |
|-----------------+-------------+----------+--------------+-------+---------+------------+-------+---------+---+---+---|
| metal | iron-plate | | iron-plate:1 | | | iron-ore:1 | | | | | |
| wood | | | | | | | | | | | |
| plastic | | | | | | | | | | | |
| glass | | | | | | | | | | | |
| stone | | | | | | | | | | | |
**** Sorted by products:
- One line per product, each product getting its own copy of all the recipes that make it (gg slag).
- Each product gets assigned a clear category. No issues, no conflicts.
- Problem: differing amounts between the recipes, so amounts need to be stated in a sep. column.
- If we use an unusual separator symbol for fields with more than one value (e.g. long lists of ingredients), we can then parse them very easily and remove ambiguity with a simple [whitespace, comma or +] test. Then situations like 'tin' being found in 'tinned wire' won't be a problem.
| Galdoc's groups | product | amount | subgroup | recipe | required building | | ingr1 | ingr2 | ingr... | | | |
|-----------------+------------+--------+----------+------------+----------------------------------------------+---+------------+-------+---------+---+---+---|
| metal | iron-plate | 1 | | iron-plate | stone-furnace+steel-furnace+electric-furnace | | iron-ore:1 | | | | | |
| wood | | | | | | | | | | | | |
| plastic | | | | | | | | | | | | |
| glass | | | | | | | | | | | | |
| stone | | | | | | | | | | | | |
*** Move csv to the right directory *** Move csv to the right directory
/Note:/ If you have this open in Emacs, move your cursor into the code block and hit ~C-c C-c~ to execute the code. It's very handy if you have commands that you use often. /Note:/ If you have this open in Emacs, move your cursor into the code block and hit ~C-c C-c~ to execute the code. It's very handy if you have commands that you use often.
#+name: move the output from the above command to the mod-recipes directory for easy access. #+name: move the output from the above command to the mod-recipes directory for easy access.
#+begin_src sh :results none #+begin_src sh :results none
mv ~/.factorio/script-output/recipes-all.csv ./mod-recipes mv ~/.factorio/script-output/products-all.csv ./mod-recipes
#+end_src #+end_src
*** Sort for easier human readability *** Sort for easier human readability
**** Sort the csv file by recipe subgroups **** Sort the csv file by recipe subgroups
@ -246,7 +284,7 @@ cat ./mod-recipes/recipes-all.csv | sort -k3 -t, | column --table -s, -o, > ./mo
**** Sort the csv file by product name **** Sort the csv file by product name
This allows us to find similarly named items easier This allows us to find similarly named items easier
#+begin_src sh :results none #+begin_src sh :results none
cat ./mod-recipes/recipes-all.csv | sort -k2 -t, | column --table -s, -o, > ./mod-recipes/recipes-all-sorted-product.csv cat ./mod-recipes/products-all.csv | sort -k2 -t, | column --table -s, -o, > ./mod-recipes/recipes-all-sorted-product.csv
#+end_src #+end_src
This is the file we'll be using for further testing, because it groups up a lot of items by material, which is what we want. This is the file we'll be using for further testing, because it groups up a lot of items by material, which is what we want.
@ -258,6 +296,36 @@ cp ./mod-recipes/recipes-all-sorted-product.csv ./mod-recipes/intermediate.csv
#+end_src #+end_src
From here on, all changes will take place on the basis of the ~intermediate.csv~ file, and outputs will be directed to ~output.csv~. This will prevent time loss in case of a mistyped command. From here on, all changes will take place on the basis of the ~intermediate.csv~ file, and outputs will be directed to ~output.csv~. This will prevent time loss in case of a mistyped command.
*** Parse the intermetiate.csv file, filling it out recursively
#+begin_src perl :tangle raw.pl
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv";
open(my $out, ">", "./mod-recipes/raw.csv") or die "Can't open raw.csv";
local $| = 1;
raw_ingredients();
sub raw_ingredients () {
$product = $ARGV[1];
while (<$in>){
@line = split(",", $_);
if ($line[1] == $product) {
print "ingredients $line[4]\n";
@ingredients = split(/\+/, $line[4]);
print "\t\@ingredients: @ingredients \n";
foreach my $ingredient (@ingredients) {
print "\t\t\$ingredient: $ingredient\n";
raw_ingredients($ingredient);
print "\t\t\trecurring! \$ingredient = $ingredient\n";
}
}
else {
continue;
}
}
}
#+end_src
*** Define raw ingredients by their category *** Define raw ingredients by their category
@ -268,7 +336,7 @@ From here on, all changes will take place on the basis of the ~intermediate.csv~
- Wood, - Wood,
- Stone, - Stone,
- Glass, - Glass,
- Electronics. - Electronics,
At the same time, we have 2843 entries to deal with. That's a lot, so let's start with the raw ingredients, and assign those using the following rough rules: At the same time, we have 2843 entries to deal with. That's a lot, so let's start with the raw ingredients, and assign those using the following rough rules:
For this reason, it is important that we first cover the base materials. For this reason, it is important that we first cover the base materials.
@ -276,96 +344,82 @@ For this reason, it is important that we first cover the base materials.
1. If the item exists in vanilla as a raw ingredient, it should be treated as such in the compatibility layer as well. If it is made craftable by a mod, its ingredients must also be tagged as raw materials. 1. If the item exists in vanilla as a raw ingredient, it should be treated as such in the compatibility layer as well. If it is made craftable by a mod, its ingredients must also be tagged as raw materials.
2. The ingredient in question may not have a recipe of its own. E.g. iron ore in vanilla Factorio, or stiratite in AngelBob. In this case, it is a raw ingredient. 2. The ingredient in question may not have a recipe of its own. E.g. iron ore in vanilla Factorio, or stiratite in AngelBob. In this case, it is a raw ingredient.
**** Metals **** Temp code:
The following code should:
1. Find all the items which stem from iron ore *only*.
2. Add 'metal' to the first field of their line in the CSV.
To do this, we'll start with something like this:
#+begin_src perl :tangle fra.pl #+begin_src perl :tangle fra.pl
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv";
open(my $out, ">", "./mod-recipes/output.csv") or die "Can't open output.csv";
my @patterns = ( our @patterns = (
# 0 metal # 0 metal
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (bronze|iron|steel|copper|
zinc| tungsten|titanium|tin|\ zinc|lithium|tungsten|titanium|tin|
nickel|silver|platinum|manganese|\ nickel|silver|platinum|manganese|
lead|gold|aluminium|aluminum)\ lead|gold|aluminium|aluminum)
[\-?,?\s*]/", [\-?,?\s*]/",
# 1 wood # 1 wood
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (seedlings|wood|wooden)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 2 plastic # 2 plastic
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (plastic)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 3 electronics # 3 electronics
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (electronic)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 4 glass # 4 glass
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (glass)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 5 stone # 5 stone
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (limestone|stone|slag|concrete|sand)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/"); [\-?,?\s*]/");
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv";
open(my $out, ">", "./mod-recipes/output.csv") or die "Can't open output.csv";
while (<$in>) { while (<$in>) {
@line = split(",", $_); my @line = split(",", $_);
if ($line[1] =~ "$patterns[0]") { if ($line[1] =~ "$patterns[0]") {
print $out "metal @line"; print $out "metal @line";
print "$patterns[0]";
print "metal @line";
} }
if ($line[1] =~ "$patterns[1]") { elsif ($line[1] =~ "$patterns[1]") {
print $out "wood @line"; print $out "wood @line";
} }
if ($line[1] =~ "$patterns[2]") { elsif ($line[1] =~ "$patterns[2]") {
print $out "plastic @line"; print $out "plastic @line";
} }
if ($line[1] =~ "$patterns[3]") { elsif ($line[1] =~ "$patterns[3]") {
print $out "electronics @line"; print $out "electronics @line";
} }
if ($line[1] =~ "$patterns[4]") { elsif ($line[1] =~ "$patterns[4]") {
print $out "glass @line"; print $out "glass @line";
} }
if ($line[1] =~ "$patterns[5]") { elsif ($line[1] =~ "$patterns[5]") {
print $out "stone @line"; print $out "stone @line";
} }
else { else {
print $out "@line"; print $out "@line";
} print "@line";
} }
} }
close $in or die "$in: $!"; close $in or die "$in: $!";

58
fra.pl
View file

@ -1,86 +1,74 @@
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv"; our @patterns = (
open(my $out, ">", "./mod-recipes/output.csv") or die "Can't open output.csv";
my @patterns = (
# 0 metal # 0 metal
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (bronze|iron|steel|copper|
zinc| tungsten|titanium|tin|\ zinc|lithium|tungsten|titanium|tin|
nickel|silver|platinum|manganese|\ nickel|silver|platinum|manganese|
lead|gold|aluminium|aluminum)\ lead|gold|aluminium|aluminum)
[\-?,?\s*]/", [\-?,?\s*]/",
# 1 wood # 1 wood
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (seedlings|wood|wooden)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 2 plastic # 2 plastic
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (plastic)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 3 electronics # 3 electronics
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (electronic)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 4 glass # 4 glass
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (glass)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/", [\-?,?\s*]/",
# 5 stone # 5 stone
"m/[\-?,?s*] "m/[\-?,?s*]
(bronze|iron|steel|copper|\ (limestone|stone|slag|concrete|sand)
zinc| tungsten|titanium|tin|\
nickel|silver|platinum|manganese|\
lead|gold|aluminium|aluminum)\
[\-?,?\s*]/"); [\-?,?\s*]/");
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv";
open(my $out, ">", "./mod-recipes/output.csv") or die "Can't open output.csv";
while (<$in>) { while (<$in>) {
@line = split(",", $_); my @line = split(",", $_);
if ($line[1] =~ "$patterns[0]") { if ($line[1] =~ "$patterns[0]") {
print $out "metal @line"; print $out "metal @line";
print "$patterns[0]";
print "metal @line";
} }
if ($line[1] =~ "$patterns[1]") { elsif ($line[1] =~ "$patterns[1]") {
print $out "wood @line"; print $out "wood @line";
} }
if ($line[1] =~ "$patterns[2]") { elsif ($line[1] =~ "$patterns[2]") {
print $out "plastic @line"; print $out "plastic @line";
} }
if ($line[1] =~ "$patterns[3]") { elsif ($line[1] =~ "$patterns[3]") {
print $out "electronics @line"; print $out "electronics @line";
} }
if ($line[1] =~ "$patterns[4]") { elsif ($line[1] =~ "$patterns[4]") {
print $out "glass @line"; print $out "glass @line";
} }
if ($line[1] =~ "$patterns[5]") { elsif ($line[1] =~ "$patterns[5]") {
print $out "stone @line"; print $out "stone @line";
} }
else { else {
print $out "@line"; print $out "@line";
} print "@line";
} }
} }
close $in or die "$in: $!"; close $in or die "$in: $!";

7
fra.py Normal file
View file

@ -0,0 +1,7 @@
mv ~/.factorio/script-output/products-all.csv ./mod-recipes
cat ./mod-recipes/recipes-all.csv | sort -k3 -t, | column --table -s, -o, > ./mod-recipes/recipes-all-sorted-subgroups.csv
cat ./mod-recipes/products-all.csv | sort -k2 -t, | column --table -s, -o, > ./mod-recipes/recipes-all-sorted-product.csv
cp ./mod-recipes/recipes-all-sorted-product.csv ./mod-recipes/intermediate.csv

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

3110
mod-recipes/products-all.csv Normal file

File diff suppressed because it is too large Load diff

0
mod-recipes/raw.csv Normal file
View file

File diff suppressed because it is too large Load diff

24
raw.pl Normal file
View file

@ -0,0 +1,24 @@
open(my $in, "<", "./mod-recipes/intermediate.csv") or die "Can't open intermediates.csv";
open(my $out, ">", "./mod-recipes/raw.csv") or die "Can't open raw.csv";
raw_ingredients();
sub raw_ingredients () {
$product = $ARGV[1];
while (<$in>){
@line = split(",", $_);
if ($line[1] == $product) {
print "ingredients $line[4]\n";
@ingredients = split(/\+/, $line[4]);
print "\t\@ingredients: @ingredients \n";
foreach my $ingredient (@ingredients) {
print "\t\t\$ingredient: $ingredient\n";
raw_ingredients($ingredient);
print "\t\t\trecurring! \$ingredient = $ingredient\n";
}
}
else {
continue;
}
}
}