mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-14 22:20:51 +00:00
Add QSBItem support for OWItems that lack dedicated derived classes
This commit is contained in:
parent
600b00bb7f
commit
4e8f9be510
@ -6,6 +6,8 @@ using QSB.ItemSync.WorldObjects.Sockets;
|
||||
using QSB.Utility;
|
||||
using QSB.Utility.Deterministic;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
@ -22,15 +24,24 @@ public class ItemManager : WorldObjectManager
|
||||
|
||||
// Items
|
||||
QSBWorldSync.Init<QSBNomaiConversationStone, NomaiConversationStone>();
|
||||
QSBWorldSync.Init<QSBScrollItem, ScrollItem>();
|
||||
// QSBWorldSync.Init<QSBScrollItem, ScrollItem>();
|
||||
QSBWorldSync.Init<QSBSharedStone, SharedStone>();
|
||||
QSBWorldSync.Init<QSBSimpleLanternItem, SimpleLanternItem>();
|
||||
QSBWorldSync.Init<QSBSlideReelItem, SlideReelItem>();
|
||||
QSBWorldSync.Init<QSBWarpCoreItem, WarpCoreItem>();
|
||||
// dream lantern and vision torch are set up in their own managers
|
||||
// dream lantern and vision torch are set up in their own managers
|
||||
|
||||
// Sockets
|
||||
QSBWorldSync.Init<QSBItemSocket, OWItemSocket>();
|
||||
// Use the basic QSBItem class for any items that do not require custom code through a derived class (mod compatibility)
|
||||
// QSB addons can still define their own QSBItem derived classes and they will just get skipped here
|
||||
var handledItemTypes = GetHandledItemTypes();
|
||||
DebugLog.DebugWrite($"Handled OWItem types (the rest will get generic QSBItem support) are: {string.Join(", ", handledItemTypes)}");
|
||||
var otherItemlistToInitFrom = QSBWorldSync.GetUnityObjects<OWItem>()
|
||||
.Where(x => !handledItemTypes.Contains(x.GetType()))
|
||||
.SortDeterministic();
|
||||
QSBWorldSync.Init<QSBItem<OWItem>, OWItem>(otherItemlistToInitFrom);
|
||||
|
||||
// Sockets
|
||||
QSBWorldSync.Init<QSBItemSocket, OWItemSocket>();
|
||||
|
||||
// other drop targets that don't already have world objects
|
||||
var listToInitFrom = QSBWorldSync.GetUnityObjects<MonoBehaviour>()
|
||||
@ -38,4 +49,25 @@ public class ItemManager : WorldObjectManager
|
||||
.SortDeterministic();
|
||||
QSBWorldSync.Init<QSBOtherDropTarget, MonoBehaviour>(listToInitFrom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all types that extend QSBItem and returns the list of OWItem types that are already handled by dedicated classes
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<Type> GetHandledItemTypes()
|
||||
{
|
||||
var assemblies = QSBCore.Addons.Values
|
||||
.Select(x => x.GetType().Assembly)
|
||||
.Append(typeof(QSBCore).Assembly);
|
||||
|
||||
if (QSBCore.QSBNHAssembly != null)
|
||||
{
|
||||
assemblies = assemblies.Append(QSBCore.QSBNHAssembly);
|
||||
}
|
||||
|
||||
return assemblies.SelectMany(x => x.GetTypes())
|
||||
.Where(x => !x.IsInterface && !x.IsAbstract && x.BaseType != null && x.BaseType.IsGenericType && x.BaseType.GetGenericTypeDefinition() == typeof(QSBItem<>))
|
||||
.Select(x => x.BaseType.GetGenericArguments()[0])
|
||||
.OrderBy(x => x.FullName);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
namespace QSB.ItemSync.WorldObjects.Items;
|
||||
|
||||
public class QSBScrollItem : QSBItem<ScrollItem> { }
|
||||
/*
|
||||
public class QSBScrollItem : QSBItem<ScrollItem> { }
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user