Registry - MSUTeam/MSU GitHub Wiki

Description

The Registry system keeps track of all MSU mods, managing the instantiation and versioning of said mods. For the modder, currently the system provides a way to easily notify your players of updates to your mod, and link them to your mod pages.

Update Checker

From MSU 1.2.0 on, you can easily connect your mod to a GitHub repository to notify users of new updates to your mod. Unfortunately, while we allow linking to NexusMods (and we may be able to allow using it as an update source in the future), it is currently not possible to check for updates from it as its API is closed.

Setting up update-checking is trivial and is done in 2-3 lines. Before you do that, your Git tags must use Semantic Versioning with all the same requirements as MSU mod versions. The Registry system reads the latest full release on your GitHub repository, and compares its tag to the version in the mod on the users machine, assuming they match, nothing happens. If they are different, the user will receive a pop-up upon launching their game, informing them of the update and linking them to your GitHub repository (and optionally your NexusMods page too). It will also notify the user if you are using a non-semver version for your Git tags and let them know the update checker isn't working. !Pasted image 20221118235410.png // TODO LINK TO IMAGE The above image is a preview of how the player's screen will look like upon launching the game with an available update, the two buttons on the bottom right of the mod row might be hidden depending on what ModSources you have set.

ModSource

A ModSource is a place your mod can be downloaded from. Available ModSources are defined in the ModSourceDomain Enum:

ModSourceDomain

This is currently the following Enum located in ::MSU.System.Registry.ModSourceDomain:

::MSU.Class.Enum([
	"GitHub",
	"NexusMods"
]);

addModSource

<Mod>.Registry.addModSource( _domain, _url )
// _domain is an entry in the Enum ::MSU.System.Registry.ModSourceDomain
// _url is a string

_url Must be the _url for your mod in the _domain, this requires the correct format depending on the ModSource, eg "https://www.nexusmods.com/battlebrothers/mods/479" for NexusMods and "https://github.com/MSUTeam/MSU" for GitHub. This is validated with a regex

Adds a new potential ModSource to your mod.

hasModSource

<Mod>.Registry.hasModSouce( _domain )
// _domain is a value in the Enum ::MSU.System.Registry.ModSourceDomain

Returns true if addModSource was successfully called on this mod with this ModSourceDomain, false otherwise.

getModSource

<Mod>.Registry.getModSouce( _domain )
// _domain is a value in the Enum ::MSU.System.Registry.ModSourceDomain

Returns the URL passed with addModSource

setUpdateSource

<Mod>.Registry.setUpdateSource( _modSource )
// _modSource is a value in the Enum ::MSU.System.Registry.ModSourceDomain

Sets a particular ModSource you added with addModSource to be used to compare the version of the local version of the player's mod against. Currently the only acceptable value here is ::MSU.System.Registry.ModSourceDomain.GitHub

hasUpdateSource

<Mod>.Registry.hasUpdateSource()

Returns true if setUpdateSource was successfully called on this Mod, false otherwise.

getUpdateSource

<Mod>.Registry.getUpdateSource()

Returns the ModUpdateSourceDomain this Mod was set to, null if it was never set.

Example

// create your mod
local yourmod = ::MSU.Class.Mod("yourmod", "1.0.0");

// add GitHub mod source
yourmod.Registry.addModSource(::MSU.System.Registry.ModSourceDomain.GitHub, "https://github.com/MSUTeam/MSU");
// this will currently do nothing on its own(though in the future we may add a way to list all MSU mods with links), to affect a players game, we have to set GitHub as our UpdateSource
yourmod.Registry.setUpdateSource(::MSU.System.Registry.ModSourceDomain.GitHub)
// now if you've set up your git tags and releases properly, the mod user will be notified if there's an available release with a version greater than 1.0.0

// add NexusMods mod source (for an easy link)
yourmod.Registry.addModSource(::MSU.System.Registry.ModSourceDomain.NexusMods, "https://www.nexusmods.com/battlebrothers/mods/479");
⚠️ **GitHub.com Fallback** ⚠️