Quick push.
This commit is contained in:
parent
11683ae175
commit
db7086f3f8
9 changed files with 12328 additions and 5769 deletions
148
README.org
148
README.org
|
@ -141,6 +141,7 @@ For each line:
|
|||
2. Insert second header
|
||||
3. Insert each ingredient and its amount as a separate item
|
||||
**** 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)
|
||||
2. Loop over output.org:
|
||||
1. Find *product section.*
|
||||
|
@ -220,21 +221,58 @@ This needs to be run manually rn, will figure out an automatic way later? Maybe?
|
|||
/c
|
||||
local recipes = {}
|
||||
for name, recipe in pairs(game.recipe_prototypes) do
|
||||
local products = {}
|
||||
local ingredients = {}
|
||||
for _, ingredient in pairs(recipe.ingredients) do
|
||||
ingredients[#ingredients+1] = ingredient.amount .. "," .. ingredient.name
|
||||
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
|
||||
recipes[#recipes+1] = "," .. name .. "," .. recipe.subgroup.name .. "," .. table.concat(ingredients, ",")
|
||||
for _, ingredient in pairs(recipe.ingredients) do
|
||||
ingredients[#ingredients+1] = ingredient.name .. "<" .. ingredient.amount
|
||||
end
|
||||
recipes[#recipes+1] = "," .. table.concat(products, "+") .. "," .. name .. "," .. recipe.subgroup.name .. "," .. table.concat(ingredients, "+")
|
||||
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
|
||||
|
||||
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
|
||||
/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.
|
||||
#+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
|
||||
*** Sort for easier human readability
|
||||
**** 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
|
||||
This allows us to find similarly named items easier
|
||||
#+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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
@ -268,7 +336,7 @@ From here on, all changes will take place on the basis of the ~intermediate.csv~
|
|||
- Wood,
|
||||
- Stone,
|
||||
- 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:
|
||||
For this reason, it is important that we first cover the base materials.
|
||||
|
@ -276,98 +344,84 @@ 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.
|
||||
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
|
||||
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.
|
||||
**** Temp code:
|
||||
|
||||
|
||||
To do this, we'll start with something like this:
|
||||
#+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
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(bronze|iron|steel|copper|
|
||||
zinc|lithium|tungsten|titanium|tin|
|
||||
nickel|silver|platinum|manganese|
|
||||
lead|gold|aluminium|aluminum)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 1 wood
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(seedlings|wood|wooden)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 2 plastic
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(plastic)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 3 electronics
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(electronic)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 4 glass
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(glass)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 5 stone
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(limestone|stone|slag|concrete|sand)
|
||||
[\-?,?\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>) {
|
||||
@line = split(",", $_);
|
||||
my @line = split(",", $_);
|
||||
|
||||
if ($line[1] =~ "$patterns[0]") {
|
||||
print $out "metal @line";
|
||||
print "$patterns[0]";
|
||||
print "metal @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[1]") {
|
||||
elsif ($line[1] =~ "$patterns[1]") {
|
||||
print $out "wood @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[2]") {
|
||||
elsif ($line[1] =~ "$patterns[2]") {
|
||||
print $out "plastic @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[3]") {
|
||||
elsif ($line[1] =~ "$patterns[3]") {
|
||||
print $out "electronics @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[4]") {
|
||||
elsif ($line[1] =~ "$patterns[4]") {
|
||||
print $out "glass @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[5]") {
|
||||
elsif ($line[1] =~ "$patterns[5]") {
|
||||
print $out "stone @line";
|
||||
}
|
||||
else {
|
||||
print $out "@line";
|
||||
print "@line";
|
||||
}
|
||||
}
|
||||
}
|
||||
close $in or die "$in: $!";
|
||||
close $out or die "$out: $!";
|
||||
#+end_src
|
||||
|
|
58
fra.pl
58
fra.pl
|
@ -1,87 +1,75 @@
|
|||
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
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(bronze|iron|steel|copper|
|
||||
zinc|lithium|tungsten|titanium|tin|
|
||||
nickel|silver|platinum|manganese|
|
||||
lead|gold|aluminium|aluminum)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 1 wood
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(seedlings|wood|wooden)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 2 plastic
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(plastic)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 3 electronics
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(electronic)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 4 glass
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(glass)
|
||||
[\-?,?\s*]/",
|
||||
|
||||
# 5 stone
|
||||
|
||||
"m/[\-?,?s*]
|
||||
(bronze|iron|steel|copper|\
|
||||
zinc| tungsten|titanium|tin|\
|
||||
nickel|silver|platinum|manganese|\
|
||||
lead|gold|aluminium|aluminum)\
|
||||
(limestone|stone|slag|concrete|sand)
|
||||
[\-?,?\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>) {
|
||||
@line = split(",", $_);
|
||||
my @line = split(",", $_);
|
||||
|
||||
if ($line[1] =~ "$patterns[0]") {
|
||||
print $out "metal @line";
|
||||
print "$patterns[0]";
|
||||
print "metal @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[1]") {
|
||||
elsif ($line[1] =~ "$patterns[1]") {
|
||||
print $out "wood @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[2]") {
|
||||
elsif ($line[1] =~ "$patterns[2]") {
|
||||
print $out "plastic @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[3]") {
|
||||
elsif ($line[1] =~ "$patterns[3]") {
|
||||
print $out "electronics @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[4]") {
|
||||
elsif ($line[1] =~ "$patterns[4]") {
|
||||
print $out "glass @line";
|
||||
}
|
||||
if ($line[1] =~ "$patterns[5]") {
|
||||
elsif ($line[1] =~ "$patterns[5]") {
|
||||
print $out "stone @line";
|
||||
}
|
||||
else {
|
||||
print $out "@line";
|
||||
print "@line";
|
||||
}
|
||||
}
|
||||
}
|
||||
close $in or die "$in: $!";
|
||||
close $out or die "$out: $!";
|
||||
|
|
7
fra.py
Normal file
7
fra.py
Normal 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
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
0
mod-recipes/raw.csv
Normal file
|
File diff suppressed because it is too large
Load diff
24
raw.pl
Normal file
24
raw.pl
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue