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.Threading.Tasks;
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
@@ -13,24 +14,30 @@ namespace Content.Server.GameObjects.Components.Paper
|
||||
[RegisterComponent]
|
||||
public class PaperComponent : SharedPaperComponent, IExamine, IInteractUsing, IUse
|
||||
{
|
||||
|
||||
private BoundUserInterface _userInterface;
|
||||
private string _content;
|
||||
private string _content = "";
|
||||
private PaperAction _mode;
|
||||
|
||||
private BoundUserInterface? UserInterface =>
|
||||
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
|
||||
ui.TryGetBoundUserInterface(PaperUiKey.Key, out var boundUi)
|
||||
? boundUi
|
||||
: null;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
|
||||
.GetBoundUserInterface(PaperUiKey.Key);
|
||||
_userInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
_content = "";
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
_mode = PaperAction.Read;
|
||||
UpdateUserInterface();
|
||||
}
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
_userInterface.SetState(new PaperBoundUserInterfaceState(_content, _mode));
|
||||
UserInterface?.SetState(new PaperBoundUserInterfaceState(_content, _mode));
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
@@ -43,11 +50,12 @@ namespace Content.Server.GameObjects.Components.Paper
|
||||
|
||||
public bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor))
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||
return false;
|
||||
|
||||
_mode = PaperAction.Read;
|
||||
UpdateUserInterface();
|
||||
_userInterface.Open(actor.playerSession);
|
||||
UserInterface?.Open(actor.playerSession);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,7 +67,7 @@ namespace Content.Server.GameObjects.Components.Paper
|
||||
|
||||
_content += msg.Text + '\n';
|
||||
|
||||
if (Owner.TryGetComponent(out SpriteComponent sprite))
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.LayerSetState(1, "paper_words");
|
||||
}
|
||||
@@ -71,12 +79,12 @@ namespace Content.Server.GameObjects.Components.Paper
|
||||
{
|
||||
if (!eventArgs.Using.HasComponent<WriteComponent>())
|
||||
return false;
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor))
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||
return false;
|
||||
|
||||
_mode = PaperAction.Write;
|
||||
UpdateUserInterface();
|
||||
_userInterface.Open(actor.playerSession);
|
||||
UserInterface?.Open(actor.playerSession);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user