Factorio python tooling

Calculate optimal ratios for feeding recipes, search through the research-tree, specialized tools to view game-information.

Factorio python tooling

Postby jcranmer » Sun Sep 11, 2016 1:42 am

So I've started a python library to read Factorio's data, complete with any installed and enabled mods. The library may be found here: https://github.com/jcranmer/factorio-tools. The library also comes with a Flask-based webserver that shows some statistics pages. The webserver itself does almost nothing, merely mapping URLs to either the static page list or a generated image file from the Factorio data files (including from within zipped mods, this is hard to do with command-line tools) or a JSON file representing parsed data. I could generate static pages for a given version (/mod combo), but including the images is risky licensing, and I don't really have accessible webspace at the moment to do any hosting.

Features:
  • schema.json: This file is a mapping of the Lua prototype data to JSON attributes. It notes the names, default values, types, and inheritance hierarchies of various tables. Well, for the properties I've seen fit to include to date. Getting everything added requires tracking down a whole lot of documentation that is missing or plain wrong.
  • ratio.html: This page dumps ratios, for example, saying that 2 electronics circuits to 3 copper cables is an exact ratio. I plan to add configurable maximum numerators/denominators (currently hardcoded to 100) and productivity module ratios later.
  • tech-tree.html: This page dumps a tech-tree in a layered graph representation. The output is admittedly hard-to-read, because I didn't implement all the steps of Sugiyama layout, and there's no way (yet) to highlight only a single node's induced subgraph.

The tool is written in Python, so it's theoretically cross-platform, but I'm almost certainly not matching the right filepaths on Windows or OS X, and Python itself may be hard to install for people on Windows. I'd be happy to share especially the schema.json file with other projects--reading in the Lua files directly and filling in missing properties is hard for the uninitiated. I may look someday at autogenerating Wiki documentation for the Lua prototype schemata, but the information at present is too incomplete to be worth the bother. Other people hacking on this would be much appreciated.
jcranmer
Inserter
Inserter
 
Posts: 39
Joined: Wed Jun 29, 2016 9:59 pm

Re: Factorio python tooling

Postby Fahrradkette » Fri Mar 17, 2017 11:43 pm

I did try it out and was first struggling:

Tried to convert it to python3 since it's something new, so no reason to use python2. The 2to3.py converter worked fine but I had problems with the Lupa dependency.
It turned out that my Lupa lib used luajit which by default targets lua 5.1 but factorio-tools uses lua 5.2. From lua 5.1 to 5.2 they changed package.loaders to package.seachers, used when lua loads modules using require().
Fixed it by uninstalling Lupa and luajit (cba building luajit with the 5.2 switch on), installing liblua5.2 and then reinstalling Lupa again.

Some time ago I also tried to get the recipes using python, I used slpp and did some parsing by hand.
Seems like the lua table->python list and lua table->python dict decision can be tricky sometimes.

factorio-tools did work with "manually added" mods but failed with my current AngelsBobs modpack:
lupa._lupa.LuaError: [string "<python>"]:377: attempt to call global 'floatationpipepictures' (a nil value)

I guess the mods directory only gets discovered 1 level deep. According to the bugtracker, Foreman (that windows-only tool) apparently also has(had?) that problem.

Anyways, I made a graph about how I imagine the required steps, I believe only the orange parts requires Lupa.
Image
Fahrradkette
Inserter
Inserter
 
Posts: 29
Joined: Thu Aug 27, 2015 4:37 pm


Return to Cheatsheets / Calculators / Viewers

Who is online

Users browsing this forum: No registered users and 2 guests