Xpath patching question: Are there functioning wildcards for "defName"?

Started by Tenshi~Akari, December 15, 2020, 07:49:40 PM

Previous topic - Next topic

Tenshi~Akari

I have been quietly trying to figure out something in my spare time & trying to at least get back into playing Rimworld while I have the time & will to do it, and trying to work out a personal mod patch for research projects in general. However, I'm not very savvy with everything involving xpath, and I easily get confused if I don't have a working example to base off of. (Meaning I'm confusing myself more looking at the modding wiki for it than I am actually finding an already existing example in mods I've downloaded.) Anyways, here it is:

Seeing the suggestion left for me in the request thread I posted a good while ago, I wanted to try patching out all the requiredResearchBuilding lines in every ResearchProjectDefs, not just for Vanilla but for any mods enabled. As a balancing option, I want to replace the bench requirement with the need of an additional connected facility object. This object itself would enable Tier 3 research for any research table/spot connected to it. I'd rather have this method done, as it still requires the same amount of research to get this object, and not lose some of the challenge aspect in researching. That, and still having choices in the style of research bench that fits my pawns' settlement styles. (What can I say? I like having options. :P

The initial idea: use the wildcard function in xpath patching to make it happen somehow.
The problem: I have no idea if there is a wildcard for the way I'm trying to do it.

Here is the borked code for reference:


<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<Operation Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="PatchOperationTest">
<xpath>Defs/ResearchProjectDef[defName=*]/requiredResearchBuilding</xpath>
<success>Invert</success>
</li>
<li Class="PatchOperationSequence">
<operations>
<li Class="PatchOperationConditional">
<xpath>Defs/ResearchProjectDef[defName=*]/requiredResearchFacilities</xpath>
<nomatch Class="PatchOperationAdd">
<xpath>Defs/ResearchProjectDef[defName=*]</xpath>
<value>
<requiredResearchFacilities><li>HiTechResearchEnabler</li></requiredResearchFacilities>
</value>
</nomatch>
<match Class="PatchOperationAdd">
<xpath>Defs/ResearchProjectDef[defName=*]/requiredResearchFacilities</xpath>
<value>
<li>HiTechResearchEnabler</li>
</value>
</match>
</li>
<li Class="PatchOperationRemove">
<xpath>Defs/ResearchProjectDef[defName=*]/requiredResearchBuilding</xpath>
</li>
</operations>
</li>
</operations>
</Operation>

</Patch>


In its current state, the patch naturally fails and the related red error tells me "XML error: <value><requiredResearchBuilding>HiTechResearchBench</requiredResearchBuilding></value> doesn't correspond to any field in type PatchOperationRemove." It will work fine when a research project's defName is specified outright, but my sorry attempt at playing around trying to find a wildcard method ends me with nothing workable at current...

So I really don't know if I'm overthinking it or trying to do the impossible, but if anybody is still around that knows better, is there a way to do this with a one-shot xml patch and wildcard syntax, or am I going to have to do specific patches for each & every research def I know requires the Hi-tech research bench?

Appreciating the help in advance.  :D

EDIT: Realized I had copied over the wrong patch file, of course the previous one wasn't gonna work regardless.

Cozarkian

I think you can just drop [defName=*] entirely.

<xpath>Defs/ResearchProjectDef/requiredResearchFacilities</xpath>

In fact, I'm certain you can, because I did this in my Pawns Choose Research mod:


<li Class="PatchOperationAddModExtension">
<xpath>Defs/ResearchProjectDef</xpath>
<value>
<li Class="PawnsChooseResearch.ResearchCategory"></li>
</value>
</li>

Cozarkian

I think you are going to run into some other problems, though.

For example, why are you using inverted success? If your test finds a research project that has a requiredResearchBuilding, it's going to succeed, get inverted to fail, and abort the rest of the operation sequence. You want <success>Normal<success> (or just no success node).

And that conditional isn't going to work like you want. It won't check each def to see if they have a facility and then match/nomatch based on that. Instead it will look if any single def has a facility. If it finds at least one, it will apply match to all defs, otherwise it will apply nomatch to all defs.

Tenshi~Akari

I see... thanks for clarifying that. I'll try that out!

I put that in there initially to stop the error spam I was getting & forgot to comment it out, that and of course mimicking patch code that I've seen with other mods to see if it would work. I'll definitely try to see how it works out when I get back to my PC in a little while.

EDIT: Forgot to report back. Got it working finally, still in the middle of testing some things with this, but it's working alright so far. Perhaps once I get a decent object texture going and know for sure it's working with modded research as well, I'll upload sometime down the road. Thanks again for your help, Cozarkian. :D