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);
_targetIdContainer = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-targetId", Owner);
if (!Owner.EnsureComponent(out AccessReader _))
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(AccessReader)}");
}
Owner.EnsureComponentWarn<AccessReader>();
Owner.EnsureComponentWarn<ServerUserInterfaceComponent>();
if (UserInterface == null)
{
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} doesn't have a {nameof(ServerUserInterfaceComponent)}");
}
else
if (UserInterface != null)
{
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
}

View File

@@ -1,15 +1,10 @@
#nullable enable
using System;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Atmos;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
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.Maths;
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
// 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.
if (!Owner.EnsureComponent(out SnapGridComponent _))
Logger.Warning($"Entity {Owner} at {Owner.Transform.MapPosition} didn't have a {nameof(SnapGridComponent)}");
Owner.EnsureComponentWarn(out SnapGridComponent _);
if(_fixAirBlockedDirectionInitialize)
if (_fixAirBlockedDirectionInitialize)
RotateEvent(new RotateEvent(Owner, Angle.Zero, Owner.Transform.LocalRotation));
UpdatePosition();

View File

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

View File

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

View File

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

View File

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

View File

@@ -66,15 +66,8 @@ namespace Content.Server.GameObjects.Components.Cargo
{
base.Initialize();
if (!Owner.EnsureComponent(out GalacticMarketComponent _))
{
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)}");
}
Owner.EnsureComponentWarn(out GalacticMarketComponent _);
Owner.EnsureComponentWarn(out CargoOrderDatabaseComponent _);
if (UserInterface != null)
{

View File

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

View File

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

View File

@@ -1,16 +1,13 @@
using System.Linq;
using Content.Server.GameObjects.Components.Fluids;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Physics;
using Microsoft.DiaSymReader;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
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.Maths;
using Robust.Shared.Prototypes;
@@ -43,11 +40,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{
base.Initialize();
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
}
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()
{
base.Initialize();
Owner.EnsureComponent<SolutionContainerComponent>();
Owner.EnsureComponentWarn<SolutionContainerComponent>();
}
private bool TryGiveToMop(MopComponent mopComponent)

View File

@@ -8,7 +8,6 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Fluids
@@ -59,10 +58,7 @@ namespace Content.Server.GameObjects.Components.Fluids
{
base.Initialize();
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
Owner.EnsureComponentWarn(out SolutionContainerComponent _);
}
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.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -26,7 +25,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Timer = Robust.Shared.Timers.Timer;
namespace Content.Server.GameObjects.Components.Fluids
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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