Extract ThingFilter's contents

Started by Kubouch, July 06, 2017, 10:23:20 AM

Previous topic - Next topic

Kubouch

Let's assume I have this:

<ingredientFilter>
    <categories>
        <li>MeatRaw</li>
    </categories>
    <thingDefs>
        <li>Wort</li>
        <li>Kibble</li>
    </thingDefs>
</ingredientFilter>

where ingredientFilter is my instance of ThingFilter. The filter works correctly in game.

Now I want to extract a string like this: "Ingredients: meat, wort, kibble". Just list what I put into the XML: one category and two thingDefs. Unfortunately ThingFilter.categories and ThingFilter.thingDefs are private.

ThingFilter.Summary (or ToString()) just lists "ingredients" in this kind of example. I could iterate over AllowedThingDefs but that lists all the ThingDefs within the category ("alpaca meat", "alphabeaver meat", etc.), thus creating a huge list. It might be possible to use DisplayRootCategory but I haven't found a way how to check whether a ThingDef belongs to a category. I also tried subclassing ThingFilter with public categories and thingDefs which worked for listing things but broke the ThingFilter functionality. Then I ran out of ideas  :D.

Any ideas?

EDIT: Some context: lines 201-216.