Jump to content

How to tell if a part will be visible in the editor


Recommended Posts

Before you say "category = none", the issue is at hand is that the category is no longer a reliable method of determining visibility with the proliferation of custom subcategories, hence my issue.

Stock parts are no problem, I can easily filter those out by name. However, I know in the past there has been some mods which have used dummy parts for various reasons that also shouldn't be visible in the editor. I was wondering if the existing dummy parts share a common attribute that I can check to prevent them being visible in the editor categories.

1) What mods make use of these dummy parts?

2) What common attributes are likely to set them apart from parts that should be visible?

Link to comment
Share on other sites

I'm fairly sure you're going to have to loop through all the subcategory filters and idewntify the parts that never show up. You could optimize that by simply keeping the list of parts that didn't show up yet from the whole list of known parts. Beucase there's no flag for an invisible parts. There are only filters for the parts :/

Link to comment
Share on other sites

That is the method of last resort which is looking increasingly likely the more I look into this. Optimising it isn't really an issue, it's just a really awkward way to do things (and prone to issues when people do something unexpected)

Link to comment
Share on other sites

Incase anyone else ever needs this

public static HashSet<string> blackListedParts;
void Init() {
///
if (blackListedParts == null)
findPartsToBlock();
///
}

void findPartsToBlock()
{
[COLOR=#008000] // all parts that may not be visible[/COLOR]
List<AvailablePart> partsToCheck = PartLoader.Instance.parts.FindAll(ap => ap.category == PartCategories.none);
[COLOR=#008000] // Only checking the category which should be Filter by Function[/COLOR]
PartCategorizer.Category mainCat = PartCategorizer.Instance.filters[0];
[COLOR=#008000] // has a reference to all the subcats that FE added to the category[/COLOR]
customCategory customMainCat = Core.Instance.Categories.Find(C => C.categoryName == mainCat.button.categoryName);
[COLOR=#008000] // loop through the subcategories. Mark FE ones as seen incase of duplication and check the parts in mod categories for visibility[/COLOR]
HashSet<string> subCatsSeen = new HashSet<string>();
for (int i = 0; i < mainCat.subcategories.Count; i++)
{
PartCategorizer.Category subCat = mainCat.subcategories[i];
[COLOR=#008000] // if the name is an FE subcat and the category should have that FE subcat and it's not the duplicate of one already seen created by another mod, mark it seen and move on[/COLOR]
if (Core.Instance.subCategoriesDict.ContainsKey(subCat.button.categoryName) && customMainCat.subCategories.Contains(subCat.button.categoryName) && !subCatsSeen.Contains(subCat.button.categoryName))
subCatsSeen.Add(subCat.button.categoryName);
else[COLOR=#008000] // subcat created by another mod[/COLOR]
{
[COLOR=#008000] // can't remove parts from a collection being looped over, need to remember the visible parts[/COLOR]
List<AvailablePart> visibleParts = new List<AvailablePart>();
for (int j = 0; j < partsToCheck.Count; j++)
{
AvailablePart AP = partsToCheck[j];
if (subCat.exclusionFilter.FilterCriteria.Invoke(AP)) // if visible
visibleParts.Add(AP); // add to visible list
}
[COLOR=#008000] // remove all visible parts from the list to block[/COLOR]
foreach (AvailablePart ap in visibleParts)
partsToCheck.Remove(ap);
}
}
[COLOR=#008000] // add the blocked parts to a hashset for later lookup[/COLOR]
blackListedParts = new HashSet<string>();
foreach (AvailablePart ap in partsToCheck)
blackListedParts.Add(ap.name);
}

parts that are not visible can then be filtered out by

if (part.category == PartCategories.none && blackListedParts.Contains(part.name))

The faults I see in the above method would be that it assumes all parts will show up in the first category (Filter by Function by default) if they should be visible, or if they create a subcat before FE that duplicates the name of the FE subcat to be added it will assume the mod one to be the FE subcat and break horribly on the FE subcat.

NOTE: findPartsToBlock has to be delayed significantly to ensure all categories are created. FE creates categories between 1 and 4 frames after the categorizer is initialised, the event used by most mods fires somewhere between 5 and 8 frames after categorizer init. The search needs to be delayed atleast that much

Edited by Crzyrndm
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...