Difference between revisions of "Module:DefInfo/doc"

From RimWorld Wiki
Jump to navigation Jump to search
m
m (Replaced content with "Dev version at Module:Test")
Tag: Replaced
Line 1: Line 1:
'''This might be called a beta version, leaning towards an alpha.'''
+
Dev version at [[Module:Test]]
 
 
'''Bugs are quite possible but I've tested a bit and looks ok. Functionality expanded to actually be usable.'''
 
 
 
'''Performance: can be optimized but seems to be quite fast (will test more in bigger templates).'''
 
 
 
'''Code esthetics: ignore for now.'''
 
 
 
== 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 ===
 
<pre><nowiki>
 
{{#invoke:DefInfo|query|<defName>|...|<tag>|<sibling=...>}}
 
</nowiki></pre>
 
 
 
; <defName>
 
: defName of the Def.
 
 
 
; ...
 
: 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, keys might get 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".
 
 
 
=== getDefName ===
 
<pre><nowiki>
 
{{#invoke:DefInfo|getDefName|<label>}}
 
</nowiki></pre>
 
 
 
; <label>
 
: get defName based on the label of a Def (not case sensitive)
 
 
 
=== count ===
 
<pre><nowiki>
 
{{#invoke:DefInfo|count|<defName>|...|<tag>|<sibling=...>}}
 
</nowiki></pre>
 
 
 
Arguments are the same as for query. It's basically a wrapped up query.
 
 
 
; <defName>
 
: defName of the Def.
 
 
 
; ...
 
: 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, keys might get 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 generated list will also be displayed in the log.
 
 
 
== Examples ==
 
=== strings, numbers, booleans ===
 
;<code><nowiki>{{#invoke:DefInfo|query|Fox_Fennec|description}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Fox_Fennec|description}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Fox_Fennec|MoveSpeed}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Fox_Fennec|MoveSpeed}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Caribou|herdAnimal}}</nowiki></code>
 
:{{#invoke:DefInfo|query|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.
 
The following query retrieves the same data (just as an example) but with the use of an additional argument.
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Caribou|race|herdAnimal}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Caribou|race|herdAnimal}}
 
 
 
=== numbered lists (tradeTags) ===
 
;<code><nowiki>{{#invoke:DefInfo|query|GuineaPig|tradeTags}}</nowiki></code>
 
:{{#invoke:DefInfo|query|GuineaPig|tradeTags}}
 
 
 
Query function returned "table" so its contents is displayed in the log (for reference). To get the length:
 
 
 
;<code><nowiki>{{#invoke:DefInfo|count|GuineaPig|tradeTags}}</nowiki></code>
 
:{{#invoke:DefInfo|count|GuineaPig|tradeTags}}
 
 
 
Count also shows the table in the log. To get the second item:
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|GuineaPig|tradeTags|2}}</nowiki></code>
 
:{{#invoke:DefInfo|query|GuineaPig|tradeTags|2}}
 
 
 
=== sibling queries (lifeStageAges, tools, etc.) ===
 
;<code><nowiki>{{#invoke:DefInfo|query|GuineaPig|minAge|sibling=AnimalAdult}}</nowiki></code>
 
:{{#invoke:DefInfo|query|GuineaPig|minAge|sibling=AnimalAdult}}
 
 
 
Same destination, different road:
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|GuineaPig|lifeStageAges|3|minAge}}</nowiki></code>
 
:{{#invoke:DefInfo|query|GuineaPig|lifeStageAges|3|minAge}}
 
 
 
Some examples for "tools" (attacks):
 
 
 
;<code><nowiki>{{#invoke:DefInfo|count|Mech_Scyther|tools}}</nowiki></code>
 
:{{#invoke:DefInfo|count|Mech_Scyther|tools}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|count|Mech_Scyther|tools|1|capacities}}</nowiki></code>
 
:{{#invoke:DefInfo|count|Mech_Scyther|tools|1|capacities}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|1}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|1}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|2}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Mech_Scyther|tools|1|capacities|2}}
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=LeftBlade}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=LeftBlade}}
 
 
 
Same result:
 
 
 
;<code><nowiki>{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=left blade}}</nowiki></code>
 
:{{#invoke:DefInfo|query|Mech_Scyther|power|sibling=left blade}}
 
 
 
=== getDefName ===
 
 
 
;<code><nowiki>{{#invoke:DefInfo|getDefName|fennec fox}}</nowiki></code>
 
:{{#invoke:DefInfo|getDefName|feNNec fox}}
 
 
 
<noinclude>[[Category:Module documentation]]</noinclude>
 

Revision as of 14:34, 9 May 2021

Dev version at Module:Test