add register required to api

This commit is contained in:
_nebula 2023-07-31 21:22:54 +01:00
parent 3a81238831
commit 62c654318e
4 changed files with 21 additions and 7 deletions

View File

@ -1,10 +1,13 @@
using System;
using OWML.Common;
using UnityEngine.Events;
namespace APITestMod;
public interface IQSBAPI
{
/// <summary>
/// If called, all players connected to YOUR hosted game must have this mod installed.
/// </summary>
void RegisterRequiredForAllPlayers(IModBehaviour mod);
/// <summary>
/// Returns the player ID of the current player.
/// </summary>
@ -65,4 +68,4 @@ public interface IQSBAPI
/// <param name="messageType">The unique key of the message.</param>
/// <param name="handler">The action to be ran when the message is received. The uint is the player ID that sent the messsage.</param>
void RegisterHandler<T>(string messageType, Action<uint, T> handler);
}
}

View File

@ -1,10 +1,14 @@
using System;
using OWML.Common;
using UnityEngine.Events;
namespace QSB.API;
public interface IQSBAPI
{
/// <summary>
/// If called, all players connected to YOUR hosted game must have this mod installed.
/// </summary>
void RegisterRequiredForAllPlayers(IModBehaviour mod);
/// <summary>
/// Returns the player ID of the current player.
/// </summary>

View File

@ -1,5 +1,6 @@
using System;
using System.Linq;
using OWML.Common;
using QSB.API.Messages;
using QSB.Messaging;
using QSB.Player;
@ -9,6 +10,12 @@ namespace QSB.API;
public class QSBAPI : IQSBAPI
{
public void RegisterRequiredForAllPlayers(IModBehaviour mod)
{
var uniqueName = mod.ModHelper.Manifest.UniqueName;
QSBCore.Addons.Add(uniqueName, mod);
}
public uint GetLocalPlayerID() => QSBPlayerManager.LocalPlayerId;
public string GetPlayerName(uint playerId) => QSBPlayerManager.GetPlayer(playerId).Name;
public uint[] GetPlayerIDs() => QSBPlayerManager.PlayerList.Select(x => x.PlayerId).ToArray();

View File

@ -235,7 +235,7 @@ public class QSBCore : ModBehaviour
/// This addon MUST NOT send any network messages, or create any worldobjects.
/// </summary>
/// <param name="addon">The behaviour of the addon.</param>
public static void RegisterCosmeticAddon(IModBehaviour addon)
public static void RegisterNotRequiredForAllPlayers(IModBehaviour addon)
{
var uniqueName = addon.ModHelper.Manifest.UniqueName;
var addonAssembly = addon.GetType().Assembly;