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

From RimWorld Wiki
Jump to navigation Jump to search
(Transformation rules.)
 
m
Line 6: Line 6:
 
=== Def keys ===
 
=== Def keys ===
 
defName is used as an index for the main Def table. defName remains as a subkey to the table.
 
defName is used as an index for the main Def table. defName remains as a subkey to the table.
 +
 +
<pre>
 +
<ThingDef ParentName="BaseHare">
 +
  <defName>Snowhare</defName>
 +
  <label>snowhare</label>
 +
  ...
 +
</pre>
 +
 +
becomes
 +
 +
<pre>
 +
["Hare"] = {
 +
  ["ParentName"] = "BaseHare",
 +
  ["defName"] = "Hare",
 +
  ["label"] = "hare",
 +
  ...
 +
</pre>
 +
 +
Parent Def that gets inherited (Name becomes the key, no defName):
 +
 +
<pre>
 +
<ThingDef Abstract="True" ParentName="AnimalThingBase" Name="BaseHare">
 +
  <statBases>
 +
    <MoveSpeed>6.0</MoveSpeed>
 +
    <MarketValue>50</MarketValue>
 +
    ...
 +
</pre>
 +
 +
becomes
 +
 +
<pre>
 +
["BaseHare"] = {
 +
  ["Abstract"] = true,
 +
  ["ParentName"] = "AnimalThingBase",
 +
  ["statBases"] = {
 +
    ["MoveSpeed"] = 6.0,
 +
    ["MarketValue"] = 50,
 +
    ...
 +
</pre>
  
 
=== <nowiki><li></nowiki> elements enclosing simple values ===
 
=== <nowiki><li></nowiki> elements enclosing simple values ===

Revision as of 19:54, 14 April 2021

Herein lie the (current) ad hoc rules for getting from an XML to a Lua table

Elements with attributes

Move into subkey with exact name.

Def keys

defName is used as an index for the main Def table. defName remains as a subkey to the table.

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

becomes

["Hare"] = {
  ["ParentName"] = "BaseHare",
  ["defName"] = "Hare",
  ["label"] = "hare",
  ...

Parent Def that gets inherited (Name becomes the key, no defName):

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

becomes

["BaseHare"] = {
  ["Abstract"] = true,
  ["ParentName"] = "AnimalThingBase",
  ["statBases"] = {
    ["MoveSpeed"] = 6.0,
    ["MarketValue"] = 50,
    ...

<li> elements enclosing simple values

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

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

becomes

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

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

<li> elements enclosing multiple items

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

becomes

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

Ranges (1~2)

TODO

Curve points

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

becomes

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