Ludeon Forums

Ludeon Forums

  • April 21, 2019, 10:39:55 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How Exactly do ModExtensions Work?  (Read 282 times)

dninemfive

  • Drifter
  • **
  • Posts: 63
  • Refugee
    • View Profile
How Exactly do ModExtensions Work?
« on: October 21, 2018, 02:09:14 PM »

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:

Code: [Select]
<Defs>
    <(def)>
        ...
        </modExtensions>
            <BHRModExtension>
                <isSuperIllegal>True</isSuperIllegal>
                <mtbReduction>12</mtbReduction>
            </BHRModExtension>
        &c.
« Last Edit: October 21, 2018, 02:15:01 PM by dninemfive »
Logged

XeoNovaDan

  • Super Tester
  • Planetologist
  • ***
  • Posts: 1533
  • Yee-Haw!
    • View Profile
Re: How Exactly do ModExtensions Work?
« Reply #1 on: October 22, 2018, 11:23:07 AM »

Hey, so the XML to add a new def wih a ModExtension would be similar to the following:
Code: [Select]
<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:

Code: [Select]
<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!
Logged
My mods - Turret Extensions, Adjustable Predator Count, Profitable Weapons and various other goodies

dninemfive

  • Drifter
  • **
  • Posts: 63
  • Refugee
    • View Profile
Re: How Exactly do ModExtensions Work?
« Reply #2 on: October 25, 2018, 11:20:42 PM »

Thanks!
Logged