update

convert_table_to_dict(table) dict | list

Converts a Lua table to a Python dict. Correctly handles nesting, and interprets Lua arrays as lists.

extract_entities(
lua: LuaRuntime,
draftsman_path: str,
game_version,
sort_tuple,
verbose: bool = False,
) None

Extracts the entities to entities.pkl in draftsman.data.

extract_equipment(
lua: LuaRuntime,
draftsman_path: str,
sort_tuple,
verbose: bool = False,
) None

Extracts equipment to equipment.pkl in draftsman.data.

extract_fluids(
lua: LuaRuntime,
draftsman_path: str,
sort_tuple,
verbose: bool = False,
)

Extracts the fluids to fluids.pkl in draftsman.data.

extract_instruments(
lua: LuaRuntime,
draftsman_path: str,
verbose: bool = False,
)

Extracts the instruments to instruments.pkl in draftsman.data.

extract_items(lua: LuaRuntime, draftsman_path: str, sort_tuple, verbose)

Extracts the items to items.pkl in draftsman.data.

extract_mods(
lua: LuaRuntime,
draftsman_path: str,
verbose: bool = False,
) None

Extract all the mod versions to mods.pkl in draftsman.data.

extract_modules(
lua: LuaRuntime,
draftsman_path: str,
sort_tuple,
verbose: bool = False,
)

Extracts the modules to modules.pkl in draftsman.data.

extract_recipes(
lua: LuaRuntime,
draftsman_path: str,
sort_tuple,
verbose: bool = False,
) None

Extracts the recipes to recipes.pkl in draftsman.data.

extract_signals(
lua: LuaRuntime,
draftsman_path: str,
sort_tuple,
verbose: bool = False,
)

Extracts the signals to signals.pkl in draftsman.data.

extract_tiles(lua: LuaRuntime, draftsman_path: str, verbose: bool = False)

Extracts the tiles to tiles.pkl in draftsman.data.

get_items(lua, game_version: tuple[int, int, int, int])

Gets the loaded items, item subgroups, and item groups. Sorts them and returns them. Saves us the trouble of recalcualting this every time we sort something along item order, which we commonly do.

get_order(objects_to_sort, sort_objects, sort_subgroups, sort_groups)

Sorts the list of objects according to their Factorio order. Attempts to sort by item order first, and defaults to entity order if not present.

Item sort order: (https://forums.factorio.com/viewtopic.php?p=23818#p23818)

  1. object groups

  2. object subgroups

  3. object itself

Across the previous categories, each is sorted by:

  1. the item order string (if present)

  2. the item name (lexographic)

py_search_archive(
mod: Mod,
module_name: str,
package_path: str,
) tuple[str | None, str]

Function called from Lua that checks for a file in a zipfile archive, and returns the contents of the file if found.

Used in the modified Lua require() function that handles special cases to model Factorio’s load pattern. This function is called after normalize_module_name, and expects the name to be it’s result.

run_data_lifecycle(
game_path: str | None = None,
mods_path: str | None = None,
owned_dlc: list[str] = ['space-age'],
no_mods: bool = False,
verbose: bool = False,
show_logs: bool = False,
) LuaRuntime

Runs the entire Factorio data lifecycle, from discovering mods, determining the dependency tree, to executing both the settings and data stages. Returns a Lua instance which contains all of the relevant data to that particular load cycle.

Parameters:
game_path: str | None = None

The path pointing to Factorio’s data, where “official” mods like base and core live.

mods_path: str | None = None

The path pointing to the user mods folder. Also the location where mod-settings.dat and mod-list.json files are searched for and parsed from.

owned_dlc: list[str] = ['space-age']

A list of string names indicating which DLC’s Draftsman should emulate owning, as mods can read this information when deciding their behavior.

no_mods: bool = False

Whether or not to actually use any of the mods at mods_path. Does not omit any “official” mods found at game_path. Useful to quickly toggle modded/unmodded configurations without having to respecify any paths.

verbose: bool = False

Pretty-prints additional status messages and information to stdout.

show_logs: bool = False

If enabled, any log() messages created on the Lua side of things will be printed to stdout. This will happen regardless of the value of verbose.

Returns:

A lupa.LuaRuntime object containing all relevant Lua tables with corresponding data, such as data.raw, mods, etc. that can be parsed.

run_data_stage(
lua: LuaRuntime,
load_order: list[Mod],
base_path: str,
verbose: bool = False,
)

Runs all 3 data stages (data.lua, data-updates.lua, data-final-fixes.lua).

run_mod_phase(
lua: LuaRuntime,
mod: Mod,
stage: str,
) None

Runs one of the mod entry-points for either the settings or the data stage. (settings.lua, data-updates.lua, etc.)

run_settings_stage(
lua: LuaRuntime,
load_order: list[Mod],
mods_path: str,
draftsman_path: str,
base_path: str,
verbose: bool = False,
)

Runs all 3 settings stages (settings.lua, settings-updates.lua, settings-final-fixes.lua). Afterward, the lua data is copied to the correct location that the data stage expects, and any user-defined settings are applied ontop of the default ones.

specify_factorio_version(
game_path: str,
desired_version: str,
verbose: bool = False,
) None

TODO Updates the factorio-data git repository to a specific version tag.

Note that this does not actually update Draftsman’s data; you have to call update_draftsman_data() for that.

Parameters:
game_path: str

Filepath to the git repo to modify. Draftsman’s copy lies within its site-packages installation.

desired_version: str

A string corresponding to the version of the game data desired.

verbose: bool = False

Whether or not to print status messages to stdout for clarity/readability. When false, this function behaves silently.

update_draftsman_data(
game_path: str | None = None,
mods_path: str | None = None,
owned_dlc: list[str] = ['space-age'],
no_mods: bool = False,
verbose: bool = False,
show_logs: bool = False,
) None

Runs the Factorio data lifecycle, and then extracts all of the relevant data that Draftsman needs to operate. The extracted data is written to a set of pickle files located in the draftsman/data folder, wherever it is installed.

If you want to just run the data lifecycle part so that you can extract the game’s data in whatever manner you wish, then instead use run_data_lifecycle().

Parameters:
game_path: str | None = None

The path pointing to Factorio’s data, where “official” mods like base and core live. If omitted, defaults to the factorio-data folder provided in the Draftsman installation location.

mods_path: str | None = None

The path pointing to the user mods folder. Also the location where mod-settings.dat and mod-list.json files are searched for and parsed from. If omitted, defaults to the factorio-mods folder provided in the Draftsman installation location.

owned_dlc: list[str] = ['space-age']

A list of string names indicating which DLC’s Draftsman should emulate owning, as mods can read this information when deciding their behavior.

no_mods: bool = False

Whether or not to actually use any of the mods at mods_path. Does not omit any “official” mods found at game_path. Useful to quickly toggle modded/unmodded configurations without having to respecify any paths.

verbose: bool = False

Pretty-prints additional status messages and information to stdout.

show_logs: bool = False

If enabled, any log() messages created on the Lua side of things will be printed to stdout. This will happen regardless of the value of verbose.