Difference between revisions of "Module:Test/doc"

From RimWorld Wiki
Jump to navigation Jump to search
m
Line 54: Line 54:
  
 
This is not the complete set as the one available to the game itself. Because a "table" is returned, the contents are in the log.
 
This is not the complete set as the one available to the game itself. Because a "table" is returned, the contents are in the log.
;<code><nowiki>{{#invoke:Test|query|Hare}}</nowiki></code>
+
;<code><nowiki>{{#invoke:Test|query|defName=Hare}}</nowiki></code>
:{{#invoke:Test|query|Hare}}
+
:{{#invoke:Test|query|defName=Hare}}
  
 
=== strings, numbers, booleans ===
 
=== strings, numbers, booleans ===
 
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|description}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|description}}</nowiki></code>
:{{#invoke:Test|query|Fox_Fennec|description}}
+
:{{#invoke:Test|query|defName=Fox_Fennec|description}}
  
 
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}</nowiki></code>
:{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}
+
:{{#invoke:Test|query|defName=Fox_Fennec|MoveSpeed}}
  
 
;<code><nowiki>{{#invoke:Test|query|Caribou|herdAnimal}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Caribou|herdAnimal}}</nowiki></code>
:{{#invoke:Test|query|Caribou|herdAnimal}}
+
:{{#invoke:Test|query|defName=Caribou|herdAnimal}}
  
 
"herdAnimal" is located in a branch of the main Def called "races" but because it appears nowhere else in the Def no additional parameters are needed to uniquely identify it.
 
"herdAnimal" is located in a branch of the main Def called "races" but because it appears nowhere else in the Def no additional parameters are needed to uniquely identify it.
Line 71: Line 71:
  
 
;<code><nowiki>{{#invoke:Test|query|Caribou|race|herdAnimal}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Caribou|race|herdAnimal}}</nowiki></code>
:{{#invoke:Test|query|Caribou|race|herdAnimal}}
+
:{{#invoke:Test|query|defName=Caribou|race|herdAnimal}}
  
 
=== numbered lists (tradeTags) ===
 
=== numbered lists (tradeTags) ===
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags}}</nowiki></code>
:{{#invoke:Test|query|GuineaPig|tradeTags}}
+
:{{#invoke:Test|query|defName=GuineaPig|tradeTags}}
  
 
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
 
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
  
 
;<code><nowiki>{{#invoke:Test|count|GuineaPig|tradeTags}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|count|GuineaPig|tradeTags}}</nowiki></code>
:{{#invoke:Test|count|GuineaPig|tradeTags}}
+
:{{#invoke:Test|count|defName=GuineaPig|tradeTags}}
  
 
Count also shows the table in the log. To get the second item:
 
Count also shows the table in the log. To get the second item:
  
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags|2}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags|2}}</nowiki></code>
:{{#invoke:Test|query|GuineaPig|tradeTags|2}}
+
:{{#invoke:Test|query|defName=GuineaPig|tradeTags|2}}
  
 
=== sibling queries (lifeStageAges, tools, etc.) ===
 
=== sibling queries (lifeStageAges, tools, etc.) ===
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}</nowiki></code>
:{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}
+
:{{#invoke:Test|query|defName=GuineaPig|minAge|sibling=AnimalAdult}}
  
 
Same destination, different road:
 
Same destination, different road:
  
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}</nowiki></code>
:{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}
+
:{{#invoke:Test|query|defName=GuineaPig|lifeStageAges|3|minAge}}
  
 
Some examples for "tools" (attacks):
 
Some examples for "tools" (attacks):
  
 
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools}}</nowiki></code>
:{{#invoke:Test|count|Mech_Scyther|tools}}
+
:{{#invoke:Test|count|defName=Mech_Scyther|tools}}
  
 
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}</nowiki></code>
:{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}
+
:{{#invoke:Test|count|defName=Mech_Scyther|tools|1|capacities}}
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|tools|1|capacities|1}}
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|tools|1|capacities|2}}
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=LeftBlade}}
  
 
Same result:
 
Same result:
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=left blade}}
  
 
Note for the two examples above (sibling=LeftBlade and sibling=left blade): these will retrieve the same data because:
 
Note for the two examples above (sibling=LeftBlade and sibling=left blade): these will retrieve the same data because:
Line 137: Line 137:
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=HeadAttackTool}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=HeadAttackTool}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|power|sibling=HeadAttackTool}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=HeadAttackTool}}
  
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=head}}</nowiki></code>
 
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=head}}</nowiki></code>
:{{#invoke:Test|query|Mech_Scyther|power|sibling=head}}
+
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=head}}
  
 
This is the source data for it:
 
This is the source data for it:

Revision as of 13:11, 14 May 2021

This module is used for development. Even if it works at the moment it might break at any time.

Most of the data should be available (ThingDefs and BiomeDefs look complete, if there's need for other Defs - easily added). Parser is done (needs a few more finishing touches) so any data that is missing can be easily added.

Description

This module is used to get information about game objects. Its main purpose is to populate the contents of infoboxes.

Values retrieved are those defined in the files so they may need to be processed to be user friendly. For example "foodType" that holds the value "OmnivoreRoughAnimal" is not entirely helpful. (TODO: This could be automatically converted to something more recognizable.)

Usage

query

{{#invoke:Test|query|<defName>|...|<tag>|<sibling=...>}}
<defName>
defName of the Def. Works for abstract Defs but in that case you have to give it the "Name" attribute.
...
Additional arguments are here to help uniquely identify the final argument <tag>. If the wanted tag is already unique within a Def tree, then additional parameters are not needed.
<tag>
This is the key to be retrieved. They are the same as those in the XML files (filtered, of course; not all of the data from the files is available).
<sibling=...>
Allows querying for something if we know a sibling value (works only for values at the moment, querying by keys or key/value pairs will most likely be added). It does not have to be at the end because named arguments do not depend on the order. (Might move this functionality to a separate function if the need arises).

The algorithm will return the first value found. If the query generates a list, for now, the default behaviour is to dump the contents of the thing to the log. The log can be accessed when previewing a page you're editing. A hint that this has happened (there is something in the log) is that the module returned the string "table".

Note for abstract Defs: they will automatically get merged with their parents.

count

{{#invoke:Test|count|<defName>|...|<tag>|<sibling=...>}}

Arguments are the same as for #query. It's basically a wrapped up query.

Because count (if not 0) means that a table was counted - it will also be displayed in the log.

getDefName

{{#invoke:Test|getDefName|<label>}}
<label>
get defName based on the label of a Def (not case sensitive)

This doesn't work if (for any reason you migh have) you want to get abstract (parent/inheritable) Defs because they don't have a <label>.

Examples

complete contents of a Def

This is not the complete set as the one available to the game itself. Because a "table" is returned, the contents are in the log.

{{#invoke:Test|query|defName=Hare}}

strings, numbers, booleans

{{#invoke:Test|query|Fox_Fennec|description}}
A small fox originally from the northern part of Earth's Africa continent. It hunts small creatures and has very large ears for cooling itself in the heat.
{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}
4.6
{{#invoke:Test|query|Caribou|herdAnimal}}
true

"herdAnimal" is located in a branch of the main Def called "races" but because it appears nowhere else in the Def no additional parameters are needed to uniquely identify it. The following query retrieves the same data (just as an example) but with the use of an additional argument.

{{#invoke:Test|query|Caribou|race|herdAnimal}}
true

numbered lists (tradeTags)

{{#invoke:Test|query|GuineaPig|tradeTags}}

Query function returned "table" so its contents is displayed in the log (for reference). To get the length:

{{#invoke:Test|count|GuineaPig|tradeTags}}
3

Count also shows the table in the log. To get the second item:

{{#invoke:Test|query|GuineaPig|tradeTags|2}}
AnimalUncommon

sibling queries (lifeStageAges, tools, etc.)

{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}
0.3

Same destination, different road:

{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}
0.3

Some examples for "tools" (attacks):

{{#invoke:Test|count|Mech_Scyther|tools}}
3
{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}
2
{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}
Cut
{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}
Stab
{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}
20

Same result:

{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}
20

Note for the two examples above (sibling=LeftBlade and sibling=left blade): these will retrieve the same data because:

    ["tools"] = {
      {
        ["label"] = "left blade",
        ["capacities"] = {
          "Cut",
          "Stab",
        },
        ["power"] = 20,
        ["cooldownTime"] = 2,
        ["linkedBodyPartsGroup"] = "LeftBlade",
        ["alwaysTreatAsWeapon"] = true,
      },

For the head they might be:

{{#invoke:Test|query|Mech_Scyther|power|sibling=HeadAttackTool}}
9
{{#invoke:Test|query|Mech_Scyther|power|sibling=head}}
9

This is the source data for it:

      {
        ["label"] = "head",
        ["capacities"] = {
          "Blunt",
        },
        ["power"] = 9,
        ["cooldownTime"] = 2,
        ["linkedBodyPartsGroup"] = "HeadAttackTool",
        ["chanceFactor"] = 0.2,
      },

getDefName

{{#invoke:Test|getDefName|fEnNeC foX}}
Script error: The function "getDefName" does not exist.