Modding Tutorials/DefModExtension

From RimWorld Wiki
Revision as of 16:35, 30 January 2019 by Mehni (talk | contribs) (first iteration - more code to follow)
Jump to navigation Jump to search

Modding Tutorials

A DefModExtension is a way to add fields to Defs. DefModExtensions are a simple way to extend functionality to a Def.

Benefits:
+ Is really simple and light-weight to use.
+ Works on any Def.
+ Exposes its functionality to XML.
+ Compatible with savefiles, other mods, you name it.
+ Does not come with the compatibility issues and pitfalls of creating a custom Def class.
+ Does not have the overhead of a ThingComp.
+ More broadly applicable than a ThingComp (not every Def is a ThingWithComps!).

Downsides:
- Static and global data.
- Can't save data.
- Only works on Defs.

Requirements

You know the deal by now.

  • Solution
  • Custom code
  • C#
  • XML

The Code

using Verse;
using RimWorld;

namespace ExampleNameSpace
{
    public class RimQuest_ModExtension : DefModExtension
    {
        public bool canBeARimQuest = true;
    }
}

That's it. DefModExtensions can of course contain any field you wish: a C# Type, a Thingfilter, a list -- but for the sake of a simple example, we'll use a bool.

See also

Ludeon thread on Mod Extensions
The pull request the code this article is based on