From RimWorld Wiki
< Module:Test‎ | data
Revision as of 02:35, 8 May 2021 by Dr. Strangelove (talk | contribs) (transformation rule added for <li> elements with a single attribute "Class")
Jump to navigation Jump to search

This is the documentation page for Module:Test/data

Transformation rules

RimWorld vesion

Vesion is added to the beginning of each generated data file.

return {

  version = "1.2.2753",

Elements with attributes

Create a new subelement and move all of the attributes to their own subelements within it.

*Def elements

<defName> is used as part of the index for the main Def table.

Additional attribute added: "DLC".

<ThingDef ParentName="BaseHare">


["ThingDef:Hare"] = {
  ["_attrib_"] = {
    ["ParentName"] = "BaseHare",
    ["FileName"] = "Races_Animal_Hares.xml",
    ["DLC"] = "Core",
  ["defName"] = "Snowhare",
  ["label"] = "snowhare",

Parent (absctact) Def that gets inherited:

<ThingDef Abstract="True" ParentName="AnimalThingBase" Name="BaseHare">


["ThingDef:BaseHare"] = {
  ["_attrib_"] = {
    ["Abstract"] = "True",
    ["ParentName"] = "AnimalThingBase",
    ["Name"] = "BaseHare",
    ["FileName"] = "Races_Animal_Hares.xml",
    ["Version"] = "1.2.2753 rev705",
    ["DLC"] = "Core",
    ["statBases"] = {
      ["MoveSpeed"] = 6.0,
      ["MarketValue"] = 50,


Because of some exceptions in Royalty Defs, <description> content has to be wrapped in double square brackets (Lua multiline syntax).

<li> elements without children

Get transformed into ordered lists (numerically indexed Lua tables).



["tradeTags"] = {

Note: a comma after the last item in a list is not flagged as an error in Lua.

<li> elements with children



["lifeStageAges"] = {
    ["def"] = "AnimalBaby",
    ["minAge"] = 0,
    ["def"] = "AnimalJuvenile",
    ["minAge"] = 0.25,
    ["def"] = "AnimalAdult",
    ["minAge"] = 0.5,

<li> elements with a single attribute "Class"

The value of the "Class" attribute is used to rename the <li>.

comps = {
    _ = {
      Class = "CompProperties_Glower",
    glowRadius = 10,


comps = {
  CompProperties_Glower = {
    glowRadius = 10,

NOTE: The first sample already underwent the transformation of attributes to a subelement.

Ranges (1~2)


Curve points

Curves pop up in a lot of places so additional support functions for those might be in order.

Min, max, maybe average... things like that. Some (like litterSizeCurve) have a fixed amount of points (correction: even for litterSizeCurve this is not true) so you could just retrieve the first one or last (fourth), but this is not the case for all of them and is a bit ugly. Whatever the case, additional processing with wiki syntax would have to be used. This is bad (and to be avoided if possible).

    <li>(1.0, 0)</li>
    <li>(1.5, 1)</li>
    <li>(2.0, 1)</li>
    <li>(2.5, 0)</li>


["litterSizeCurve"] = {
  ["points"] = {
    {0.5, 0},
    {1, 1},
    {1.5, 1},
    {2.0, 0},


It would be useful to have some of the more used components. They can then be queried for additional functionality that some game objects have.

They can be numbered tables or, as in some of the examples above, string indexed. String indexes, in general, are simpler to use. Numeric tables I have to search through.


TODO: implement filtering


One (data) file to rule them all

One data file or smaller ones split by categories (buildings, races, items, etc.).


  • simplicity
    • versioning
    • uploading


  • dynamic loading

Inheritance (interaction with parser)

Inheritance can be handled by the parser or the module. If the parser handles it, then for any change the dataset needs to be recreated so I'm leaning towards letting the module take care of that. In this case the only purpose of the parser is to filter data and transform it into something Lua can use.