evennia/docs/3.x/api/evennia.utils.containers.html
2023-12-21 00:12:31 +01:00

296 lines
No EOL
17 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>evennia.utils.containers &#8212; Evennia 3.x documentation</title>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="evennia.utils.create" href="evennia.utils.create.html" />
<link rel="prev" title="evennia.utils.batchprocessors" href="evennia.utils.batchprocessors.html" />
</head><body>
<div class="admonition important">
<p class="first admonition-title">Note</p>
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.utils.create.html" title="evennia.utils.create"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="evennia.utils.batchprocessors.html" title="evennia.utils.batchprocessors"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 3.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.utils.html" accesskey="U">evennia.utils</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.utils.containers</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h4>Previous topic</h4>
<p class="topless"><a href="evennia.utils.batchprocessors.html"
title="previous chapter">evennia.utils.batchprocessors</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="evennia.utils.create.html"
title="next chapter">evennia.utils.create</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/api/evennia.utils.containers.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-evennia.utils.containers">
<span id="evennia-utils-containers"></span><h1>evennia.utils.containers<a class="headerlink" href="#module-evennia.utils.containers" title="Permalink to this headline"></a></h1>
<p>Containers</p>
<p>Containers are storage classes usually initialized from a setting. They
represent Singletons and acts as a convenient place to find resources (
available as properties on the singleton)</p>
<p>evennia.GLOBAL_SCRIPTS
evennia.OPTION_CLASSES</p>
<dl class="py class">
<dt id="evennia.utils.containers.Container">
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.containers.</code><code class="sig-name descname">Container</code><a class="reference internal" href="../_modules/evennia/utils/containers.html#Container"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.Container" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Base container class. A container is simply a storage object whose
properties can be acquired as a property on it. This is generally
considered a read-only affair.</p>
<p>The container is initialized by a list of modules containing callables.</p>
<dl class="py attribute">
<dt id="evennia.utils.containers.Container.storage_modules">
<code class="sig-name descname">storage_modules</code><em class="property"> = []</em><a class="headerlink" href="#evennia.utils.containers.Container.storage_modules" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.Container.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#Container.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.Container.__init__" title="Permalink to this definition"></a></dt>
<dd><p>Read data from module.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.Container.load_data">
<code class="sig-name descname">load_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#Container.load_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.Container.load_data" title="Permalink to this definition"></a></dt>
<dd><p>Delayed import to avoid eventual circular imports from inside
the storage modules.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.Container.get">
<code class="sig-name descname">get</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">key</span></em>, <em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#Container.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.Container.get" title="Permalink to this definition"></a></dt>
<dd><p>Retrive data by key (in case of not knowing it beforehand).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<em>str</em>) The name of the script.</p></li>
<li><p><strong>default</strong> (<em>any</em><em>, </em><em>optional</em>) Value to return if key is not found.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><em>any (any)</em> The data loaded on this container.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.Container.all">
<code class="sig-name descname">all</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#Container.all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.Container.all" title="Permalink to this definition"></a></dt>
<dd><p>Get all stored data</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><em>scripts (list)</em> All global script objects stored on the container.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="evennia.utils.containers.OptionContainer">
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.containers.</code><code class="sig-name descname">OptionContainer</code><a class="reference internal" href="../_modules/evennia/utils/containers.html#OptionContainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.OptionContainer" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#evennia.utils.containers.Container" title="evennia.utils.containers.Container"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.utils.containers.Container</span></code></a></p>
<p>Loads and stores the final list of OPTION CLASSES.</p>
<p>Can access these as properties or dictionary-contents.</p>
<dl class="py attribute">
<dt id="evennia.utils.containers.OptionContainer.storage_modules">
<code class="sig-name descname">storage_modules</code><em class="property"> = ['evennia.utils.optionclasses']</em><a class="headerlink" href="#evennia.utils.containers.OptionContainer.storage_modules" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="py class">
<dt id="evennia.utils.containers.GlobalScriptContainer">
<em class="property">class </em><code class="sig-prename descclassname">evennia.utils.containers.</code><code class="sig-name descname">GlobalScriptContainer</code><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#evennia.utils.containers.Container" title="evennia.utils.containers.Container"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.utils.containers.Container</span></code></a></p>
<p>Simple Handler object loaded by the Evennia API to contain and manage a
games Global Scripts. This will list global Scripts created on their own
but will also auto-(re)create scripts defined in <strong>settings.GLOBAL_SCRIPTS</strong>.</p>
<p class="rubric">Example</p>
<p>import evennia
evennia.GLOBAL_SCRIPTS.scriptname</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This does not use much of the BaseContainer since its not loading
callables from settings but a custom dict of tuples.</p>
</div>
<dl class="py method">
<dt id="evennia.utils.containers.GlobalScriptContainer.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer.__init__" title="Permalink to this definition"></a></dt>
<dd><p>Note: We must delay loading of typeclasses since this module may get
initialized before Scripts are actually initialized.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.GlobalScriptContainer.start">
<code class="sig-name descname">start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer.start"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer.start" title="Permalink to this definition"></a></dt>
<dd><p>Called last in evennia.__init__ to initialize the container late
(after script typeclasses have finished loading).</p>
<p>We include all global scripts in the handler and
make sure to auto-load time-based scripts.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.GlobalScriptContainer.load_data">
<code class="sig-name descname">load_data</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer.load_data"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer.load_data" title="Permalink to this definition"></a></dt>
<dd><p>This delayed import avoids trying to load Scripts before they are
initialized.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.GlobalScriptContainer.get">
<code class="sig-name descname">get</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">key</span></em>, <em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer.get" title="Permalink to this definition"></a></dt>
<dd><p>Retrive data by key (in case of not knowing it beforehand). Any
scripts that are in settings.GLOBAL_SCRIPTS that are not found
will be recreated on-demand.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> (<em>str</em>) The name of the script.</p></li>
<li><p><strong>default</strong> (<em>any</em><em>, </em><em>optional</em>) Value to return if key is not found
at all on this container (i.e it cannot be loaded at all).</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><em>any (any)</em> The data loaded on this container.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.utils.containers.GlobalScriptContainer.all">
<code class="sig-name descname">all</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/utils/containers.html#GlobalScriptContainer.all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.utils.containers.GlobalScriptContainer.all" title="Permalink to this definition"></a></dt>
<dd><p>Get all global scripts. Note that this will not auto-start
scripts defined in settings.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><em>scripts (list)</em> All global script objects stored on the container.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.utils.create.html" title="evennia.utils.create"
>next</a> |</li>
<li class="right" >
<a href="evennia.utils.batchprocessors.html" title="evennia.utils.batchprocessors"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 3.x</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.utils.html" >evennia.utils</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.utils.containers</a></li>
</ul>
</div>
<div class="admonition important">
<p class="first admonition-title">Note</p>
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>