evennia.utils.containers¶
Containers
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)
evennia.GLOBAL_SCRIPTS evennia.OPTION_CLASSES
-
class
evennia.utils.containers.
Container
[源代码]¶ 基类:
object
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.
The container is initialized by a list of modules containing callables.
-
storage_modules
= []¶
-
load_data
()[源代码]¶ Delayed import to avoid eventual circular imports from inside the storage modules.
-
-
class
evennia.utils.containers.
OptionContainer
[源代码]¶ 基类:
evennia.utils.containers.Container
Loads and stores the final list of OPTION CLASSES.
Can access these as properties or dictionary-contents.
-
storage_modules
= ['evennia.utils.optionclasses']¶
-
-
class
evennia.utils.containers.
GlobalScriptContainer
[源代码]¶ 基类:
evennia.utils.containers.Container
Simple Handler object loaded by the Evennia API to contain and manage a game’s Global Scripts. This will list global Scripts created on their own but will also auto-(re)create scripts defined in settings.GLOBAL_SCRIPTS.
示例
import evennia evennia.GLOBAL_SCRIPTS.scriptname
注解
This does not use much of the BaseContainer since it’s not loading callables from settings but a custom dict of tuples.
-
__init__
()[源代码]¶ Note: We must delay loading of typeclasses since this module may get initialized before Scripts are actually initialized.
-
start
()[源代码]¶ Called last in evennia.__init__ to initialize the container late (after script typeclasses have finished loading).
We include all global scripts in the handler and make sure to auto-load time-based scripts.
-
get
(key, default=None)[源代码]¶ 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.
- 参数
key (str) – The name of the script.
default (any, optional) – Value to return if key is not found at all on this container (i.e it cannot be loaded at all).
- 返回
any (any) – The data loaded on this container.
-