Difference between revisions of "Module:Test/doc"

From RimWorld Wiki
Jump to navigation Jump to search
Line 2: Line 2:
 
'''This module is used for development.'''
 
'''This module is used for development.'''
  
'''Parser is done (needs a few more finishing touches) so any data that is missing can be easily added.'''
+
== Purpose ==
  
'''At the moment the dataset has: ThingDefs, BiomeDefs, ResearchProjectDefs and DamageDefs.'''
+
This module is used to query information from the uploaded and parsed game files.
 
 
== Description ==
 
 
 
This module is used to query information from the parsed game definition files.
 
  
 
Its main purpose is to populate the infoboxes.
 
Its main purpose is to populate the infoboxes.
Line 14: Line 10:
 
== Usage ==
 
== Usage ==
  
A note on the order of parameters. All of the parameters that begin with <code>somelabel=...</code> are called named parameters and their order is not important (as is the general case with named parameters for templates).
+
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).
  
<hr/>
 
 
=== query ===
 
=== query ===
 +
<hr>
 +
 +
The work-horse. Output varies based on use:
 +
: 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 work-horse. Output varies based on use. If simple values are queried it will return the string. If lists are queried it will return nothing but call <code><nowiki>{{#vardefine}}</nowiki></code> for all the simple values within it. What got defined can be seen in the page's log.
+
<pre><nowiki>{{#invoke:Test|query|<def ID>[|...|][|tag|][|sibling=...]}}</nowiki></pre>
  
<pre><nowiki>{{#invoke:Test|query|<def ID>|[...|...|...]|[tag]|[sibling=...]}}</nowiki></pre>
+
'''Named parameters:'''
  
 
<code><def ID></code>
 
<code><def ID></code>
Line 28: Line 28:
  
 
: <code>defName=<defName></code>
 
: <code>defName=<defName></code>
:: <defName> ''(case sensitive)'' should be replaced with the actual defName of a Def.
+
:: <code><defName></code> <small>''(case sensitive)''</small> should be replaced with the actual defName of a Def.
  
 
: <code>label=<label></code>
 
: <code>label=<label></code>
:: <label> ''(case insensitive)'' should be replaced with the actual label of a Def.
+
:: <code><label></code> <small>''(case insensitive)''</small> should be replaced with the actual label of a Def.
 +
 
 +
<code>[sibling=...]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
 +
: Allows querying for something if we know its sibling's value (works only for values at the moment).
  
<code>[...|...|...]</code>
+
'''Anonymous parameters:'''
: 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.
 
  
<code>[tag]</code>
+
<code>[|...|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
: The final parameter is just a normal numbered parameter but because it is the last one, it is mentioned here so it can be referred to.
+
: 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.
  
<code>[sibling=<value>]</code>
+
<code>[|tag|]</code> <small>''(optional)''</small> <small>''(case sensitive)''</small>
: Allows querying for something if we know its sibling's value (works only for values at the moment). It does not have to be at the end because named arguments do not depend on the order.
+
: The final anonymous parameter defines what is to be queried.
  
<hr/>
 
 
=== count ===
 
=== count ===
 +
<hr>
  
 
<pre><nowiki>{{#invoke:Test|count|<def ID>|[...|...|...]|[tag]|[sibling=...]}}</nowiki></pre>
 
<pre><nowiki>{{#invoke:Test|count|<def ID>|[...|...|...]|[tag]|[sibling=...]}}</nowiki></pre>
  
Arguments are the same as for [[#query]]. It's basically a wrapped up query.
+
Parameters are the same as for <code>query</code>. It's basically a wrapped up query that behaves a bit differently.
  
Because count (if not 0) means that a table was counted - it will also be displayed in the log.
+
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.
 
 
<hr/>
 
=== getDefName ===
 
 
 
Used to retrieve a Def's defName if we know the label. Most of the wiki pages are labels of Defs so this can come in handy.
 
 
 
<pre><nowiki>{{#invoke:Test|getDefName|<label>}}</nowiki></pre>
 
 
 
<code><label></code>
 
: Def's label (not case sensitive)
 
  
 
== How-to ==
 
== How-to ==
 
=== Get defName if we know label ===
 
 
<code><nowiki>{{#invoke:Test|getDefName|feNNec fOx}}</nowiki></code>
 
 
<code>{{#invoke:Test|getDefName|feNNec fOx}}</code>
 
  
 
=== Take a look at a Def ===
 
=== Take a look at a Def ===

Revision as of 09:13, 18 May 2021

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


The work-horse. Output varies based on use:

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.
{{#invoke:Test|query|<def ID>[|...|][|tag|][|sibling=...]}}

Named parameters:

<def ID>

This parameter identifies the Def so it is mandatory. It can take two forms:
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}}

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