Skip to content

The Modular API

Aristeas edited this page Apr 22, 2024 · 17 revisions

The Modular Assemblies Definition API (DefinitionApi from here on) is the beating heart of the framework. All communication between client mods and Modular Assemblies goes through it, and it offers several useful functions to ensure your custom assemblies work properly.

Installation

While the DefinitionApi is best used in the template, it can also be used standalone in your mods. The standalone installation guide can be found here. The template provides a simple project structure for using Modular Assemblies as the focus of your mod and will automatically handle loading your definitions, whereas the standalone DefinitionApi gives you more flexibility in using the framework exactly how your mod demands.

Updating

TODO; basically just copy-paste the latest API version into your existing API file and check for broken references.

API Reference

All public methods are explained in the DefinitionApi's included documentation, but this reference will provide more details and give examples.

API Metainfo

Object Description Example
`void Init(IMyModContext modContext, Action onLoad = null)` Prepares the DefinitionApi for use - this *must* be called before using the API.
Include your mod context and an optional action to be triggered whenever the API fully loads (equivalent to OnReady).
```cs DefinitionApi defApi = new DefinitionApi(); defApi.Init(this.ModContext); ```
`int ApiVersion` The integer DefinitionApi version included in your mod.
The latest API can always be [obtained from here.](https://github.com/StarCoreSE/Modular-Assemblies/blob/main/Data/Scripts/AssemblyScripts/Definitions/DefinitionApi.cs)
```cs MyAPIGateway.Utilities.ShowNotification($"DefinitionApi {defApi.ApiVersion} loaded."); ```
`int FrameworkVersion` The integer Modular Assemblies Framework version currently loaded. ```cs MyAPIGateway.Utilities.ShowNotification($"Modular Assemblies version {defApi.FrameworkVersion} detected."); ```
`bool IsReady` Boolean value representing whether or not the DefinitionApi is ready for use. ```cs public override void UpdateAfterSimulation() { if (!defApi.IsReady) return; // do stuff with the API } ```
`Action OnReady` An action triggered whenever the DefinitionApi is ready to be used. This may be triggered at any time after you call Init(). TODO example