Page 1 of 1

Filters for selection-tool not working as expected

Posted: Thu Jul 07, 2022 3:06 pm
by Pi-C
I've created this selection-tool:

Code: Select all

local tool =  {
  type                                  = "selection-tool",
  name                                  = GCKI.carkey_name,

  entity_filter_mode			= "whitelist",
  entity_type_filters                   = {"car", "spider-vehicle"},
  selection_mode                        = {"entity-with-owner", "avoid-rolling-stock"},
  selection_color                       = {g = 1},
  selection_cursor_box_type             = "entity",
}
data:extend({tool})
In data-final-fixes.lua, I sort out the names of prototypes I want to ignore and add the renaming names to entity_filters:

Code: Select all


local keys = data.raw["selection-tool"][GCKI.carkey_name]
keys.entity_filters = { "name_1", "name_2", "name_3" }
The prototype browser shows that the filters have been applied. However, when I select an area with the tool, the selection includes entities that are based on prototypes not mentioned in keys.entity_filters.

I got the expected result when I removed entity_type_filters. I therefore suspect that tool.entity_filters and tool.entity_type_filters are ORed instead of ANDed (the same applies for alt_entity_filters and alt_entity_type_filters). In my opinion, this behavior is unexpected because it makes the filters more general where they should be more precise.

Re: Filters for selection-tool not working as expected

Posted: Thu Jul 07, 2022 5:16 pm
by Rseding91
Thanks for the report however that's working as intended. If you don't want the filters "ORd" then just delete the entity type filters and use the entity filters.

Re: Filters for selection-tool not working as expected

Posted: Fri Jul 08, 2022 9:27 am
by Pi-C
Rseding91 wrote:
Thu Jul 07, 2022 5:16 pm
Thanks for the report however that's working as intended. If you don't want the filters "ORd" then just delete the entity type filters and use the entity filters.
Thanks for the answer. I realize that things are a bit more complex than I've assumed when writing my report. Deleting the type filters will work in the case I presented (when filters are used in "whitelist" mode) because the list of name filters should include only names of prototypes with the correct type. But that can't work in "blacklist" mode, as it would literally find everything that doesn't match the name pattern.

Why suddenly turning to blacklists? I assume that filtering works like this: You select an area with the selection tool. For each entity found inside the area, you loop over the name list and check if the entity's name matches any name from the list. So it would be of advantage to keep that list as short as possible (speed gain as the maximum number of loop iterations is lower, and increased readability of code and logs). Therefore, if I want to find most of the prototypes in data.raw[proto_type], it should be more efficient to go over a short list of blacklisted names than over a long list of whitelisted names. But blacklisting names only won't work as the filter would call everything with a non-matching name, including things that are of a wrong type. Do you have any suggestion how to deal with that? :-)