Filter options: game.get_filtered_xxxxx_prototypes(filters)

Things that already exist in the current mod API
Post Reply
Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Filter options: game.get_filtered_xxxxx_prototypes(filters)

Post by Helfima »

I use these methods when I can and it is very cool and faster

Filter group and subgroup:
for example in LuaRecipePrototypeFilters there are 2 filters

Code: Select all

"subgroup": Additional fields:
subgroup :: string: A LuaGroup (subgroup) name
"category": Additional fields:
category :: string: A LuaRecipeCategoryPrototype name
if you want the subgroup list you must parse all recipes before to build the subgroup list when there are lot of recipe is bad, if we can have a subgroup list similar at LuaRecipeCategoryPrototype
Why? there is not filter group for LuaRecipePrototypeFilters (not yet?)
Proposal:
  • add group filter where prototype has group
  • add subgroup filter where prototype has subgroup
  • add a solution to get group and subgroup without table loop to build it
Filter prototype attribut value:
when I try to filter recipes by the contain value in the name of the product or ingredient, it is quickly a problem of performance in lua
if we can have a filter similar at string.find(s, pattern [, index [, plain]])
Proposal:
  • add find filter on string attribut, sample:

    Code: Select all

    "find": Additional fields:
    attribut:: AttributString
    value :: string: The value to find in the attribut.
  • LuaRecipePrototypeFilters, add find product filter on string attribut of a recipe product, sample:

    Code: Select all

    "find_by_product": Additional fields:
    attribut:: AttributString
    value :: string: The value to find in the attribut.
  • LuaRecipePrototypeFilters, add find ingredient filter on string attribut of a recipe ingredient, sample:

    Code: Select all

    "find_by_ingredient": Additional fields:
    attribut:: AttributString
    value :: string: The value to find in the attribut.

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

Re: Filter options: game.get_filtered_xxxxx_prototypes(filters)

Post by Rseding91 »

If you want to get ahold of me I'm almost always on Discord.

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

Re: Filter options: game.get_filtered_xxxxx_prototypes(filters)

Post by Rseding91 »

As for filtering ingredients or products: those don't change runtime and I don't consider them queries you're going to be running frequently. Realistically you'll run them once at game init and once every time after during on_configuration_changed. That isn't a performance concern to me: run the queries build a table and cache it.
If you want to get ahold of me I'm almost always on Discord.

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Filter options: game.get_filtered_xxxxx_prototypes(filters)

Post by Helfima »

here https://lua-api.factorio.com/latest/LuaRecipe.html the recipe have a group and with mod the groups in not the same of item ( i need check that) or i have not understand the group of item it s for all prototype?
i use the recipe.group in my code
cafting.PNG
cafting.PNG (105.06 KiB) Viewed 1415 times
and in the crafting menu the group choose is not subgroup

for several reasons I have build few selectors and when it use in MP with big mod the impact is significant when you parse a big table (>10000 elements), lua is bad on table. few mod use this way. in the profiler i can have value of 10ms when build my cache table and if the user use the filter input i must parse this table 5-10ms in MP you can do x5 and more.
selector.PNG
selector.PNG (744.64 KiB) Viewed 1408 times
my recipe selector is not faster there so much element and it is the parse of the cache table that costs time
for example the form of my cache

Code: Select all

list_products[product.name][group_name][lua_recipe.name]=recipe
I search the faster way to find the recipes that contain a product, is the first key
for information when i write a json of my cache the file do 3Mo :P

Post Reply

Return to “Already exists”