Difference between revisions of "Template:Time"

From Captain of Industry Wiki
Jump to: navigation, search
(full rewrite)
(logic and typo fixes)
Line 1: Line 1:
<includeonly><templatestyles src="Template:Time/styles.css" /><!--
<includeonly><templatestyles src="Template:Time/styles.css" /><!--


** Check if we were given both {{{1}}} (a qty) and {{{2}}} (a time) **
** Calculate how many unnamed parameters we we're missing. **
-->{{#ifeq: {{{1|1}}}{{{2|1}}} < 1 |<!--
-->{{#vardefine: param_count | <!--
  -->{{#expr: {{#if: {{{1|}}} | 1 | 0}} + {{#if: {{{2|}}} | 1 | 0}} }}<!--
-->}}<!--


  ** Unset var `isitblue` in case there were any previous calls on the same article **
** Unset var `isitblue` in case there were any previous calls on the same article **
  -->{{#vardefine: isitblue}}<!--
-->{{#vardefine: isitblue}}<!--
 
** We received nothing so we're going to print the "/ 60 s" in plain white and quit. **
-->{{#ifeq: {{#var: param_count}} | 0 |<!--
  --><span class="nowrap inline_time">/ 60 [[File:Clock.png|link=Time|16x16px]]</span><!--
-->}}<!--
 
** We only received {{{1}}} or {{{2}}} so we'll assume that's a time and not a quantity. **


   ** Check if the time is already 60 seconds and set variable `isitblue` to `_60s` if true. **
   ** Check if the time is already 60 seconds and set variable `isitblue` to `_60s` if true. **
   ** Note: Bit of a trick here: `_60s` is both the name of the CSS class to make text blue, **
   ** Note: Bit of a trick here: `_60s` is both the name of the CSS class to make text blue, **
   ** as the well as the additional bit of the filename between the regular and blue clocks. **
   ** as the well as the additional bit of the filename between the regular and blue clocks. **
-->{{#ifeq: {{#var: param_count}} | 1 |<!--
  -->{{#ifeq: {{{1|}}} | 60 | {{#vardefine: isitblue | _60s}} }}<!--
  --><span class="nowrap inline_time {{#var: isitblue}}">/ {{{1|}}}{{{2|}}} [[File:Clock{{#var: isitblue}}.png|link=Time|16x16px]]</span><!--
-->}}<!--
** We received {{{1}}} and {{{2}}} so we'll assume they're a qty and a time, in that order. **
-->{{#ifeq: {{#var: param_count}} | 2 |<!--


   -->{{#ifeq: {{{2}}} | 60 | {{#vardefine: isitblue = _60s}} }}<!--
   -->{{#ifeq: {{{2}}} | 60 | {{#vardefine: isitblue | _60s}} }}<!--
   --><span class="nowrap inline_time {{#var: isitblue}}">{{{1}}} / {{{2}}} [[File:Clock{{#var: isitblue}}.png|link=Time|16x16px]]</span><!--
   --><span class="nowrap inline_time {{#var: isitblue}}">{{{1}}} / {{{2}}} [[File:Clock{{#var: isitblue}}.png|link=Time|16x16px]]</span><!--
   -->{{#ifeq: {{{2}}} | 60 ||<!--
   -->{{#ifeq: {{{2}}} | 60 ||<!--
     -->{{#if: {{{per60|}}} |<!--
     -->{{#if: {{{per60|}}} |<!--
       --><span style="nowrap inline_time _60s"> ({{#expr: 60/{{{2}}}*{{{1}}} round 2 }} / 60 [[File:Clock_60s.png|link=Time|16x16px]])</span><!--
       --><span class="nowrap inline_time _60s"><!--
      --> ({{#expr: 60/{{{2}}}*{{{1}}} round 2 }} / 60 [[File:Clock_60s.png|link=Time|16x16px]])<!--
      --></span><!--
     -->}}<!--
     -->}}<!--
   -->}}<!--
   -->}}<!--
-->}}<!--


  -->|<!--
  ** We only received {{{1}}} or {{{2}}} so we'll assume that's a time and not a quantity **
  -->{{#ifeq: {{{1}}} | 60 | {{#vardefine: isitblue = _60s}} }}<!--
  --><span class="nowrap inline_time {{#var: isitblue}}">/ {{{1}}} [[File:Clock{{#var: isitblue}}.png|link=Time|16x16px]]</span><!--
-->}}<!--
--></includeonly><!--
--></includeonly><!--
--><noinclude>{{documentation}}
--><noinclude>{{documentation}}</noinclude>

Revision as of 06:13, 23 January 2022

Template documentation (for the above template, sometimes hidden or invisible) [view] [edit] [history] [refresh]


Purpose
To provide a quick, shorthand method to refer to lengths of game time and rates of production. Additionally, to automatically do the math to convert from recipe qty/length to per 60 second formats if so desired.
Automations
  • Automatically highlights blue if a per-60 rate is detected (examples for disabling this feature are below)
  • As requested, performs the math to convert to a per-60 second rate and display it already marked up.
Limitations
When an automatic version to a per-60 second rate is performed, the number of digits to round is fixed at 2. For integer results, they are not displayed.
Usage
To output just a length of time and nothing else.
Markup Renders as
{{Time|40}}

/ 40 Clock.png

{{Time}}

/ 60 Clock.png

To output a rate.
Markup Renders as
{{Time|40|20}}

40 / 20 Clock.png

20 {{Time}}

20 / 60 Clock.png

To output with 60 highlighting, but no conversion.
Markup Renders as
{{Time|60}}

/ 60 Clock 60s.png

{{Time|40|60}}

40 / 60 Clock 60s.png

To output with 60 highlighting and per-60 conversion (ignored when already per-60).
Markup Renders as
{{Time|40|20|per60=y}}

40 / 20 Clock.png (120 / 60 Clock 60s.png)

{{Time|30|60|per60=y}}

30 / 60 Clock 60s.png

To output just time icon.
Markup Renders as
{{Time|icononly=y}}

/ 60 Clock.png

The above text is transcluded from Template:Time/doc; you can change it or view its history. (How does this work?)
If you're done making changes, please refresh the text. (Why?)
You can experiment in this template's sandbox (edit | diff) and testcases (create) pages.
Please add categories and interwikis to Template:Time/doc. (View all subpages of this page.)