mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-28 09:39:08 +00:00
Some cleanup
This commit is contained in:
1 parent
1eb13d0513
commit
bb45bab198
11 files changed
+80
-39
No files matched your search
@@ -8,9 +8,25 @@ public abstract class AbstractCosmeticsGroup
|
||||
public List<SkinData> Skins { get; } = [];
|
||||
public List<VisorData> Visors { get; } = [];
|
||||
public List<NamePlateData> Nameplates { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The name of the group. Visible in options menu.
|
||||
/// </summary>
|
||||
public abstract string GroupName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A function that returns whether the group should be visible or not.
|
||||
/// </summary>
|
||||
public virtual Func<bool> GroupVisible => () => true;
|
||||
|
||||
/// <summary>
|
||||
/// The sorting mode of individual hats within this group.
|
||||
/// </summary>
|
||||
public virtual SortingMode SortingMode { get; } = SortingMode.AlphabeticName;
|
||||
|
||||
/// <summary>
|
||||
/// The priority of a group for sorting groups.
|
||||
/// </summary>
|
||||
public virtual int SortingPriority { get; } = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
internal class AbstractCosmeticsGroupComparer : Comparer<AbstractCosmeticsGroup>
|
||||
|
||||
@@ -6,8 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
public static class CustomCosmeticManager
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MiraAPI.Cosmetics;
|
||||
public class VanillaCosmeticsGroup : AbstractCosmeticsGroup
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Cosmetics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MiraAPI.Patches.Cosmetics;
|
||||
[HarmonyPatch(typeof(HatManager), nameof(HatManager.GetHatById))]
|
||||
public static class HatManagerPatch
|
||||
{
|
||||
public static bool Prefix(HatManager __instance, string hatId, ref HatData __result)
|
||||
{
|
||||
__result = (HatData)CustomCosmeticManager._cosmeticToGroup.FirstOrDefault(x => string.Equals(x.Key.ProdId, hatId)).Key;
|
||||
if (__result) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,28 @@ namespace MiraAPI.Utilities.Assets.Addressable;
|
||||
/// </summary>
|
||||
public class Catalog(string CatalogPath)
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the catalog asynchronously.
|
||||
/// </summary>
|
||||
public void LoadCatalogAsync() {
|
||||
Coroutines.Start(LoadCatalogAsynchronously());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the catalog. This must be done before you can call any addressables.
|
||||
/// </summary>
|
||||
public void LoadCatalog()
|
||||
{
|
||||
Addressables.LoadContentCatalog(CatalogPath).WaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the network catalogs.
|
||||
/// </summary>
|
||||
public void UpdateNetworkCatalog()
|
||||
{
|
||||
Coroutines.Start(UpdateCatalog());
|
||||
}
|
||||
protected IEnumerator LoadCatalogAsynchronously()
|
||||
{
|
||||
AsyncOperationHandle<IResourceLocator> handle = Addressables.LoadContentCatalogAsync(CatalogPath, true);
|
||||
|
||||
@@ -4,18 +4,37 @@ using System.Reflection;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class for various catalog-related operations.
|
||||
/// </summary>
|
||||
public static class CatalogTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts string filenames to catalog paths within the plugins folder.
|
||||
/// </summary>
|
||||
/// <param name="fileName">A string of the catalog file without the extension</param>
|
||||
/// <returns>The path to the catalog file.</returns>
|
||||
public static string ToLocalPath(this string fileName)
|
||||
{
|
||||
return Path.GetDirectoryName(Assembly.GetAssembly(typeof(MiraApiPlugin)).Location) + $"\\{fileName}.catalog";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the resource locations of a specific label.
|
||||
/// </summary>
|
||||
/// <param name="label">The label of the addressables assets</param>
|
||||
/// <returns>An IList of IResourceLocation</returns>
|
||||
public static Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> GetResourceLocation(string label)
|
||||
{
|
||||
return Addressables.LoadResourceLocationsAsync(label).WaitForCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the resource locations of multiple specific labels.
|
||||
/// </summary>
|
||||
/// <param name="label">The label of the addressables assets</param>
|
||||
/// <returns>An IList of IResourceLocation</returns>
|
||||
public static Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> GetResourceLocations(string[] labels)
|
||||
{
|
||||
var il2cppLabels = new Il2CppSystem.Collections.Generic.IList<Il2CppSystem.Object>(labels.WrapToIl2Cpp().Pointer);
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets.Addressable;
|
||||
public class WaitForAsyncOperationHandleFinish : IEnumerator
|
||||
{
|
||||
internal AsyncOperationHandle handle;
|
||||
public WaitForAsyncOperationHandleFinish(AsyncOperationHandle handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An IEnumerator for awaiting an AsyncOperationHandle
|
||||
/// </summary>
|
||||
/// <param name="handle">The AsyncOperationHandle being awaited</param>
|
||||
public class WaitForAsyncOperationHandleFinish(AsyncOperationHandle handle) : IEnumerator
|
||||
{
|
||||
public object Current => null;
|
||||
public bool MoveNext()
|
||||
{
|
||||
|
||||
@@ -3,8 +3,18 @@ using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class for loading assets from the addressables api.
|
||||
/// </summary>
|
||||
/// <param name="name">The name/identifier of the asset</param>
|
||||
/// <typeparam name="T">The type of the asset to be loaded</typeparam>
|
||||
public class LoadableAddressableAsset<T>(string name) : LoadableAsset<T> where T : UnityEngine.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the asset from the addressables api.
|
||||
/// </summary>
|
||||
/// <returns>The asset</returns>
|
||||
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||
public override T LoadAsset()
|
||||
{
|
||||
if (LoadedAsset)
|
||||
|
||||
@@ -4,9 +4,22 @@ using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class for loading multiple assets from the addressables api.
|
||||
/// </summary>
|
||||
/// <param name="locations">A list of IResourceLocations that locate the assets.</param>
|
||||
/// <typeparam name="T">The type of the assets to be loaded</typeparam>
|
||||
public class LoadableAddressableGroupAsset<T>(Il2CppSystem.Collections.Generic.IList<UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation> locations) where T : UnityEngine.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// A reference to the loaded assets. Intended to be used for caching purposes.
|
||||
/// </summary>
|
||||
protected List<T> LoadedAsset = new();
|
||||
/// <summary>
|
||||
/// Loads the assets from the addressables api.
|
||||
/// </summary>
|
||||
/// <returns>The assets</returns>
|
||||
/// <exception cref="Exception">The asset did not load properly.</exception>
|
||||
public List<T> LoadAsset()
|
||||
{
|
||||
if (LoadedAsset.Count != 0)
|
||||
|
||||
Reference in new issue
Block a user