Inline TryGetComponent completely, for real
This commit is contained in:
@@ -60,7 +60,7 @@ namespace Content.Server.Light.Components
|
||||
/// </summary>
|
||||
public void UpdateState()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver))
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace Content.Server.Light.Components
|
||||
|
||||
public void OnUpdate(float frameTime)
|
||||
{
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) || !Owner.TryGetComponent(out BatteryComponent? battery) || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPaused))
|
||||
if ((!IoCManager.Resolve<IEntityManager>().EntityExists(Owner.Uid) || !IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out BatteryComponent? battery) || IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(Owner.Uid).EntityPaused))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace Content.Server.Light.Components
|
||||
battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency;
|
||||
if (battery.IsFullyCharged)
|
||||
{
|
||||
if (Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ApcPowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.Load = 1;
|
||||
}
|
||||
@@ -110,23 +110,23 @@ namespace Content.Server.Light.Components
|
||||
|
||||
private void TurnOff()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = false;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
|
||||
appearance.SetData(EmergencyLightVisuals.On, false);
|
||||
}
|
||||
|
||||
private void TurnOn()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = true;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out AppearanceComponent? appearance))
|
||||
appearance.SetData(EmergencyLightVisuals.On, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,14 @@ namespace Content.Server.Light.Components
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent<ItemComponent>(out var item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(Owner.Uid, out var item))
|
||||
{
|
||||
item.EquippedPrefix = "unlit";
|
||||
}
|
||||
|
||||
CurrentState = ExpendableLightState.BrandNew;
|
||||
Owner.EnsureComponent<PointLightComponent>();
|
||||
Owner.TryGetComponent(out _appearance);
|
||||
IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out _appearance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,7 +53,7 @@ namespace Content.Server.Light.Components
|
||||
{
|
||||
if (!Activated && CurrentState == ExpendableLightState.BrandNew)
|
||||
{
|
||||
if (Owner.TryGetComponent<ItemComponent>(out var item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(Owner.Uid, out var item))
|
||||
{
|
||||
item.EquippedPrefix = "lit";
|
||||
}
|
||||
@@ -92,7 +92,7 @@ namespace Content.Server.Light.Components
|
||||
|
||||
private void UpdateSpriteAndSounds(bool on)
|
||||
{
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SpriteComponent? sprite))
|
||||
{
|
||||
switch (CurrentState)
|
||||
{
|
||||
@@ -126,7 +126,7 @@ namespace Content.Server.Light.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ClothingComponent? clothing))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ClothingComponent? clothing))
|
||||
{
|
||||
clothing.ClothingEquippedPrefix = on ? "Activated" : string.Empty;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace Content.Server.Light.Components
|
||||
UpdateSpriteAndSounds(Activated);
|
||||
UpdateVisualizer();
|
||||
|
||||
if (Owner.TryGetComponent<ItemComponent>(out var item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ItemComponent?>(Owner.Uid, out var item))
|
||||
{
|
||||
item.EquippedPrefix = "unlit";
|
||||
}
|
||||
|
||||
@@ -167,22 +167,22 @@ namespace Content.Server.Light.Components
|
||||
|
||||
private void SetState(bool on)
|
||||
{
|
||||
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out SpriteComponent? sprite))
|
||||
{
|
||||
sprite.LayerSetVisible(1, on);
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = on;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ClothingComponent? clothing))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ClothingComponent? clothing))
|
||||
{
|
||||
clothing.ClothingEquippedPrefix = Loc.GetString(on ? "on" : "off");
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ItemComponent? item))
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Uid, out ItemComponent? item))
|
||||
{
|
||||
item.EquippedPrefix = Loc.GetString(on ? "on" : "off");
|
||||
}
|
||||
@@ -254,7 +254,7 @@ namespace Content.Server.Light.Components
|
||||
{
|
||||
public bool DoToggleAction(ToggleItemActionEventArgs args)
|
||||
{
|
||||
if (!args.Item.TryGetComponent<HandheldLightComponent>(out var lightComponent)) return false;
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<HandheldLightComponent?>(args.Item.Uid, out var lightComponent)) return false;
|
||||
if (lightComponent.Activated == args.ToggledOn) return false;
|
||||
return lightComponent.ToggleStatus(args.Performer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user