Module Bases - TeamMoonstorm/MoonstormSharedUtils GitHub Wiki

Module Bases

A module base is an abstract class from MoonstormSharedUtils, as their name implies, they're a type of class that acts as a Module for handling ContentBase classes, The module base system works with static methods for handling the respective content classes fed into them, however, for adding new ContentBase classes, one requires to inherit from the ModuleBase itself. (Which is why they're abstract in the first place)

For simplicity and less work, MSU also comes with two SubClasses of ModuleBase.

ContentModule

A ContentModule is a type of ModuleBase which's purpose is to add UnityEngine.Object inheriting assets to your mod's SerializableContentPack, most if not all ModuleBases provided by MSU inherit from ContentModule.

public abstract class ContentModule<T> : ModuleBase<T> where T : ContentBase
{
    public abstract R2APISerializableContentPack SerializableContentPack { get; }

    protected bool AddSafely<TAsset>(ref TAsset[] contentPackArray, TAsset content, string correspondingArrayName = null) where TAsset : UnityEngine.Object
    {
        if (contentPackArray.Contains(content)) //Content already in the contentPack for whatever reason? return true;
        {
            MSULog.Warning($"Content {content} was already in {SerializableContentPack}'s {correspondingArrayName ?? content.GetType().Name} array!\n" +
                $"MSU automatically adds the content piece to its corresponding array in initialization, do not add it beforehand.");
            return true;
        }

        HG.ArrayUtils.ArrayAppend(ref contentPackArray, content);
        return true;
    }
}

BundleModule

Unlike ContentModule, the BundleModule is a subclass of ModuleBase which's main work is to handle specific assets that are not related to ContentPack assets, unlike the ModuleBase and the ContentBase, a BundleModule by definition does NOT handle a ContentBase class by definition.

public abstract class BundleModule : ModuleBase<ContentBase>
{
    public abstract AssetBundle MainBundle { get; }

    protected sealed override void InitializeContent(ContentBase contentClass)
    {
        throw new System.NotSupportedException($"A BundleModule does not have a ContentBase by definition.");
    }

    protected IEnumerable<T> GetContentClasses<T>(Type excludedType = null) where T : ContentBase
    {
        throw new System.NotSupportedException($"A BundleModule does not have a ContentBase by definition.");
    }

    public TObject Load<TObject>(string name) where TObject : UObject
    {
        return MainBundle.LoadAsset<TObject>(name);
    }

    public TObject[] LoadAll<TObject>() where TObject : UObject
    {
        return MainBundle.LoadAllAssets<TObject>();
    }
}

Provided ModuleBases by MSU

MSU comes bundled with a total of 14 ModuleBases, 13 of which inherit from ContentModule and one which inherits from BundleModule

The provided module bases by MSU will usually contain the following properties and utilities:

  • an abstract property of either R2APISerializableContentPack or Assetbundle, depending if the class is a Bundle or Content module
  • The following only apply to ContentModules
    • A ReadOnly collection that's used to access the initialized pieces, this only apppplies to ContentModules
    • An action that gets invoked when the ReadOnly collection of a ContentModule gets initialized.
    • A method for obtaining all the ContentBases the ContentModule handles from your assembly, this method will also create instances of them using the Activator class.
    • A method for adding and initializing the content base.
Module Name Module Type Type of Content ContentBase Class Usage Extra Interactions
ArtifactModuleBase ContentModule ArtifactDefs ArtifactBase Automatically handles the process of hooking onto methods using the game's RunArtifactManager Has support for custom ArtifactCodes using R2API's ArtifactCodeAPI
BuffModuleBase ContentModule BuffDefs BuffBase Allows the ability to easily add overlay materials to bodies afflicted by the buff, also contains code for making BuffBodyBehaviorBases to work properly None
CharacterModuleBase ContentModule CharacterBodies, CharacterMasters, Survivors and Monsters CharacterBase (and also Survivor and Monster Bases, both of which inherit from CharacterBase) Monsters intialized via a MonsterBase class will automatically be added to stages assuming their MSMonsterDirectorCard is assigned. None
DamageTypeModuleBase ModuleBase DamageTypes DamageTypeBase Allows for managing and handling ModdedDamageTypes added by R2API's DamageAPI None
EliteModuleBase ContentModule EliteDefs EliteEquipmentBase Used for adding Elites to the game, with the extended MSEliteDef you can easily create unique looking elites and easily add them to the game Has a dependency on EquipmentBase, it is recommended to read this Guide in order to understand how the EliteModuleBase works
EliteTierDefModuleBase ModuleBase CombatDirector's EliteTierDef EliteTierDefBase Creates new EliteTiers using the SerializableEliteTierdef More information on using the EliteTierModule can be found here
EquipmentModuleBase ContentModule EquipmentDefs EquipmentBase Automatically handles the process of activating the equipment's on use effect EliteModuleBase depends on this class
InteractableModuleBase ContentModule Interactable Prefabs InteractableBase Automatically adds the interactable prefab to stages if the MSInteractableDirectorCard is provided
ItemDispplayModuleBase BundleModule ItemDisplays None Automatically handles MSU's NamedIDRS and ItemDisplayDictionary scriptable objects. More information on the IDRS system of MSU can be found here
ItemModuleBase ContentModule ItemDefs ItemBase Generally used for handling the ItemBodyBehaviors of each ItemDef, or hooking to different methods for ensuring proper item functionality
ProjectileModuleBase ContentModule Projectile Prefabs ProjectileBase Generally used for finishing the setup of a projectile
SceneModuleBase ContentModule Scene Defs SceneBase Manages Scenes for the game, works with Rai of Stages
UnlockablesModuleBase ContentModule UnlockableDefs and AchievementDefs UnlockableBase Handles the addition of unlockables that have an achievement tied to them, the UnlockableModuleBase has the ability to add the Unlockable only if the required content bases are initialized (For examplpe, if your survivor has an unlock and achievement, you can add their CharacterBase class as a dependency, and the UnlockableModuleBase will only load the unlockable if the CharacterBase class is initialized)
⚠️ **GitHub.com Fallback** ⚠️