Careful Conditional - KonradHeinser/EBSGFramework GitHub Wiki

This is a type of patch operation that mostly acts like PatchOperationConditional, but instead of just a pass/fail, it allows you to set up a series of conditions that trigger based on where the check failed, assuming it did. This is intended to help avoid a series of nested conditionals, allowing you to put all of them into one operation that executes other operations based on the results.

The operation starts like so:

    <Operation Class="EBSGFramework.PatchOperationCarefulConditional">
        <xpath>INSERT/FULL/XPATH/HERE</xpath>
    </Operation>

Under the xpath you have 3 options to pick from, along with a debug option:

  • match : If the xpath exists, this stuff occurs
  • conditions : A special list of items that each contain two things
    • operation : Set up the same as match/nomatch, and only triggers if the failPoint is correct
    • failPoint : Which part of the xpath should fail to trigger this patch. This should contain everything in-between, but not including, the /'s
  • nomatch : If the xpath wasn't found and the fail point isn't covered, this operation is run
  • warnWhenFailed : Default (False) : If you're not sure what failPoint to use, set this to True and the log will print a warning that states the failPoint, fail path, and attempted path. The line should always be removed before releasing the mod

This example checks for the xpath Defs/GeneDef[defName="FoamSpray"]/displayOrderInCategory to see if the Gene FoamSpray exists, and if so whether it has a displayOrderInCategory already. There are 3 potential results from this patch. First, if it does have the tag, it replaces the value. Second, if the gene doesn't have the tag it adds it. Third, if the GeneDef of FoamSpray doesn't exist (in this case because Biotech isn't active), then the patch will quietly give up because no nomatch is set up.

    <Operation Class="EBSGFramework.PatchOperationCarefulConditional">
        <xpath>Defs/GeneDef[defName="FoamSpray"]/displayOrderInCategory</xpath>
        <match Class="PatchOperationReplace">
            <xpath>Defs/GeneDef[defName="FoamSpray"]/displayOrderInCategory</xpath>
            <value>
                <displayOrderInCategory>1</displayOrderInCategory>
            </value>
        </match>
        <conditions>
            <li>
                <failPoint>displayOrderInCategory</failPoint>
                <operation Class="PatchOperationAdd">
                    <xpath>Defs/GeneDef[defName="FoamSpray"]</xpath>
                    <value>
                        <displayOrderInCategory>1</displayOrderInCategory>
                    </value>
                </operation>
            </li>
        </conditions>
    </Operation>
⚠️ **GitHub.com Fallback** ⚠️