Get prototype tree (in data stage)

Post Reply
L0laapk3
Inserter
Inserter
Posts: 47
Joined: Sun Mar 18, 2018 10:01 pm
Contact:

Get prototype tree (in data stage)

Post by L0laapk3 »

For some applications, its useful to know the complete prototype hierarchy.

Some use cases: in factorio calculator apps or factoriomaps, if you want to get all the signals types: `item, fluid, virtual`, but if you just iterate over those three from `data.raw`, it will be far from complete. Currently, apart from `item`, you also have to iterate: `"ammo", "capsule", "gun", "item-with-entity-data", "item-with-label", "item-with-inventory", "blueprint-book", "item-with-tags", "selection-tool", "blueprint", "deconstruction-item", "module", "rail-planner", "tool", "armor", "mining-tool", "repair-tool"`.

Currently, the only way to obtain this list is to hardcode it into your mod, and manually update it for every version of the game, which is quite error prone.

It would be nice if there was a function that returned the complete prototype hierarchy similar to the one found on https://wiki.factorio.com/Prototype_definitions.

I'm not sure if there are any applications beyond the data stage, but in the data stage for sure it would be useful.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Get prototype tree (in data stage)

Post by Rseding91 »

All of that information can be gotten runtime through the Lua API: https://lua-api.factorio.com/latest/ for a given prototype type.
If you want to get ahold of me I'm almost always on Discord.

L0laapk3
Inserter
Inserter
Posts: 47
Joined: Sun Mar 18, 2018 10:01 pm
Contact:

Re: Get prototype tree (in data stage)

Post by L0laapk3 »

How would I be able to determine if, for example, "ammo" (or lets say, artillery-shell), is a child of Prototype/Item? I can see that its of type "ammo", but nothing points me towards the fact that this is in fact an item and could be used as, for example, signalID.

The only way that I have been able to determine this is to hardcode a list of children of Prototype/Item for each version of the game. My goal is to do this in the data stage without the error prone process of hardcoding a list for each version of the game.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Get prototype tree (in data stage)

Post by Klonan »

L0laapk3 wrote:
Fri Feb 15, 2019 7:13 pm
How would I be able to determine if, for example, "ammo" (or lets say, artillery-shell), is a child of Prototype/Item? I can see that its of type "ammo", but nothing points me towards the fact that this is in fact an item and could be used as, for example, signalID.

The only way that I have been able to determine this is to hardcode a list of children of Prototype/Item for each version of the game. My goal is to do this in the data stage without the error prone process of hardcoding a list for each version of the game.
What is wrong with using the runtime stage game.item_prototypes ?

L0laapk3
Inserter
Inserter
Posts: 47
Joined: Sun Mar 18, 2018 10:01 pm
Contact:

Re: Get prototype tree (in data stage)

Post by L0laapk3 »

I need information thats only available in the data stage: paths to textures.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Get prototype tree (in data stage)

Post by Bilka »

This (for the purpose of e.g. iterating through all item prototypes) was added as defines.prototypes some time ago.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”