Difference between revisions of "Module:Test/doc"

From RimWorld Wiki
Jump to navigation Jump to search
(category)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''This module is used for development. Even if it works at the moment it might break at any time.'''
+
__NOEDITSECTION__
 +
'''This module is used for development.'''
  
'''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.'''
+
== Purpose ==
== 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.)
+
This module is used to query information from the uploaded and parsed game files.
 +
 
 +
Its main purpose is to populate the infoboxes.
  
 
== Usage ==
 
== Usage ==
=== query ===
 
<pre><nowiki>
 
{{#invoke:Test|query|<defName>|...|<tag>|<sibling=...>}}
 
</nowiki></pre>
 
  
; <defName>
+
A note on the order of named parameters. All of the parameters that look like <code>...=...</code> are called named parameters and their order is not important (this is true for all templates).
: defName of the Def. Works for abstract Defs but in that case you have to give it the "Name" attribute.
 
  
; ...
+
=== query ===
: 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.
+
<pre><nowiki>{{#invoke:Test|query|<def ID>[|...|][|tag|][|sibling=...]}}</nowiki></pre>
 
 
; <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=...>
+
The work-horse. Output varies based on use:
: 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).
+
: If only the <code><def ID></code> parameter is set, it will show the whole Def in the log.
 +
: If simple values are queried it will return them.
 +
: If lists are queried it will return nothing but call <code><nowiki>{{#vardefine}}</nowiki></code> on all the simple values within it. What got defined can be seen in the page's log.
  
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".
+
Named parameters:
  
Note for abstract Defs: they will automatically get merged with their parents.
+
: <code><def ID></code>
  
=== count ===
+
:: This parameter identifies the Def so it is mandatory. It can take two forms, if both are defined then <code>defName</code> takes preference.
<pre><nowiki>
 
{{#invoke:Test|count|<defName>|...|<tag>|<sibling=...>}}
 
</nowiki></pre>
 
  
Arguments are the same as for [[#query]]. It's basically a wrapped up query.
+
::: <code>defName=<defName></code>
 +
:::: <code><defName></code> <small>''(case sensitive)''</small> should be replaced with the actual defName of a Def.
  
Because count (if not 0) means that a table was counted - it will also be displayed in the log.
+
::: <code>label=<label></code>
 +
:::: <code><label></code> <small>''(case insensitive)''</small> should be replaced with the actual label of a Def.
  
=== getDefName ===
+
: <code>[sibling=...]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
<pre><nowiki>
+
::: Allows querying for something if we know its sibling's value (works only for values at the moment).
{{#invoke:Test|getDefName|<label>}}
 
</nowiki></pre>
 
  
; <label>
+
Anonymous parameters:
: 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>.
+
: <code>[|...|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
 +
:: Anonymous paramaters before the last one (<code>[tag]</code>) are here to help uniquely identify it. If the <code>[tag]</code> is already unique within a Def tree, then these additional parameters are not needed.
  
== Examples ==
+
: <code>[|tag|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
 +
:: The final anonymous parameter defines what is to be queried.
  
=== complete contents of a Def ===
+
=== count ===
 +
<pre><nowiki>{{#invoke:Test|count|<def ID>[|...|][|tag|][|sibling=...]}}</nowiki></pre>
  
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.
+
Parameters are the same as for <code>query</code>. It's basically a wrapped up query that behaves a bit differently.
;<code><nowiki>{{#invoke:Test|query|defName=Hare}}</nowiki></code>
 
:{{#invoke:Test|query|defName=Hare}}
 
  
=== strings, numbers, booleans ===
+
The difference is in how it handles lists. If a list is queried, unlike <code>query</code>, it will return the length of the list.
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|description}}</nowiki></code>
 
:{{#invoke:Test|query|defName=Fox_Fennec|description}}
 
  
;<code><nowiki>{{#invoke:Test|query|Fox_Fennec|MoveSpeed}}</nowiki></code>
+
== How-to ==
:{{#invoke:Test|query|defName=Fox_Fennec|MoveSpeed}}
 
  
;<code><nowiki>{{#invoke:Test|query|Caribou|herdAnimal}}</nowiki></code>
+
=== Take a look at a Def ===
:{{#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.
+
<code><nowiki>{{#invoke:Test|query|label=desert}}</nowiki></code>
The following query retrieves the same data (just as an example) but with the use of an additional argument.
 
  
;<code><nowiki>{{#invoke:Test|query|Caribou|race|herdAnimal}}</nowiki></code>
+
<code>{{#invoke:Test|query|label=desert}}</code>
:{{#invoke:Test|query|defName=Caribou|race|herdAnimal}}
 
  
=== numbered lists (tradeTags) ===
+
Data is in the log.
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags}}</nowiki></code>
 
:{{#invoke:Test|query|defName=GuineaPig|tradeTags}}
 
  
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
+
=== Retrieve a simple value ===
  
;<code><nowiki>{{#invoke:Test|count|GuineaPig|tradeTags}}</nowiki></code>
+
<code><nowiki>{{#invoke:Test|query|defName=Caribou|description}}</nowiki></code>
:{{#invoke:Test|count|defName=GuineaPig|tradeTags}}
 
  
Count also shows the table in the log. To get the second item:
+
<code>{{#invoke:Test|query|defName=Caribou|description}}</code>
  
;<code><nowiki>{{#invoke:Test|query|GuineaPig|tradeTags|2}}</nowiki></code>
+
=== Dealing with lists ===
:{{#invoke:Test|query|defName=GuineaPig|tradeTags|2}}
 
  
=== sibling queries (lifeStageAges, tools, etc.) ===
+
<code><nowiki>{{#invoke:Test|query|defName=Mech_Scyther|tools}}</nowiki></code>
;<code><nowiki>{{#invoke:Test|query|GuineaPig|minAge|sibling=AnimalAdult}}</nowiki></code>
 
:{{#invoke:Test|query|defName=GuineaPig|minAge|sibling=AnimalAdult}}
 
  
Same destination, different road:
+
<code>{{#invoke:Test|query|defName=Mech_Scyther|tools}}</code>
  
;<code><nowiki>{{#invoke:Test|query|GuineaPig|lifeStageAges|3|minAge}}</nowiki></code>
+
When a list is retrieved there will be no output but the log will contain a list of defined variables.
:{{#invoke:Test|query|defName=GuineaPig|lifeStageAges|3|minAge}}
 
  
Some examples for "tools" (attacks):
+
For convenience the list is reprinted here:
  
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools}}</nowiki></code>
+
<pre>
:{{#invoke:Test|count|defName=Mech_Scyther|tools}}
+
tools_1_linkedBodyPartsGroup = LeftBlade
 
+
tools_1_cooldownTime = 2
;<code><nowiki>{{#invoke:Test|count|Mech_Scyther|tools|1|capacities}}</nowiki></code>
+
tools_1_label = left blade
:{{#invoke:Test|count|defName=Mech_Scyther|tools|1|capacities}}
+
tools_1_DPS = 10
 
+
tools_1_power = 20
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|1}}</nowiki></code>
+
tools_1_capacities_1 = Cut
:{{#invoke:Test|query|defName=Mech_Scyther|tools|1|capacities|1}}
+
tools_1_capacities_2 = Stab
 
+
tools_2_linkedBodyPartsGroup = RightBlade
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|tools|1|capacities|2}}</nowiki></code>
+
tools_2_cooldownTime = 2
:{{#invoke:Test|query|defName=Mech_Scyther|tools|1|capacities|2}}
+
tools_2_label = right blade
 
+
tools_2_DPS = 10
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=LeftBlade}}</nowiki></code>
+
tools_2_power = 20
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=LeftBlade}}
+
tools_2_capacities_1 = Cut
 
+
tools_2_capacities_2 = Stab
Same result:
+
tools_3_linkedBodyPartsGroup = HeadAttackTool
 +
tools_3_capacities_1 = Blunt
 +
tools_3_label = head
 +
tools_3_DPS = 4.5
 +
tools_3_chanceFactor = 0.2
 +
tools_3_power = 9
 +
tools_3_cooldownTime = 2
 +
</pre>
  
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=left blade}}</nowiki></code>
+
All of the above can be accessed with the use of <code><nowiki>{{#var:...}}</nowiki></code>.
:{{#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:
+
<code><nowiki>{{#var:tools_1_DPS}}</nowiki></code>
<pre>
 
    ["tools"] = {
 
      {
 
        ["label"] = "left blade",
 
        ["capacities"] = {
 
          "Cut",
 
          "Stab",
 
        },
 
        ["power"] = 20,
 
        ["cooldownTime"] = 2,
 
        ["linkedBodyPartsGroup"] = "LeftBlade",
 
        ["alwaysTreatAsWeapon"] = true,
 
      },
 
</pre>
 
  
For the head they might be:
+
<code>{{#var:tools_1_DPS}}</code>
  
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=HeadAttackTool}}</nowiki></code>
+
''DPS'' is not a normal member of this table but has been added with Lua. Let's call it a virtual field.
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=HeadAttackTool}}
 
  
;<code><nowiki>{{#invoke:Test|query|Mech_Scyther|power|sibling=head}}</nowiki></code>
+
=== Retrieve something if a sibling is known ===
:{{#invoke:Test|query|defName=Mech_Scyther|power|sibling=head}}
 
  
This is the source data for it:
+
<code><nowiki>{{#invoke:Test|query|label=guinea pig|minAge|sibling=AnimalAdult}}</nowiki></code>
<pre>
 
      {
 
        ["label"] = "head",
 
        ["capacities"] = {
 
          "Blunt",
 
        },
 
        ["power"] = 9,
 
        ["cooldownTime"] = 2,
 
        ["linkedBodyPartsGroup"] = "HeadAttackTool",
 
        ["chanceFactor"] = 0.2,
 
      },
 
</pre>
 
  
=== getDefName ===
+
<code>{{#invoke:Test|query|label=guinea pig|minAge|sibling=AnimalAdult}}</code>
  
;<code><nowiki>{{#invoke:Test|getDefName|fEnNeC foX}}</nowiki></code>
+
<includeonly>[[Category:Module]]</includeonly>
:{{#invoke:Test|getDefName|fEnNeC foX}}
+
<noinclude>[[Category:Module documentation]]</noinclude>

Latest revision as of 22:51, 22 October 2022

This module is used for development.

Purpose

This module is used to query information from the uploaded and parsed game files.

Its main purpose is to populate the infoboxes.

Usage

A note on the order of named parameters. All of the parameters that look like ...=... are called named parameters and their order is not important (this is true for all templates).

query

{{#invoke:Test|query|<def ID>[|...|][|tag|][|sibling=...]}}

The work-horse. Output varies based on use:

If only the <def ID> parameter is set, it will show the whole Def in the log.
If simple values are queried it will return them.
If lists are queried it will return nothing but call {{#vardefine}} on all the simple values within it. What got defined can be seen in the page's log.

Named parameters:

<def ID>
This parameter identifies the Def so it is mandatory. It can take two forms, if both are defined then defName takes preference.
defName=<defName>
<defName> (case sensitive) should be replaced with the actual defName of a Def.
label=<label>
<label> (case insensitive) should be replaced with the actual label of a Def.
[sibling=...] (optional) (case sensitive)
Allows querying for something if we know its sibling's value (works only for values at the moment).

Anonymous parameters:

[|...|] (optional) (case sensitive)
Anonymous paramaters before the last one ([tag]) are here to help uniquely identify it. If the [tag] is already unique within a Def tree, then these additional parameters are not needed.
[|tag|] (optional) (case sensitive)
The final anonymous parameter defines what is to be queried.

count

{{#invoke:Test|count|<def ID>[|...|][|tag|][|sibling=...]}}

Parameters are the same as for query. It's basically a wrapped up query that behaves a bit differently.

The difference is in how it handles lists. If a list is queried, unlike query, it will return the length of the list.

How-to

Take a look at a Def

{{#invoke:Test|query|label=desert}}

Data is in the log.

Retrieve a simple value

{{#invoke:Test|query|defName=Caribou|description}}

A large member of the deer family, well-adapted to life in cold climates. Caribou can be milked, but refuse to carry packs.

Dealing with lists

{{#invoke:Test|query|defName=Mech_Scyther|tools}}

When a list is retrieved there will be no output but the log will contain a list of defined variables.

For convenience the list is reprinted here:

tools_1_linkedBodyPartsGroup = LeftBlade
tools_1_cooldownTime = 2
tools_1_label = left blade
tools_1_DPS = 10
tools_1_power = 20
tools_1_capacities_1 = Cut
tools_1_capacities_2 = Stab
tools_2_linkedBodyPartsGroup = RightBlade
tools_2_cooldownTime = 2
tools_2_label = right blade
tools_2_DPS = 10
tools_2_power = 20
tools_2_capacities_1 = Cut
tools_2_capacities_2 = Stab
tools_3_linkedBodyPartsGroup = HeadAttackTool
tools_3_capacities_1 = Blunt
tools_3_label = head
tools_3_DPS = 4.5
tools_3_chanceFactor = 0.2
tools_3_power = 9
tools_3_cooldownTime = 2

All of the above can be accessed with the use of {{#var:...}}.

{{#var:tools_1_DPS}}

10

DPS is not a normal member of this table but has been added with Lua. Let's call it a virtual field.

Retrieve something if a sibling is known

{{#invoke:Test|query|label=guinea pig|minAge|sibling=AnimalAdult}}

0.3