Code: Select all
local ItemPrototypeTypes =
{
["item"] = true,
["ammo"] = true,
["capsule"] = true,
["gun"] = true,
["item-with-entity-data"] = true,
["item-with-label"] = true,
--theres 20 lines of this.. and this is just for items, there's another for entities
}
local function FindPrototypeFromTypeSet(prototypeName, typeSet)
for prototypeType, _ in pairs(typeSet) do
local prototype = data.raw[prototypeType][prototypeName]
if prototype ~= nil then
return prototype
end
end
return nil
end
I propose a new define: defines.prototypeTypes, which is a tree mapping all prototype types to a table of their child types, and so on recursively, similar to the tree structure on the wiki.
As an example, defines.prototypeTypes["item"] would look like this:
Code: Select all
defines.prototypeTypes["item"] = {
["ammo"] = {},
["capsule"] = {},
["gun"] = {},
["item-with-entity-data"] = {},
["item-with-label"] = {
["item-with-inventory"] = {
["blueprint-book"] = {},
},
["item-with-tags"] = {},
["selection-tool"] = {
["blueprint"] = {},
["copy-paste-tool"] = {},
["deconstruction-item"] = {},
["upgrade-item"] = {},
},
},
["module"] = {},
["rail-planner"] = {},
["tool"] = {
["armor"] = {},
["mining-tool"] = {},
["repair-tool"] = {},
},
}
By parsing this define, modders can make cached tables for their specific needs, and be assured that it will remain up to date.
Another use that this could solve is knowing whether an entity/item inherits a certain type. If I want to read an item's tags, but I'm not sure if it is an ItemWithTags, I could check its type in the tree to know whether or not calling get_tag would throw an error.
I tried making this myself with source access, but the game doesn't have a list of of all prototype types, nor a list of every prototype (you have to already know the type), so a more involved solution would have to be made.