Skip to content
XuuXiao edited this page Aug 21, 2024 · 2 revisions

ContentLib API Wiki

Welcome to the ContentLib API wiki. This wiki covers the core classes and API's available in ContentLib

  • Core API:
    • (ModDefinition)[]
    • (ContentDefinition)[]
    • (RegisterCallbacks)[]
    • (MatchingTags)[]
  • Enemy API:
    • (EnemyDefinition)[]
  • Hazard API
    • (HazardDefinition)[]

ModDefinition

ModDefinition Class

ModDefinition is a core class in the ContentLib API, representing a mod and its content.

  • Properties

    • string ModGUID { get; } - A unique identifier for the mod.
    • string ModName { get; } - The name of the mod.
    • List<ContentDefinition> Content { get; } - A list of content definitions associated with the mod.
  • Static Properties

    • IReadOnlyDictionary<string modGUID, ModDefinition> AllMods { get; } - An immutable dictionary of all mods by GUID.

MD:Methods

  1. static ModDefinition Create(PluginInfo pluginInfo)

    • Creates a new ModDefinition using the provided PluginInfo.
    • Throws an exception if pluginInfo is null.
    • Usage:
    var modDef = ModDefinition.Create(pluginInfo);
  2. static ModDefinition Create(BepInPlugin bepInPlugin)

    • Creates a new ModDefinition using the provided BepInPlugin.
    • Throws an exception if bepInPlugin is null.
  3. static ModDefinition Create(string modGUID, string modName)

    • Tries to return an identical ModDefinition based on modGUID if found, otherwise, creates a new ModDefinition using the provided GUID and name.
    • Throws an exception if modGUID or modName are null or empty.
    • Usage:
    var modDef = ModDefinition.Create("com.github.exampleauthor.examplemod", "Example Mod");
  4. void RegisterContent()

    • Registers all content in the ModDefinition
    • Usage:
    modDef.RegisterContent();

ContentDefinition

ContentDefinition Class

ContentDefinition is an abstract class representing a piece of content in a mod.

  • Properties
    • [NonSerialized] ModDefinition Mod { get; } - The mod to which this content belongs.
    • [NonSerialized] bool IsRegistered { get; } - Indicates whether the content is registered.
  • Properties to be implemented by inheriting classes
    • Ignore<Content>DefinitionValidationFlags IgnoreValidationFlags { get; set; }

CD:Methods

  1. virtual (bool, string) Validate()

    • Validates the content. If the validation fails, a message is returned.
    • Usage:
    var (isValid, message) = contentDef.Validate();
  2. abstract Register()

    • Registers the content. If validation fails, an exception is thrown.

RegisterCallbacks

RegisterCallbacks Class

RegisterCallbacks<T> provides a mechanism to register callbacks for content registration events.

  • Delegate
    • CallbackInvoker(ModDefinition modDefinition, string contentDefinitionName, bool isBefore, T contentDefinition)

RC:Methods

  1. void RegisterCallbacks(ref CallbackInvoker callbackInvoker)
    • Registers the callback invoker.
  2. void AddOnBeforeRegister(string authorName, string modName, string contentDefinitionName, Action<T> eventHandler)
    • Adds a callback to be invoked before content registration using AuthorName and ModName. void AddOnBeforeRegister(ModDefintion modDefinition, string contentDefinitionName, Action<T> eventHandler)
    • Adds a callback to be invoked before content registration using ModDefinition.
  3. void AddOnAfterRegister(string authorName, string modName, string contentDefinitionName, Action<T> eventHandler)
    • Adds a callback to be invoked after content registration using AuthorName and ModName. void AddOnAfterRegister(ModDefinition modDefinition, string contentDefinitionName, Action<T> eventHandler)
    • Adds a callback to be invoked after content registration using ModDefinition.

MatchingTags

MatchingTags Class

MatchingTags represents a collection of tags with associated weights.

  • Properties
    • List<WeightedTagsGroup> ModNameTags - Tags related to mod names.
    • List<WeightedTagsGroup> AuthorNameTags - Tags related to author names.

EnemyDefinition

EnemyDefinition Class

EnemyDefinition is a content definition for enemy types in the game.

  • Properties
    • EnemyType enemyType { get; set; } - The type of enemy.
    • LevelMatchingTags InsideLevelMatchingTags { get; set; }
    • LevelMatchingTags OutsideLevelMatchingTags { get; set; }
    • LevelMatchingTags DaytimeLevelMatchingTags { get; set; }
    • IgnoreEnemyDefinitionValidationFlags IgnoreValidationFlags { get; set; }

ED:Methods

  1. static EnemyDefinition Create(EnemyType? enemyType)

    • Creates a new EnemyDefinition instance.
    • Usage:
    var enemyDef = EnemyDefinition.Create(enemyType);
  2. static RegisterCallbacks<EnemyDefinition> Callbacks { get; }

    • Provides callbacks for enemy registration events.
  3. override (bool, string) Validate()

    • Validates the enemy definition.
  4. override Register()

    • Registers the enemy definition.