Skip to content

Commit 8edacfe

Browse files
authored
Merge pull request #718 from qsb-dev/dev
1.5.0 - Fix some quantum objects in NH mods. They should move around now, at least. - Fix most items in NH mods. Custom item logic will not work, but you can do normal item things (pick up, drop, insert into slot). - Fix chat/HUD working in custom systems. It still does not work in the eye yet.
2 parents b8a2ab6 + 59f9b37 commit 8edacfe

File tree

14 files changed

+132
-37
lines changed

14 files changed

+132
-37
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.cs]
2+
indent_style = tab

QSB-NH/QSBNH.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using OWML.Common;
77
using QSB;
88
using QSB.HUD;
9+
using QSB.HUD.Messages;
910
using QSB.Messaging;
1011
using QSB.Utility;
1112
using UnityEngine;
@@ -33,6 +34,8 @@ private void OnWakeUp()
3334
// Allow time for MultiplayerHUDManager.OnWakeUp to run
3435
Delay.RunNextFrame(() =>
3536
{
37+
var triggers = new List<PlanetTrigger>();
38+
3639
var currentPlanets = NewHorizons.Main.BodyDict[NewHorizons.Main.Instance.CurrentStarSystem];
3740
foreach (var planet in currentPlanets)
3841
{
@@ -62,8 +65,20 @@ private void OnWakeUp()
6265

6366
if (!nhAstro.isVanilla)
6467
{
65-
MultiplayerHUDManager.CreateTrigger(nhAstro.GetRootSector().gameObject, astroObjName);
68+
triggers.Add(MultiplayerHUDManager.CreateTrigger(nhAstro.GetRootSector().gameObject, astroObjName));
69+
}
70+
}
71+
72+
foreach (var trigger in triggers)
73+
{
74+
if (!trigger._sector.ContainsOccupant(DynamicOccupant.Player))
75+
{
76+
continue;
6677
}
78+
79+
MultiplayerHUDManager.HUDIconStack.Push(trigger.PlanetID);
80+
new PlanetMessage(trigger.PlanetID).Send();
81+
break;
6782
}
6883
});
6984
}

QSB/HUD/MultiplayerHUDManager.cs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,24 +375,46 @@ Sprite GetSprite(AstroObject.Name name)
375375

376376
CreatePlanetToSprite();
377377

378-
CreateTrigger("TowerTwin_Body/Sector_TowerTwin", AstroObject.Name.TowerTwin);
379-
CreateTrigger("CaveTwin_Body/Sector_CaveTwin", AstroObject.Name.CaveTwin);
380-
CreateTrigger("TimberHearth_Body/Sector_TH", AstroObject.Name.TimberHearth);
381-
CreateTrigger("Moon_Body/Sector_THM", AstroObject.Name.TimberMoon);
382-
CreateTrigger("BrittleHollow_Body/Sector_BH", AstroObject.Name.BrittleHollow);
383-
CreateTrigger("VolcanicMoon_Body/Sector_VM", AstroObject.Name.VolcanicMoon);
384-
CreateTrigger("GiantsDeep_Body/Sector_GD", AstroObject.Name.GiantsDeep);
385-
CreateTrigger("DarkBramble_Body/Sector_DB", AstroObject.Name.DarkBramble);
386-
CreateTrigger("Comet_Body/Sector_CO", AstroObject.Name.Comet);
387-
CreateTrigger("WhiteHole_Body/Sector_WhiteHole", AstroObject.Name.WhiteHole);
388-
CreateTrigger("RingWorld_Body/Sector_RingWorld", AstroObject.Name.RingWorld); // TODO : this doesnt work????
389-
CreateTrigger("QuantumMoon_Body/Sector_QuantumMoon", AstroObject.Name.QuantumMoon);
378+
var planetTriggers = new List<PlanetTrigger>
379+
{
380+
CreateTrigger("TowerTwin_Body/Sector_TowerTwin", AstroObject.Name.TowerTwin),
381+
CreateTrigger("CaveTwin_Body/Sector_CaveTwin", AstroObject.Name.CaveTwin),
382+
CreateTrigger("TimberHearth_Body/Sector_TH", AstroObject.Name.TimberHearth),
383+
CreateTrigger("Moon_Body/Sector_THM", AstroObject.Name.TimberMoon),
384+
CreateTrigger("BrittleHollow_Body/Sector_BH", AstroObject.Name.BrittleHollow),
385+
CreateTrigger("VolcanicMoon_Body/Sector_VM", AstroObject.Name.VolcanicMoon),
386+
CreateTrigger("GiantsDeep_Body/Sector_GD", AstroObject.Name.GiantsDeep),
387+
CreateTrigger("DarkBramble_Body/Sector_DB", AstroObject.Name.DarkBramble),
388+
CreateTrigger("Comet_Body/Sector_CO", AstroObject.Name.Comet),
389+
CreateTrigger("WhiteHole_Body/Sector_WhiteHole", AstroObject.Name.WhiteHole),
390+
CreateTrigger("RingWorld_Body/Sector_RingWorld", AstroObject.Name.RingWorld),
391+
CreateTrigger("QuantumMoon_Body/Sector_QuantumMoon", AstroObject.Name.QuantumMoon)
392+
};
390393

391394
HUDIconStack.Clear();
392395
HUDIconStack.Push("__SPACE__");
393396

394-
HUDIconStack.Push("TimberHearth");
395-
new PlanetMessage("TimberHearth").Send();
397+
foreach (var trigger in planetTriggers)
398+
{
399+
if (trigger == null)
400+
{
401+
continue;
402+
}
403+
404+
if (trigger._sector == null)
405+
{
406+
continue;
407+
}
408+
409+
if (!trigger._sector.ContainsOccupant(DynamicOccupant.Player))
410+
{
411+
continue;
412+
}
413+
414+
HUDIconStack.Push(trigger.PlanetID);
415+
new PlanetMessage(trigger.PlanetID).Send();
416+
break;
417+
}
396418

397419
_textChat = multiplayerGroup.transform.Find("TextChat");
398420
var inputFieldGO = _textChat.Find("InputField");
@@ -561,6 +583,7 @@ public static PlanetTrigger CreateTrigger(GameObject parent, string name)
561583
triggerGO.transform.SetParent(parent.transform, false);
562584
triggerGO.SetActive(false);
563585
var trigger = triggerGO.AddComponent<PlanetTrigger>();
586+
trigger.Reset(); // Force _sector to be found immediately
564587
trigger.PlanetID = name;
565588
triggerGO.SetActive(true);
566589
return trigger;

QSB/ItemSync/ItemManager.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using Cysharp.Threading.Tasks;
2+
using HarmonyLib;
23
using OWML.Common;
34
using QSB.ItemSync.WorldObjects;
45
using QSB.ItemSync.WorldObjects.Items;
56
using QSB.ItemSync.WorldObjects.Sockets;
67
using QSB.Utility;
78
using QSB.Utility.Deterministic;
89
using QSB.WorldSync;
10+
using System;
11+
using System.Collections.Generic;
912
using System.Linq;
1013
using System.Threading;
1114
using UnityEngine;
@@ -21,21 +24,66 @@ public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken
2124
DebugLog.DebugWrite("Building OWItems...", MessageType.Info);
2225

2326
// Items
24-
QSBWorldSync.Init<QSBNomaiConversationStone, NomaiConversationStone>();
25-
QSBWorldSync.Init<QSBScrollItem, ScrollItem>();
26-
QSBWorldSync.Init<QSBSharedStone, SharedStone>();
27-
QSBWorldSync.Init<QSBSimpleLanternItem, SimpleLanternItem>();
2827
QSBWorldSync.Init<QSBSlideReelItem, SlideReelItem>();
2928
QSBWorldSync.Init<QSBWarpCoreItem, WarpCoreItem>();
3029
// dream lantern and vision torch are set up in their own managers
30+
// the rest can just use the generic thing below because they dont have special things using them
31+
32+
// Use the basic QSBItem class for any items that do not require custom code through a derived class (mod compatibility)
33+
// QSB addons can still define their own QSBItem derived classes and they will just get skipped here
34+
var handledItemTypes = new HashSet<Type>(GetHandledItemTypes()); // set cuz we do Contains below
35+
DebugLog.DebugWrite($"Handled OWItem types (the rest will get generic QSBItem support) are: {handledItemTypes.Join()}");
36+
var otherItemlistToInitFrom = QSBWorldSync.GetUnityObjects<OWItem>()
37+
.Where(x => !handledItemTypes.Contains(x.GetType()))
38+
.SortDeterministic();
39+
// could make a subclass for this but i dont care, and would have to filter out from reflection thing below
40+
QSBWorldSync.Init<QSBItem<OWItem>, OWItem>(otherItemlistToInitFrom);
3141

3242
// Sockets
3343
QSBWorldSync.Init<QSBItemSocket, OWItemSocket>();
3444

3545
// other drop targets that don't already have world objects
46+
// breaks if mod adds custom subclass of IItemDropTarget and then makes WorldObject of that but can just fix that when that happens
3647
var listToInitFrom = QSBWorldSync.GetUnityObjects<MonoBehaviour>()
3748
.Where(x => x is IItemDropTarget and not (RaftDock or RaftController or PrisonCellElevator))
3849
.SortDeterministic();
3950
QSBWorldSync.Init<QSBOtherDropTarget, MonoBehaviour>(listToInitFrom);
4051
}
52+
53+
/// <summary>
54+
/// Gets all types that extend QSBItem and returns the list of OWItem types that are already handled by dedicated classes
55+
/// </summary>
56+
private static IEnumerable<Type> GetHandledItemTypes()
57+
{
58+
var assemblies = QSBCore.Addons.Values
59+
.Select(x => x.GetType().Assembly)
60+
.Append(typeof(QSBCore).Assembly);
61+
62+
if (QSBCore.QSBNHAssembly != null)
63+
{
64+
assemblies = assemblies.Append(QSBCore.QSBNHAssembly);
65+
}
66+
67+
// If the class inherits from QSBItem<T>, this will return what T is else null
68+
static Type GetTypeFromQSBItem(Type type)
69+
{
70+
if (type.IsInterface || type.IsAbstract || type.BaseType == null)
71+
{
72+
return null;
73+
}
74+
if (type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(QSBItem<>))
75+
{
76+
return type.BaseType.GetGenericArguments()[0];
77+
}
78+
else
79+
{
80+
return GetTypeFromQSBItem(type.BaseType);
81+
}
82+
}
83+
84+
return assemblies.SelectMany(x => x.GetTypes())
85+
.Select(GetTypeFromQSBItem)
86+
.Where(x => x != null)
87+
.OrderBy(x => x.FullName);
88+
}
4189
}

QSB/ItemSync/WorldObjects/Items/QSBItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace QSB.ItemSync.WorldObjects.Items;
1414

15+
// not abstract so modded items can use this QSBItem<OWItem>
16+
// could use QSBOtherItem subclass but i dont feel like it
1517
public class QSBItem<T> : WorldObject<T>, IQSBItem
1618
where T : OWItem
1719
{

QSB/ItemSync/WorldObjects/Items/QSBNomaiConversationStone.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

QSB/ItemSync/WorldObjects/Items/QSBScrollItem.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

QSB/ItemSync/WorldObjects/Items/QSBSharedStone.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

QSB/ItemSync/WorldObjects/Items/QSBSimpleLanternItem.cs

Lines changed: 0 additions & 3 deletions
This file was deleted.

QSB/ItemSync/WorldObjects/Items/QSBWarpCoreItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
public class QSBWarpCoreItem : QSBItem<WarpCoreItem>
44
{
55
public bool IsVesselCoreType() => AttachedObject.IsVesselCoreType();
6-
}
6+
}

0 commit comments

Comments
 (0)