How Exactly do ModExtensions Work?

Started by dninemfive, October 21, 2018, 02:09:14 PM

Previous topic - Next topic

dninemfive

I'm working on a project for someone who doesn't know C# and doesn't care to learn, so I'm hoping to expose the relevant variables in ModExtensions for certain defs. I generally know how they work, particularly the C# behind them, but I don't know the XML or PatchOperation syntax for adding them. Unfortunately, I haven't been able to find any posts or examples of their usage anywhere online.

For reference, my custom-defined ModExtension, "BHRModExtension," defines a boolean isSuperIllegal and an int mtbReduction, so I'm assuming the syntax would be something like:


<Defs>
    <(def)>
        ...
        </modExtensions>
            <BHRModExtension>
                <isSuperIllegal>True</isSuperIllegal>
                <mtbReduction>12</mtbReduction>
            </BHRModExtension>
        &c.

XeoNovaDan

Hey, so the XML to add a new def wih a ModExtension would be similar to the following:

<Defs>

    <ExampleDef>
        <defName>Example</defName>
        <modExtensions>
            <li Class="YourMod.ModExtensionClass">
                <isSuperIllegal>true</isSuperIllegal>
                <mtbReduction>12</mtbReduction>
            </li>
        </modExtensions>
    </ExampleDef>

</Defs>


Or if you wanted to xpath patch a mod extension onto an existing def, you'd use PatchOperationAddModExtension, which is like PatchOperationAdd but saves having to check if modExtensions has already been added/having to include it in your value field:


<Patch>

    <Operation Class="PatchOperationAddModExtension">
        <xpath>*/ExampleDef[defName="Example"]</xpath>
        <value>
            <li Class="YourMod.ModExtensionClass">
                <isSuperIllegal>true</isSuperIllegal>
                <mtbReduction>12</mtbReduction>
            </li>
        </value>
    </Operation>

</Patch>


My SurvivalTools mod uses a few ModExtensions, which might be worth using as a point of reference: https://github.com/XeoNovaDan/SurvivalTools/tree/master/Source/SurvivalTools

Hope that's helped!