Difference between revisions of "Module:Test/data/doc"

From RimWorld Wiki
Jump to navigation Jump to search
(transformation rule added for <li> elements with a single attribute "Class")
m (update for MayRequire attribute)
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Transformation rules ==
 
== Transformation rules ==
  
=== RimWorld vesion ===
+
=== RimWorld version ===
Vesion is added to the beginning of each generated data file.
+
Version is added to the beginning of each generated Lua table.
  
 
<pre>
 
<pre>
Line 17: Line 17:
 
<defName> is used as part of the index for the main Def table.
 
<defName> is used as part of the index for the main Def table.
  
Additional attribute added: "DLC".
+
Additional attributes added: "DLC", "FileName".
  
 
<pre>
 
<pre>
Line 26: Line 26:
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 40: Line 40:
 
</pre>
 
</pre>
  
Parent (absctact) Def that gets inherited:
+
Parent (abstract) Def:
  
 
<pre>
 
<pre>
Line 50: Line 50:
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 59: Line 59:
 
     ["Name"] = "BaseHare",
 
     ["Name"] = "BaseHare",
 
     ["FileName"] = "Races_Animal_Hares.xml",
 
     ["FileName"] = "Races_Animal_Hares.xml",
    ["Version"] = "1.2.2753 rev705",
 
 
     ["DLC"] = "Core",
 
     ["DLC"] = "Core",
 
   },
 
   },
Line 68: Line 67:
 
</pre>
 
</pre>
  
=== Descriptions ===
+
=== List elements without children ===
 
 
Because of some exceptions in Royalty Defs, <description> content has to be wrapped in double square brackets (Lua multiline syntax).
 
 
 
=== <nowiki><li></nowiki> elements without children ===
 
 
Get transformed into ordered lists (numerically indexed Lua tables).
 
Get transformed into ordered lists (numerically indexed Lua tables).
  
Line 82: Line 77:
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 93: Line 88:
 
Note: a comma after the last item in a list is not flagged as an error in Lua.
 
Note: a comma after the last item in a list is not flagged as an error in Lua.
  
=== <nowiki><li></nowiki> elements with children ===
+
=== List elements with children ===
  
 
<pre>
 
<pre>
Line 112: Line 107:
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 131: Line 126:
 
</pre>
 
</pre>
  
=== <nowiki><li></nowiki> elements with a single attribute "Class" ===
+
=== List elements with a single attribute Class ===
 
The value of the "Class" attribute is used to rename the <nowiki><li></nowiki>.
 
The value of the "Class" attribute is used to rename the <nowiki><li></nowiki>.
  
 
<pre>
 
<pre>
comps = {
+
<comps>
   {
+
   <li Class="CompProperties_Glower">
    _ = {
+
     <glowRadius>10</glowRadius>
      Class = "CompProperties_Glower",
 
    },
 
     glowRadius = 10,
 
 
...
 
...
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 153: Line 145:
 
</pre>
 
</pre>
  
NOTE: The first sample already underwent the transformation of attributes to a subelement.
+
=== Components ===
 +
 
 +
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.
 +
 
 +
See [[#List elements with a single attribute Class]]
  
 
=== Ranges (1~2) ===
 
=== Ranges (1~2) ===
: TODO
+
<pre><overdoseSeverityOffset>0.18~0.35</overdoseSeverityOffset></pre>
 +
transforms to:
 +
<pre>overdoseSeverityOffset = { ["<"]=0.18, [">"]=0.35 },</pre>
  
 
=== Curve points ===
 
=== Curve points ===
Line 174: Line 174:
 
</pre>
 
</pre>
  
becomes
+
transforms to:
  
 
<pre>
 
<pre>
Line 187: Line 187:
 
</pre>
 
</pre>
  
=== Components ===
+
=== Descriptions ===
  
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.
+
Because of some exceptions in Royalty Defs, <description> content has to be wrapped in double square brackets (Lua multiline syntax).
  
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.
+
=== MayRequire attribute ===
 
+
Removed.
See
 
 
 
'''TODO:''' implement filtering
 
  
 
== Issues ==
 
== Issues ==
Line 212: Line 209:
 
=== Inheritance (interaction with parser) ===
 
=== 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.
 
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.
 +
 +
== TODO ==
 +
* Implement filtering for components (any list item that follows the same pattern)

Revision as of 03:36, 8 May 2021

Transformation rules

RimWorld version

Version is added to the beginning of each generated Lua table.

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 attributes added: "DLC", "FileName".

<ThingDef ParentName="BaseHare">
  <defName>Snowhare</defName>
  <label>snowhare</label>
  ...

transforms to:

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

Parent (abstract) Def:

<ThingDef Abstract="True" ParentName="AnimalThingBase" Name="BaseHare">
  <statBases>
    <MoveSpeed>6.0</MoveSpeed>
    <MarketValue>50</MarketValue>
    ...

transforms to:

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

List elements without children

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

<tradeTags>
  <li>AnimalUncommon</li>
  <li>AnimalFighter</li>
</tradeTags>

transforms to:

["tradeTags"] = {
  "AnimalUncommon",
  "AnimalFighter",
},

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

List elements with children

<lifeStageAges>
  <li>
    <def>AnimalBaby</def>
    <minAge>0</minAge>
  </li>
  <li>
    <def>AnimalJuvenile</def>
    <minAge>0.25</minAge>
  </li>
  <li>
    <def>AnimalAdult</def>
    <minAge>0.5</minAge>
  </li>
</lifeStageAges>

transforms to:

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

List elements with a single attribute Class

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

<comps>
  <li Class="CompProperties_Glower">
    <glowRadius>10</glowRadius>
...

transforms to:

comps = {
  CompProperties_Glower = {
    glowRadius = 10,
...

Components

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.

See #List elements with a single attribute Class

Ranges (1~2)

<overdoseSeverityOffset>0.18~0.35</overdoseSeverityOffset>

transforms to:

overdoseSeverityOffset = { ["<"]=0.18, [">"]=0.35 },

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).

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

transforms to:

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

Descriptions

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

MayRequire attribute

Removed.

Issues

One (data) file to rule them all

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

Single:

  • simplicity
    • versioning
    • uploading

Split:

  • 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.

TODO

  • Implement filtering for components (any list item that follows the same pattern)