Update components to use EnsureWarn (#2676)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
DrSmugleaf
2020-12-04 13:26:54 +01:00
committed by GitHub
parent 1eaad7e5d7
commit 1b1d050ee7
24 changed files with 32 additions and 104 deletions

View File

@@ -45,16 +45,10 @@ namespace Content.Server.GameObjects.Components.Access
_privilegedIdContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-privilegedId", Owner); _privilegedIdContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-privilegedId", Owner);
_targetIdContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-targetId", Owner); _targetIdContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-targetId", Owner);
if (!Owner.EnsureComponent(out AccessReader _)) Owner.EnsureComponentWarn<AccessReader>();
{ Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(AccessReader)}");
}
if (UserInterface == null) if (UserInterface != null)
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} doesn't have a {nameof(ServerUserInterfaceComponent)}");
}
else
{ {
UserInterface.OnReceiveMessage += OnUiReceiveMessage; UserInterface.OnReceiveMessage += OnUiReceiveMessage;
} }

View File

@@ -1,15 +1,10 @@
#nullable enable #nullable enable
using System;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -85,10 +80,9 @@ namespace Content.Server.GameObjects.Components.Atmos
// Using the SnapGrid is critical for performance, and thus if it is absent the component // Using the SnapGrid is critical for performance, and thus if it is absent the component
// will not be airtight. A warning is much easier to track down than the object magically // will not be airtight. A warning is much easier to track down than the object magically
// not being airtight, so log one if the SnapGrid component is missing. // not being airtight, so log one if the SnapGrid component is missing.
if (!Owner.EnsureComponent(out SnapGridComponent _)) Owner.EnsureComponentWarn(out SnapGridComponent _);
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(SnapGridComponent)}");
if(_fixAirBlockedDirectionInitialize) if (_fixAirBlockedDirectionInitialize)
RotateEvent(new RotateEvent(Owner, Angle.Zero, Owner.Transform.LocalRotation)); RotateEvent(new RotateEvent(Owner, Angle.Zero, Owner.Transform.LocalRotation));
UpdatePosition(); UpdatePosition();

View File

@@ -6,7 +6,6 @@ using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body.Networks; using Content.Shared.GameObjects.Components.Body.Networks;
using Content.Shared.GameObjects.Components.Chemistry; using Content.Shared.GameObjects.Components.Chemistry;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -116,10 +115,7 @@ namespace Content.Server.GameObjects.Components.Body.Behavior
{ {
base.Startup(); base.Startup();
if (!Owner.EnsureComponent(out SolutionContainerComponent solution)) Owner.EnsureComponentWarn(out SolutionContainerComponent solution);
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
solution.MaxVolume = InitialMaxVolume; solution.MaxVolume = InitialMaxVolume;
} }

View File

@@ -6,7 +6,6 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Body namespace Content.Server.GameObjects.Components.Body
@@ -45,11 +44,9 @@ namespace Content.Server.GameObjects.Components.Body
{ {
base.Initialize(); base.Initialize();
if (UserInterface == null) Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} doesn't have a {nameof(ServerUserInterfaceComponent)}"); if (UserInterface != null)
}
else
{ {
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage; UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
} }

View File

@@ -26,7 +26,6 @@ using Robust.Shared.Interfaces.Random;
using Robust.Shared.Interfaces.Timing; using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -124,8 +123,7 @@ namespace Content.Server.GameObjects.Components.Botany
{ {
base.Initialize(); base.Initialize();
if(!Owner.EnsureComponent<SolutionContainerComponent>(out var solution)) Owner.EnsureComponentWarn<SolutionContainerComponent>();
Logger.Warning($"Entity {Owner} with a PlantHolderComponent did not have a SolutionContainerComponent.");
} }
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)

View File

@@ -3,7 +3,6 @@ using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;

View File

@@ -66,15 +66,8 @@ namespace Content.Server.GameObjects.Components.Cargo
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out GalacticMarketComponent _)) Owner.EnsureComponentWarn(out GalacticMarketComponent _);
{ Owner.EnsureComponentWarn(out CargoOrderDatabaseComponent _);
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} had no {nameof(GalacticMarketComponent)}");
}
if (!Owner.EnsureComponent(out CargoOrderDatabaseComponent _))
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} had no {nameof(GalacticMarketComponent)}");
}
if (UserInterface != null) if (UserInterface != null)
{ {

View File

@@ -4,7 +4,6 @@ using Content.Server.GameObjects.Components.Nutrition;
using Content.Server.GameObjects.Components.Utensil; using Content.Server.GameObjects.Components.Utensil;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Mechanism;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility; using Content.Shared.Utility;
@@ -14,7 +13,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -52,10 +50,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out _contents)) Owner.EnsureComponentWarn(out _contents);
{
Logger.Error($"Prototype {Owner.Prototype?.ID} had a {nameof(PillComponent)} without a {nameof(SolutionContainerComponent)}!");
}
} }
bool IUse.UseEntity(UseEntityEventArgs eventArgs) bool IUse.UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -4,7 +4,6 @@ using Content.Shared.Chemistry;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -42,11 +41,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{ {
base.Startup(); base.Startup();
if (!Owner.EnsureComponent(out SolutionContainerComponent solution)) Owner.EnsureComponentWarn(out SolutionContainerComponent solution);
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
solution.Capabilities |= SolutionContainerCaps.FitsInDispenser; solution.Capabilities |= SolutionContainerCaps.FitsInDispenser;
} }

View File

@@ -1,16 +1,13 @@
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Fluids;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Physics; using Content.Shared.Physics;
using Microsoft.DiaSymReader;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -43,11 +40,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out SolutionContainerComponent _)) Owner.EnsureComponentWarn(out SolutionContainerComponent _);
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
} }
public void Start(Vector2 dir, float velocity, EntityCoordinates target, float aliveTime) public void Start(Vector2 dir, float velocity, EntityCoordinates target, float aliveTime)

View File

@@ -49,7 +49,7 @@ namespace Content.Server.GameObjects.Components.Fluids
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponent<SolutionContainerComponent>(); Owner.EnsureComponentWarn<SolutionContainerComponent>();
} }
private bool TryGiveToMop(MopComponent mopComponent) private bool TryGiveToMop(MopComponent mopComponent)

View File

@@ -8,7 +8,6 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Fluids namespace Content.Server.GameObjects.Components.Fluids
@@ -59,10 +58,7 @@ namespace Content.Server.GameObjects.Components.Fluids
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out SolutionContainerComponent _)) Owner.EnsureComponentWarn(out SolutionContainerComponent _);
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
} }
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs) void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)

View File

@@ -17,7 +17,6 @@ using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers; using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -26,7 +25,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using Timer = Robust.Shared.Timers.Timer;
namespace Content.Server.GameObjects.Components.Fluids namespace Content.Server.GameObjects.Components.Fluids
{ {

View File

@@ -75,11 +75,7 @@ namespace Content.Server.GameObjects.Components.Fluids
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out SolutionContainerComponent _)) Owner.EnsureComponentWarn(out SolutionContainerComponent _);
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
if (_hasSafety) if (_hasSafety)
{ {

View File

@@ -39,14 +39,15 @@ namespace Content.Server.GameObjects.Components.GUI
UserInterface.OnReceiveMessage += HandleUserInterfaceMessage; UserInterface.OnReceiveMessage += HandleUserInterfaceMessage;
} }
Owner.EnsureComponent<InventoryComponent>(); Owner.EnsureComponentWarn<InventoryComponent>();
Owner.EnsureComponent<HandsComponent>(); Owner.EnsureComponentWarn<HandsComponent>();
Owner.EnsureComponent<CuffableComponent>(); Owner.EnsureComponentWarn<CuffableComponent>();
if (Owner.TryGetComponent(out CuffableComponent? cuffed)) if (Owner.TryGetComponent(out CuffableComponent? cuffed))
{ {
cuffed.OnCuffedStateChanged += UpdateSubscribed; cuffed.OnCuffedStateChanged += UpdateSubscribed;
} }
if (Owner.TryGetComponent(out InventoryComponent? inventory)) if (Owner.TryGetComponent(out InventoryComponent? inventory))
{ {
inventory.OnItemChanged += UpdateSubscribed; inventory.OnItemChanged += UpdateSubscribed;

View File

@@ -46,10 +46,7 @@ namespace Content.Server.GameObjects.Components.Movement
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out PhysicsComponent _)) Owner.EnsureComponentWarn(out PhysicsComponent _);
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(PhysicsComponent)}");
}
_doAfterSystem = EntitySystem.Get<DoAfterSystem>(); _doAfterSystem = EntitySystem.Get<DoAfterSystem>();
} }

View File

@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponent<SolutionContainerComponent>(); Owner.EnsureComponentWarn<SolutionContainerComponent>();
} }
bool IUse.UseEntity(UseEntityEventArgs eventArgs) bool IUse.UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -56,6 +56,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
Owner.EnsureComponent<BatteryComponent>(); Owner.EnsureComponent<BatteryComponent>();
Owner.EnsureComponent<PowerConsumerComponent>(); Owner.EnsureComponent<PowerConsumerComponent>();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
if (UserInterface != null) if (UserInterface != null)
{ {

View File

@@ -3,9 +3,7 @@ using System.Collections.Generic;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -142,10 +140,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out PowerReceiverComponent receiver)) Owner.EnsureComponentWarn(out PowerReceiverComponent receiver);
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(PowerReceiverComponent)}");
}
receiver.OnPowerStateChanged += UpdateState; receiver.OnPowerStateChanged += UpdateState;
State = EmergencyLightState.Charging; State = EmergencyLightState.Charging;

View File

@@ -36,7 +36,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
base.Initialize(); base.Initialize();
Owner.EnsureComponent<BatteryComponent>(); Owner.EnsureComponent<BatteryComponent>();
Owner.EnsureComponent<AppearanceComponent>(); Owner.EnsureComponentWarn<AppearanceComponent>();
} }
public void OnUpdate() public void OnUpdate()

View File

@@ -4,7 +4,6 @@ using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Timing; using Robust.Shared.Interfaces.Timing;
using Robust.Shared.Log;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -73,10 +72,7 @@ namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out PowerSupplierComponent _)) Owner.EnsureComponentWarn(out PowerSupplierComponent _);
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(PowerSupplierComponent)}");
}
UpdateSupply(); UpdateSupply();
} }

View File

@@ -32,11 +32,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
{ {
base.Initialize(); base.Initialize();
if (!Owner.EnsureComponent(out ProjectileComponent _)) Owner.EnsureComponentWarn(out ProjectileComponent _);
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(ProjectileComponent)}");
}
} }
void ICollideBehavior.CollideWith(IEntity entity) void ICollideBehavior.CollideWith(IEntity entity)

View File

@@ -37,6 +37,8 @@ namespace Content.Server.GameObjects.Components.Research
{ {
base.Initialize(); base.Initialize();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
if (UserInterface != null) if (UserInterface != null)
{ {
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage; UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;

View File

@@ -157,11 +157,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{ {
base.OnAdd(); base.OnAdd();
if (!Owner.EnsureComponent(out ServerRangedWeaponComponent rangedWeaponComponent)) Owner.EnsureComponentWarn(out ServerRangedWeaponComponent rangedWeaponComponent);
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(ServerRangedWeaponComponent)}");
}
rangedWeaponComponent.Barrel ??= this; rangedWeaponComponent.Barrel ??= this;
rangedWeaponComponent.FireHandler += Fire; rangedWeaponComponent.FireHandler += Fire;