Page 1 of 1

Get prototype tree (in data stage)

Posted: Tue Feb 12, 2019 1:48 pm
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.

Re: Get prototype tree (in data stage)

Posted: Tue Feb 12, 2019 5:36 pm
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.

Re: Get prototype tree (in data stage)

Posted: Fri Feb 15, 2019 7:13 pm
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.

Re: Get prototype tree (in data stage)

Posted: Fri Feb 15, 2019 7:27 pm
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 ?

Re: Get prototype tree (in data stage)

Posted: Fri Feb 15, 2019 8:06 pm
by L0laapk3
I need information thats only available in the data stage: paths to textures.

Re: Get prototype tree (in data stage)

Posted: Fri Nov 03, 2023 10:05 am
by Bilka
This (for the purpose of e.g. iterating through all item prototypes) was added as defines.prototypes some time ago.