some minor improvements

This commit is contained in:
Az committed 2026-11-18 01:37:41 -05:00
1 parent c51ad7e0de
commit fc4f3d1aa0
11 files changed
+36 -39

No files matched your search

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Modifiers;
using MiraAPI.Roles;
using MiraAPI.Utilities;
@@ -46,7 +45,6 @@ public abstract class AbstractOptionGroup
/// <summary>
/// Gets the sprite of the group that is displayed in the match info guide.
/// </summary>
[HideFromIl2Cpp]
public virtual LoadableAsset<Sprite> Sprite => MiraAssets.IconSettings;
/// <summary>
+1 -9
View File
@@ -55,15 +55,6 @@ public sealed class ModdedArray<T> : IList<T>, IReadOnlyList<T>, IList, IModdedA
items = [.. collection];
}
/// <summary>
/// Initializes a new instance of the <see cref="ModdedArray{T}"/> class with initial values.
/// </summary>
/// <param name="span">The initial span of values to initialise with.</param>
public ModdedArray(Span<T> span)
{
items = [.. span];
}
/// <summary>
/// Initializes a new instance of the <see cref="ModdedArray{T}"/> class with initial values.
/// </summary>
@@ -178,6 +169,7 @@ public sealed class ModdedArray<T> : IList<T>, IReadOnlyList<T>, IList, IModdedA
{
listAttribute = attribute;
typedAttribute = attribute as ITypedOptionList<T>;
Refresh();
}
/// <inheritdoc/>
+10 -2
View File
@@ -397,8 +397,16 @@ public static class ModdedOptionsManager
continue;
}
option.ShowNotification = showNotifs;
option.HandleNetData(netData.Data);
try
{
option.ShowNotification = showNotifs;
option.HandleNetData(netData.Data);
}
catch (Exception e)
{
option.ShowNotification = true;
Error(e);
}
}
foreach (var plugin in MiraPluginManager.Instance.RegisteredPlugins)
@@ -60,7 +60,7 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
var index = Array.IndexOf(UnderlyingValues, value);
if (index == -1)
Info($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}");
Warning($"Cannot find a valid index for {value}. Returning -1 instead. Values: {string.Join(", ", Values)}");
return index;
}
@@ -120,6 +120,7 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
if ((uint)index < (uint)UnderlyingValues.Length)
return UnderlyingValues[index];
Warning($"Received an index {index} when there wasn't enough values (Length: {UnderlyingValues.Length})");
return UnderlyingValues.Length > 0 ? UnderlyingValues[0] : default!;
}
}
@@ -111,7 +111,7 @@ public class ModdedEnumOption : ModdedBaseEnumOption<int>
}
/// <inheritdoc />
protected internal override ConfigDescription? CreateDescription()
protected override ConfigDescription? CreateDescription()
{
return new(string.Empty, new AcceptableValueList<int>(UnderlyingValues));
}
@@ -197,7 +197,7 @@ public class ModdedEnumOption<T> : ModdedBaseEnumOption<T>
}
/// <inheritdoc />
protected internal override ConfigDescription? CreateDescription()
protected override ConfigDescription? CreateDescription()
{
return new(string.Empty, new AcceptableEnumValues<T>(UnderlyingValues));
}
@@ -93,7 +93,7 @@ public class ModdedNumberOption : ModdedOption<float>
string? formatString = null,
bool halfIncrements = false,
bool includeInPreset = true)
: base(groupPrefix, title, defaultValue, includeInPreset)
: base(groupPrefix, title, Math.Clamp(defaultValue, min, max), includeInPreset)
{
Min = min;
Max = max;
@@ -102,15 +102,12 @@ public class ModdedNumberOption : ModdedOption<float>
ZeroWordValue = zeroBehavior;
ShiftIncrement = halfIncrements;
NegativeWordValue = negativeBehavior;
IsInt = defaultValue.IsInteger() &&
IsInt = DefaultValue.IsInteger() &&
Increment.IsInteger() &&
Value.IsInteger() &&
Min.IsInteger() &&
Max.IsInteger();
FormatString = formatString ?? (IsInt ? "0" : "0.0");
Value = Mathf.Clamp(defaultValue, min, max);
if (IsInt)
{
var data = ScriptableObject.CreateInstance<IntGameSetting>();
@@ -297,7 +294,7 @@ public class ModdedNumberOption : ModdedOption<float>
/// <inheritdoc />
public override float GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour)
{
return Mathf.Clamp(optionBehaviour.GetFloat(), Min, Max);
return Math.Clamp(optionBehaviour.GetFloat(), Min, Max);
}
/// <inheritdoc />
@@ -316,7 +313,7 @@ public class ModdedNumberOption : ModdedOption<float>
}
/// <inheritdoc />
protected internal override ConfigDescription? CreateDescription()
protected override ConfigDescription? CreateDescription()
{
return new(string.Empty, new AcceptableValueRange<float>(Min, Max));
}
@@ -262,9 +262,11 @@ public abstract class ModdedOption<T>(string groupPrefix, string title, T defaul
return newValue;
}
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Internal code.)
protected internal virtual ConfigDescription? CreateDescription()
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>
/// Creates a <see cref="ConfigDescription"/> instance for the option's backing config.
/// </summary>
/// <returns>The option's config description, or null if there is none.</returns>
protected virtual ConfigDescription? CreateDescription()
{
return null;
}
@@ -67,8 +67,12 @@ public class ModdedPlayerOption : ModdedOption<int>
PlayerOption playerOpt,
Transform container)
{
var oldPlayer = GetPlayerValue();
Values = GetFilteredPlayers();
var newIndex = oldPlayer ? Values.IndexOf(oldPlayer!) : -1;
Value = newIndex >= 0 ? newIndex : (AllowNone ? -1 : 0);
var playerOption = Object.Instantiate(playerOpt, container);
playerOption.name = $"{ParentMod!.OptionsTitleText}.PlayerOption.{Title}";
@@ -78,7 +82,7 @@ public class ModdedPlayerOption : ModdedOption<int>
playerOption.Title = StringName;
playerOption.Values = Values.ToIl2CppList();
playerOption.Value = Value;
playerOption.playerIndex = Values.FindIndex(p => p.PlayerId == Value);
playerOption.playerIndex = Value;
playerOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
playerOption.SetValueText();
@@ -153,8 +157,8 @@ public class ModdedPlayerOption : ModdedOption<int>
public override string GetDisplayValue()
{
var player = GetPlayerValue();
return !player
? TranslationController.Instance.GetString(StringNames.None)
: player!.PlayerName;
return player
? player!.PlayerName
: TranslationController.Instance.GetString(StringNames.None);
}
}
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using BepInEx.Configuration;
@@ -54,6 +53,8 @@ public class ModdedStringOption : ModdedBaseStringOption<string>
[Obsolete("Use the Setter feature of modded options to simulate conditional values. This wil be removed in a future version.")]
public void RegisterExtraValue(string value, int index = -1)
{
Warning("Use the Setter feature of modded options to simulate conditional values.");
if (!Values.Contains(value))
{
if (index <= -1)
@@ -97,7 +98,7 @@ public class ModdedStringOption : ModdedBaseStringOption<string>
/// <inheritdoc />
public override NetData GetNetData()
{
return new NetData(Id, Encoding.Unicode.GetBytes(Convert.ToString(Value, NumberFormatInfo.InvariantInfo)));
return new NetData(Id, Encoding.Unicode.GetBytes(Value));
}
/// <inheritdoc />
@@ -107,7 +108,7 @@ public class ModdedStringOption : ModdedBaseStringOption<string>
}
/// <inheritdoc />
protected internal override ConfigDescription? CreateDescription()
protected override ConfigDescription? CreateDescription()
{
return new(string.Empty, new AcceptableValueList<string>(UnderlyingValues));
}
-2
View File
@@ -171,7 +171,6 @@ public abstract class BaseModifier : IOptionable
/// <summary>
/// Gets the list of abilities or other similar information to display below the text of a modifier's wiki page.
/// </summary>
[HideFromIl2Cpp]
public virtual List<AdvancedWikiAbilityDescription> WikiAbilities => [];
/// <summary>
@@ -182,7 +181,6 @@ public abstract class BaseModifier : IOptionable
/// <summary>
/// Gets the <see cref="TMP_SpriteAsset"/> for the Modifier Icon.
/// </summary>
[HideFromIl2Cpp]
public virtual TMP_SpriteAsset IconTmp => null!;
/// <summary>
-4
View File
@@ -81,25 +81,21 @@ public record struct CustomRoleConfiguration
/// <summary>
/// Gets or sets the <see cref="Sprite"/> used for the Role Options menu screenshot.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? OptionsScreenshot { get; set; } = null;
/// <summary>
/// Gets or sets the <see cref="Sprite"/> used for the Role Icon.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<Sprite>? Icon { get; set; } = null;
/// <summary>
/// Gets or sets the <see cref="TMP_SpriteAsset"/> for the Role Icon.
/// </summary>
[HideFromIl2Cpp]
public TMP_SpriteAsset IconTmp { get; set; }
/// <summary>
/// Gets or sets the Intro sound for the Role.
/// </summary>
[HideFromIl2Cpp]
public LoadableAsset<AudioClip>? IntroSound { get; set; } = null;
/// <summary>