An other xpath subjet : no defname to use on the targetted node

Started by Teneombre, November 30, 2017, 08:20:24 AM

Previous topic - Next topic

Teneombre

I everyone,

I'm come here to ask your help because all the patches files I found modify a file with a defname as definition (I mean <defname>XX</defname> so they target using this defname [defname="XX"]. I currently trying to modify the global stats for tree (plant_base) in which there is no such defname to target. I can't nether just modify all the stats of all the bush/tree there since I only want to modify tree.
So, I use this code :
Quote<Patch>

   <Operation Class="PatchOperationReplace">
     <xpath>/Defs/ThingDefs_Plants/ThingDef ParentName="PlantBase" Name="TreeBase" Abstract="True"/pathCost</xpath>
     <value>
      <pathCost>12</pathCost>
     </value>
   </Operation>
</Patch>
The problem is :
1- should the game throw back an error if a patches files is not valide ?
2- I can't use the name of the file "plant_base" because I want to be able to modify any mod with its own name. With the code I used, the game will look for "<ThingDef ParentName="PlantBase" Name="TreeBase" Abstract="True"> in all the files in the "ThingDef_Plants" folder or I didn't understant something ?
3-I try to reduce as much as possible the number of operation for my xpath to operate. Should I always start the path setting from the begining (so the general Defs folder) and so on, or must I only start the path setting from the subfolder there there is the files I want to change ?

Sorry for the noob questions. I was able to manage near everything in A16 by looking how other mods do and then learning but it's a little bit harder for the xpathing method. I hope someone will be able to help me there ^^
Thanks anyway for reading this :) Double thanks if you take time to answer :)

CannibarRechter

I didn't quite follow what you are asking. Can you rephrase by posting the XML you are trying to patch? If you show me an example, I might be able to tell you how to patch it.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Nightinggale

Quote from: Teneombre on November 30, 2017, 08:20:24 AM2- I can't use the name of the file "plant_base" because I want to be able to modify any mod with its own name. With the code I used, the game will look for "<ThingDef ParentName="PlantBase" Name="TreeBase" Abstract="True"> in all the files in the "ThingDef_Plants" folder or I didn't understant something ?
Each patch is applied to all files and there is nothing you can do to prevent that. I wrote about a new ModCheck feature to allow a patch file to work on just one file in one mod, but that idea is still on the idea stage and I haven't written even a single line of code for it yet.

The only way to pick the right file with the currently available tools would be to use an xpath, which only triggers on the file you want to patch.

Quote from: Teneombre on November 30, 2017, 08:20:24 AM3-I try to reduce as much as possible the number of operation for my xpath to operate. Should I always start the path setting from the begining (so the general Defs folder) and so on, or must I only start the path setting from the subfolder there there is the files I want to change ?
The path you need in xpath is the one inside the xml files and it has nothing to do with where the actual file is located. If you want to know how to make your patching use as little time as possible, read this.
ModCheck - boost your patch loading times and include patchmods in your main mod.

Teneombre

Sorry, I'm not an english speaker so my first post was probably a little bit messy.
Currently, I want to modify this file :
/Core/Defs/ThingDefs_plants/Plants_Bases.xml
I want to change the
Quote
</Defs>
...
<ThingDef ParentName="PlantBase" Name="TreeBase" Abstract="True">
   
<statBases>
      <MaxHitPoints>300</MaxHitPoints>
    </statBases>
    <description>A tree.</description>
    <altitudeLayer>Building</altitudeLayer>
    <selectable>true</selectable>
    <fillPercent>0.25</fillPercent>
...
    <pathCost>130</pathCost>
    ...
  </ThingDef>
</Defs>
I want to change the pathCost value. So I use the code I post on the first post. All exemple I found use the "defName" tage to target something, but there is no defName here so I want to be sure the strange thing I use is the good one. It's my first patches so I want to be sure I understand everything fine.

CannibarRechter

I thought you might be asking for something like that. Here's what you do instead:

<Operation Class="PatchOperationReplace">
<xpath>*/ThingDef[@Name = "TreeBase"]/pathCost</xpath>
<value><pathCost>260</pathCost></value>
</Operation>
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Teneombre

Thanks !
In order to me learn a little bit, can you also give me the version with the / in the beginning ? There is also a // but I already know it's a bad idea to use it.

CannibarRechter

I don't really use them that way, as it really isn't necessary, but I believe it would go "/Defs/ThingDef[..."
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects