<spanid="evennia-contrib-base-systems-custom-gametime-custom-gametime"></span><h1>evennia.contrib.base_systems.custom_gametime.custom_gametime<aclass="headerlink"href="#module-evennia.contrib.base_systems.custom_gametime.custom_gametime"title="Permalink to this headline">¶</a></h1>
<p>Custom gametime</p>
<p>Contrib - Griatch 2017, vlgeoff 2017</p>
<p>This implements the evennia.utils.gametime module but supporting
a custom calendar for your game world. It allows for scheduling
events to happen at given in-game times, taking this custom
calendar into account.</p>
<p>Usage:</p>
<p>Use as the normal gametime module, that is by importing and using the
helper functions in this module in your own code. The calendar can be
customized by adding the <strong>TIME_UNITS</strong> dictionary to your settings
file. This maps unit names to their length, expressed in the smallest
unit. Here’s the default as an example:</p>
<blockquote>
<div><dlclass="simple">
<dt>TIME_UNITS = {</dt><dd><p>“sec”: 1,
“min”: 60,
“hr”: 60 * 60,
“hour”: 60 * 60,
“day”: 60 * 60 * 24,
“week”: 60 * 60 * 24 * 7,
“month”: 60 * 60 * 24 * 7 * 4,
“yr”: 60 * 60 * 24 * 7 * 4 * 12,
“year”: 60 * 60 * 24 * 7 * 4 * 12, }</p>
</dd>
</dl>
</div></blockquote>
<p>When using a custom calendar, these time unit names are used as kwargs to
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">time_to_tuple</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">seconds</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">divisors</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#time_to_tuple"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.time_to_tuple"title="Permalink to this definition">¶</a></dt>
<dd><p>Helper function. Creates a tuple of even dividends given a range
of divisors.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>seconds</strong> (<em>int</em>) – Number of seconds to format</p></li>
<li><p><strong>*divisors</strong> (<em>int</em>) – a sequence of numbers of integer dividends. The
number of seconds will be integer-divided by the first number in
this sequence, the remainder will be divided with the second and
<dt>This tuple has length len(<ahref="#id1"><spanclass="problematic"id="id2">*</span></a>args)+1, with the</dt><dd><p>last element being the last remaining seconds not evenly
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">gametime_to_realtime</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">format</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#gametime_to_realtime"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.gametime_to_realtime"title="Permalink to this definition">¶</a></dt>
<dd><p>This method helps to figure out the real-world time it will take until an
in-game time has passed. E.g. if an event should take place a month later
in-game, you will be able to find the number of real-world seconds this
corresponds to (hint: Interval events deal with real life seconds).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Keyword Arguments</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>format</strong> (<em>bool</em>) – Formatting the output.</p></li>
<li><p><strong>month etc</strong> (<em>days</em><em>,</em>) – These are the names of time units that must
match the <strong>settings.TIME_UNITS</strong> dict keys.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>time (float or tuple)</em>–</p>
<dlclass="simple">
<dt>The realtime difference or the same</dt><dd><p>time split up into time units.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Example</p>
<dlclass="simple">
<dt>gametime_to_realtime(days=2) -> number of seconds in real life from</dt><dd><p>now after which 2 in-game days will have passed.</p>
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">custom_gametime</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">absolute</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#custom_gametime"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.custom_gametime"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the custom game time as a tuple of units, as defined in settings.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>absolute</strong> (<em>bool</em><em>, </em><em>optional</em>) – return the relative or absolute time.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>The tuple describing the game time. The length of the tuple
is related to the number of unique units defined in the
settings. By default, the tuple would be (year, month,
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">real_seconds_until</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#real_seconds_until"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.real_seconds_until"title="Permalink to this definition">¶</a></dt>
<dd><p>Return the real seconds until game time.</p>
<p>If the game time is 5:00, TIME_FACTOR is set to 2 and you ask
the number of seconds until it’s 5:10, then this function should
return 300 (5 minutes).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>(</strong><strong>str</strong> (<em>times</em>) – int): the time units.</p>
</dd>
</dl>
<pclass="rubric">Example</p>
<p>real_seconds_until(hour=5, min=10, sec=0)</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p>The number of real seconds before the given game time is up.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>day/week/month start from 1, not from 0 (there is no month 0 for example)</p>
<codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">schedule</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">callback</span></em>, <emclass="sig-param"><spanclass="n">repeat</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#schedule"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.schedule"title="Permalink to this definition">¶</a></dt>
<dd><p>Call the callback when the game time is up.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>callback</strong> (<em>function</em>) – The callback function that will be called. This
must be a top-level function since the script will be persistent.</p></li>
<li><p><strong>repeat</strong> (<em>bool</em><em>, </em><em>optional</em>) – Should the callback be called regularly?</p></li>
<li><p><strong>day</strong>– int): The time units to call the callback; should
match the keys of TIME_UNITS.</p></li>
<li><p><strong>month</strong>– int): The time units to call the callback; should
match the keys of TIME_UNITS.</p></li>
<li><p><strong>(</strong><strong>str</strong> (<em>etc</em>) – int): The time units to call the callback; should
match the keys of TIME_UNITS.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>script (Script)</em>– The created script.</p>
</dd>
</dl>
<pclass="rubric">Examples</p>
<p>schedule(func, min=5, sec=0) # Will call next hour at :05.
schedule(func, hour=2, min=30, sec=0) # Will call the next day at 02:30.</p>
<pclass="rubric">Notes</p>
<p>This function will setup a script that will be called when the
time corresponds to the game time. If the game is stopped for
more than a few seconds, the callback may be called with a
slight delay. If <strong>repeat</strong> is set to True, the callback will be
called again next time the game time matches the given time.
The time is given in units as keyword arguments.</p>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.base_systems.custom_gametime.custom_gametime.</code><codeclass="sig-name descname">GametimeScript</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#GametimeScript"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_script_creation</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#GametimeScript.at_script_creation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.at_script_creation"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">at_repeat</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/base_systems/custom_gametime/custom_gametime.html#GametimeScript.at_repeat"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.at_repeat"title="Permalink to this definition">¶</a></dt>
<emclass="property">exception </em><codeclass="sig-name descname">DoesNotExist</code><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.DoesNotExist"title="Permalink to this definition">¶</a></dt>
<emclass="property">exception </em><codeclass="sig-name descname">MultipleObjectsReturned</code><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.MultipleObjectsReturned"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">path</code><emclass="property"> = 'evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript'</em><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.path"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">typename</code><emclass="property"> = 'GametimeScript'</em><aclass="headerlink"href="#evennia.contrib.base_systems.custom_gametime.custom_gametime.GametimeScript.typename"title="Permalink to this definition">¶</a></dt>