Add a test that puts all components on an entity and checks for no exceptions (#1815)
* Add test that puts all components on an entity and checks for no exceptions Also fix all the exceptions that happened because of this * Add comments to the test * Fix nullable errors * Fix more nullable errors * More nullable error fixes * Unignore basic actor component * Fix more nullable errors * NULLABLE ERROR * Add string interpolation * Merge if checks * Remove redundant pragma warning disable 649 * Address reviews * Remove null wrappers around TryGetComponent * Merge conflict fixes * APC battery component error fix * Fix power test * Fix atmos mapgrid usages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Interfaces;
|
||||
@@ -34,12 +35,8 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
IUse,
|
||||
IThrown
|
||||
{
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager;
|
||||
|
||||
[Dependency] private readonly IGameTiming _gameTiming;
|
||||
#pragma warning restore 649
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private static readonly TimeSpan OneSecAgo = TimeSpan.FromSeconds(-1);
|
||||
|
||||
@@ -47,7 +44,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
/// The client channel currently playing the instrument, or null if there's none.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private IPlayerSession _instrumentPlayer;
|
||||
private IPlayerSession? _instrumentPlayer;
|
||||
|
||||
private bool _handheld;
|
||||
|
||||
@@ -72,9 +69,6 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
[ViewVariables]
|
||||
private int _midiEventCount = 0;
|
||||
|
||||
[ViewVariables]
|
||||
private BoundUserInterface _userInterface;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the instrument is an item which can be held or not.
|
||||
/// </summary>
|
||||
@@ -95,7 +89,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
}
|
||||
}
|
||||
|
||||
public IPlayerSession InstrumentPlayer
|
||||
public IPlayerSession? InstrumentPlayer
|
||||
{
|
||||
get => _instrumentPlayer;
|
||||
private set
|
||||
@@ -108,11 +102,18 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
_instrumentPlayer = value;
|
||||
|
||||
if (value != null)
|
||||
_instrumentPlayer.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
_instrumentPlayer!.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerStatusChanged(object sender, SessionStatusEventArgs e)
|
||||
[ViewVariables]
|
||||
private BoundUserInterface? UserInterface =>
|
||||
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
|
||||
ui.TryGetBoundUserInterface(InstrumentUiKey.Key, out var boundUi)
|
||||
? boundUi
|
||||
: null;
|
||||
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.Session != _instrumentPlayer || e.NewStatus != SessionStatus.Disconnected) return;
|
||||
InstrumentPlayer = null;
|
||||
@@ -122,8 +123,11 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(InstrumentUiKey.Key);
|
||||
_userInterface.OnClosed += UserInterfaceOnClosed;
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnClosed += UserInterfaceOnClosed;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
@@ -137,14 +141,14 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
return new InstrumentState(Playing, _lastSequencerTick);
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case InstrumentMidiEventMessage midiEventMsg:
|
||||
if (!Playing || session != _instrumentPlayer) return;
|
||||
if (!Playing || session != _instrumentPlayer || InstrumentPlayer == null) return;
|
||||
|
||||
var send = true;
|
||||
|
||||
@@ -231,7 +235,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
Clean();
|
||||
SendNetworkMessage(new InstrumentStopMidiMessage());
|
||||
InstrumentPlayer = null;
|
||||
_userInterface.CloseAll();
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
public void Thrown(ThrownEventArgs eventArgs)
|
||||
@@ -239,7 +243,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
Clean();
|
||||
SendNetworkMessage(new InstrumentStopMidiMessage());
|
||||
InstrumentPlayer = null;
|
||||
_userInterface.CloseAll();
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
public void HandSelected(HandSelectedEventArgs eventArgs)
|
||||
@@ -255,12 +259,12 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
{
|
||||
Clean();
|
||||
SendNetworkMessage(new InstrumentStopMidiMessage());
|
||||
_userInterface.CloseAll();
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
public void Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (Handheld || !eventArgs.User.TryGetComponent(out IActorComponent actor)) return;
|
||||
if (Handheld || !eventArgs.User.TryGetComponent(out IActorComponent? actor)) return;
|
||||
|
||||
if (InstrumentPlayer != null) return;
|
||||
|
||||
@@ -270,7 +274,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
|
||||
public bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) return false;
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor)) return false;
|
||||
|
||||
if (InstrumentPlayer == actor.playerSession)
|
||||
{
|
||||
@@ -291,7 +295,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
|
||||
private void OpenUserInterface(IPlayerSession session)
|
||||
{
|
||||
_userInterface.Open(session);
|
||||
UserInterface?.Open(session);
|
||||
}
|
||||
|
||||
public override void Update(float delta)
|
||||
@@ -302,7 +306,7 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
{
|
||||
InstrumentPlayer = null;
|
||||
Clean();
|
||||
_userInterface.CloseAll();
|
||||
UserInterface?.CloseAll();
|
||||
}
|
||||
|
||||
if ((_batchesDropped >= MaxMidiBatchDropped
|
||||
@@ -314,9 +318,9 @@ namespace Content.Server.GameObjects.Components.Instruments
|
||||
SendNetworkMessage(new InstrumentStopMidiMessage());
|
||||
Playing = false;
|
||||
|
||||
_userInterface.CloseAll();
|
||||
UserInterface?.CloseAll();
|
||||
|
||||
if (mob.TryGetComponent(out StunnableComponent stun))
|
||||
if (mob != null && mob.TryGetComponent(out StunnableComponent? stun))
|
||||
{
|
||||
stun.Stun(1);
|
||||
Clean();
|
||||
|
||||
Reference in New Issue
Block a user