I made a recipe planner in python!
DISCLAIMER: I know that there are many amazing factory planners as mods and otherwise, but in the spirit of figuring out/doing everything myself, I figured I would make my own!
I got annoyed with constantly doing math on paper to get the perfect ratios, especially when it came down to factoring in modules, so I wanted a tool that would help me plan out exactly what I need for each quantity of item I wanted to make.
I started off by choosing python and using tkinter because I kind of felt like learning tkinter. I don't regret it, but using something more robust like QT would have made alot of the coding much easier. And my final result much prettier.
Then, I decided to manually import each item into python by painstakingly writing down their properties (e.g., names, crafting times, ingredients, etc.). This was chosen more by stubbornness/laziness than anything, as I am sure I could have imported this information directly from the game files in some way or another. But I was too lazy to figure out how and it was kind of relaxing to listen to music and manually enter in all the information. I haven't finished porting in every ingredient, mainly just the ones required for science are done.
Next, I needed a way to structure the information in an easy to use format. I decided to make an object called a "Plan". a Plan has the following properties:
- Desired Ingredient: the item you want to make together with how many per second
- Recipe: The recipe that you want to use. A recipe is a list of Ingredients
- Building: The building used to make the desired ingredient. A building has a crafting speed as well as potentially having module slots
- Beacon Modules: You can add beacon modules to the plan
Once the plan is set up, it has various functions to calculate helpful amounts, e.g.,
- How many buildings you need to produce the desired amount (taking into account modules, of course)
- How many input ingredients you need
Now that I had a way to represent a single Plan, I wanted a way to customize it further. I wanted to be able to modify all parts of it, e.g., if my plan is advanced circuits, I may want to think about how much iron I need instead of how many electronic circuits I need. To do this, I created a tree-structure called a "PlanNode".
A PlanNode is simply a Plan with a list of children Plans (one for each required ingredient) as well as a parent Plan. With this tree structure, it is very easy to recursively navigate the whole stack of Plans in order to compile handy metrics like the total amount of X ingredient needed to make your desired ingredient.
With that structure done, all I had to do was make (relatively) pretty GUI objects that let me do things like:
- Change the desired ingredient
- Change the recipe used for the ingredient
- Add or remove modules to buildings and beacons
- Show the total amount of input ingredients required (these are the sum of all the leaves of the tree)
- View the sub-ingredients and modify their respective plans
There are still many features to add to make it more polished and have more quality of life features, but overall I am very happy with its current state! The biggest feature that I will be adding next is a way to apply module settings to the entire graph: as it is right now, modules have to be added one by one for each ingredient, which is obviously not too fun for something like space science.
I'm not sure the best way to share this with people, but I uploaded it to git so maybe people can download it if they are curious to try it. If there is a better way let me know. Overall I just thought I would share what I did because I am pretty proud of it. https://github.com/JayJackman/factorio
Here are some images that show it in action! https://imgur.com/a/ChYRsTA
Posted Oct 7, 2022, 1:51 AM UTC · edited
Looks great! How does it perform with complex systems like advanced oil?
Right now it’s ok but not amazing. You can choose the recipes that you want to use for each product that you need, but it doesn’t have any fancy math to figure out what to do with extra outputs. It just adds the extra outputs to the overall outputs and then I can figure out what to do with them. Eventually I want to add a “smart” recipe for things like petroleum where I can do advanced oil cracking and convert the heavy and light down into petroleum. As it stands right now if I choose advanced oil processing I will just have the heavy and light as extra outputs.
I added a picture onto the imgur link so you can see how it looks!
Well it's a great program so far. I'm sure it'll be better as you improve on it over time :)