Template:ResourceHelper: Difference between revisions

From bg3.wiki
Jump to navigation Jump to search
m (NtCarlson moved page Template:ResourceSimple to Template:ResourceHelper: More appropriate name for helper template that isn't intended be called directly)
(Changed the input format to "type:count" instead of "count type")
Line 1: Line 1:
<includeonly><!--
<includeonly><!--
Handle resources in the format of [count] <resource> e.g. "4 ki" or just "ki"
Handle resources in the format of [count] <resource> e.g. "ki:4" or just "ki"
-->{{#vardefine:param1|{{ #explode: {{{1}}}| |0}}}}<!--
-->{{#vardefine:type|{{ #explode: {{{1}}}|:|0}}}}<!--
Split parameters on whitespace
Split parameter into type and count on the :
-->{{#vardefine:param2|{{ #explode: {{{1}}}| |1}}}}<!--
-->{{#vardefine:count|{{ #explode: {{{1}}}|:|1}}}}<!--
If there are multiple parameters, assume the first value is the count
-->{{#if: {{#var: count}}
-->{{#if: {{#var: param2}}
   | {{resource|{{#var: type}}|count={{#var: count}}}}
   | {{resource|{{#var: param2}}|count={{#var: param1}}}}
   | {{resource|{{#var: type}}}}
   | {{resource|{{#var: param1}}}}
}}</includeonly><noinclude>
}}</includeonly><noinclude>
=What is this?=
=What is this?=
This is a wrapper around [[Template:Resource]] to work better in conjunction with [[Module:ParseList]] specifically by [[Template:ResourceList]].
This is a wrapper around [[Template:Resource]] to work better in conjunction with [[Module:ParseList]] specifically by [[Template:ResourceList]].
Optional parameters like <code>cost=3</code> do not work when applying a template to a list with ParseList, so this template enables an alternative syntax that can be used with ParseList.
=Usage=
=Usage=
<pre>{{ResourceSimple | [count] <type>}}</pre>
<pre>{{ResourceHelper | <type>:[count]}}</pre>
----
----
<br/><code><></code> Denotes mandatory parameters, <code>[]</code> denotes optional parameters.
<br/><code><></code> Denotes mandatory parameters, <code>[]</code> denotes optional parameters.
Line 25: Line 26:
|{{ResourceSimple|ki}}||<pre>{{ResourceSimple|ki}}</pre>
|{{ResourceSimple|ki}}||<pre>{{ResourceSimple|ki}}</pre>
|-
|-
|{{ResourceSimple|5 ki}}||<pre>{{ResourceSimple|5 ki}}</pre>
|{{ResourceSimple|ki:5}}||<pre>{{ResourceSimple|ki:5}}</pre>
|-
|-
|{{ResourceSimple|30 movement}}||<pre>{{ResourceSimple|30 movement}}</pre>
|{{ResourceSimple|movement:30}}||<pre>{{ResourceSimple|movement:30}}</pre>
|-
|-
| {{#invoke: ParseList | main | action, 3 ki | useTemplate = ResourceSimple }}
| {{#invoke: ParseList | main | action, ki:3 | useTemplate = ResourceSimple }}
| <pre>{{#invoke: ParseList | main | action, 3 ki | useTemplate = ResourceSimple }}</pre>
| <pre>{{#invoke: ParseList | main | action, ki:3 | useTemplate = ResourceSimple }}</pre>
|-
|-
| {{#invoke: ParseList | main  
| {{#invoke: ParseList | main  
   | bonus, 10 movement | useTemplate = ResourceSimple
   | bonus, movement:10 | useTemplate = ResourceSimple
}}
}}
| <pre>
| <pre>
{{#invoke: ParseList | main
{{#invoke: ParseList | main
   | bonus, 10 movement | useTemplate = ResourceSimple
   | bonus, movement:10 | useTemplate = ResourceSimple
}}
}}
</pre>
</pre>
|}
|}
</noinclude>
</noinclude>

Revision as of 02:47, 14 November 2023

What is this?

This is a wrapper around Template:Resource to work better in conjunction with Module:ParseList specifically by Template:ResourceList.

Optional parameters like cost=3 do not work when applying a template to a list with ParseList, so this template enables an alternative syntax that can be used with ParseList.

Usage

{{ResourceHelper | <type>:[count]}}


<> Denotes mandatory parameters, [] denotes optional parameters.

Refer to Template:Resource for a list of the handled resource types.

Examples

Output Input
Ki Point
{{ResourceSimple|ki}}
5Ki Points
{{ResourceSimple|ki:5}}
(ERROR: Use movement m or movement ft.)Movement
{{ResourceSimple|movement:30}}
Action, and 3Ki Points
{{#invoke: ParseList | main | action, ki:3 | useTemplate = ResourceSimple }}
Bonus action, and(ERROR: Use movement m or movement ft.)Movement
{{#invoke: ParseList | main
  | bonus, movement:10 | useTemplate = ResourceSimple
}}