This is a simple Raku script which generates an analysis of each recipe into its component parts, and delivers insight into the balance and progression of a mod.
The .csv files used as input are generated in Factorio, by loading a new game with only ~base~ and your chosen mod enabled, and running the following Lua code:
This is a literate script. The source code is embedded in these code blocks, and tangled into the Raku script using org-babel. This allows me to write a description of what I want to do, and comment on it without resorting to ~// /* */~ ugly comments.
Better yet, I can include [[Lua code generating a .csv file containing all recipes using the items in the whitelist.][links directly to places within the file]] and easily cross-reference what I'm doing with the documentation/ design.
If you open this org file raw (e.g. by clicking [[https://git.bajsicki.com/phil/factorio-recipe-analyzer/raw/branch/main/README.org][here]]), you will see that there are a number of different blocks.
There is a rough overview of the structure:
#+begin_example
,#+name: Name of the following source block.
,#+begin_src raku :tangle file.name
[code goes here]
,#+end_src
#+end_example
~:tangle~ defines the file into which the code block will be passed to ~org-babel-tangle~. To disable, pass ~no~.
In the begging of the file, we can set global (in the scope of the file) properties, such as the default target for ~:tangle~:
~#+PROPERTY: header-args :tangle fra.raku~
The easiest way to generate outputs from here is to open this file in Emacs, and run ~M-x org-babel-tangle~. If you're using [[https://github.com/doomemacs/doomemacs][Doom Emacs]], the default key binding is ~C-c C-v C-t~.
*Important note:* the files in ~./mod-recipes~ are working files. They're not intrinsic parts of the software - they're there primarily for testing and development.
Create an org-mode file with all the calculations included, and complete, for a clear overview of recipe progression, subgroups, item inputs and outputs, and total cost.
For this, we'll likely want to include some metadata, like creation date, mod name, number of ingredients, maybe the total amount of raw mats needed to make one of everything?
** Make a list of products
That's the first column in the .csv file.
Read first column of the csv file and insert it into the .org (output) file.
3. Insert each ingredient and its amount as a separate item
**** Parse the output.org file, filling it out recursively
1. Open .org (output file)
2. Loop over output.org:
1. Find *product section.*
2. Find (next) ingredient lines in this product section.
3. Pass the product and each direct input item and its number to ~raw-ingredients~. /(We can distinguish direct inputs from raw ingredients easily because org-mode supports multiple characters for defining lists. So we can just look for lines beginning with ~-~ and not really think about anything else.)/
This is not for analysis as much as helping Galdoc out with creating compat layers for [[https://github.com/Orion351/galdocs_manufacturing][Galdoc's Manufacturing.]]
Take above csv data dump from Factorio, then:
1. Figure out appropriate categories. This is the starting point we have:
- Telescoping, (inserters, belts, things that reach)
- Metalworking,
- Plastic,
- Wood,
- Stone,
- Glass,
- Electronics.
- And possibly in the future:
- Motors,
- Agriculture,
- Chemicals,
- Small Arms / Equipment.
This has to be done manually. The csv file already includes an empty first column, which lets us manually go over it and add the tags to each item.
2. Then pull the output template CSV file, which should have the following structure:
This structure allows for unambiguous selection of the relevant data from the csv file, for the following reasons:
1. Amounts and categories are paired by the matching number at the end of the column name.
2. These cannot be confused with the amounts themselves, because the column names include [a-zA-Z] characters.
3. The first column makes it easy to find whether an item belongs to a particular column or not.
4. Additionally, this way we can automate creating the output .csv template, since we can check what number of columns we need for each ingredient category.