Source code for modloader.modclass
"""This file is free software under the MIT license"""
from modloader import modinfo
[docs]class Mod(object):
"""The Mod class
This is supposed to act like a superclass for mods.
Execution order is as follows:
:meth:`mod_load` -> :meth:`mod_complete`
"""
[docs] def mod_info(self):
"""Get the mod info
Returns:
A tuple with the name, version, author, and (optionally) if the mod is NSFW
"""
raise NotImplementedError("Mod info isn't overriden")
[docs] def mod_load(self):
"""Executes when the mod is loaded
This is where you put patcher code.
See Also:
:meth:`mod_complete`
"""
raise NotImplementedError("Mod load isn't overriden")
[docs] def mod_complete(self):
"""Executes when all mods are loaded
This method is useful for dependency loading but can be left empty otherwise
"""
raise NotImplementedError("Mod complete isn't overriden")
[docs]def loadable_mod(modclass):
"""Annotation to add a Mod subclass to the mod list
Args:
modclass (Mod): The Mod class, not an instance of the Mod class
Raises:
Exception: If the given class is not a subclass of Mod
"""
if not issubclass(modclass, Mod):
raise Exception("Class must be a subclass of Mod")
mod = modclass()
mod.mod_load()
modinfo.add_mod(mod.mod_info()[0], mod)