More power nullability (#3070)

This commit is contained in:
collinlunn
2021-02-02 05:20:24 -06:00
committed by GitHub
parent d0d2434fba
commit a5492bc943
20 changed files with 73 additions and 56 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.EntitySystems;
@@ -63,7 +64,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// </summary>
public void UpdateState()
{
if (!Owner.TryGetComponent(out PowerReceiverComponent receiver))
if (!Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
return;
}
@@ -83,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public void OnUpdate(float frameTime)
{
if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent battery))
if (Owner.Deleted || !Owner.TryGetComponent(out BatteryComponent? battery))
{
return;
}
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
battery.CurrentCharge += _chargingWattage * frameTime * _chargingEfficiency;
if (battery.BatteryState == BatteryState.Full)
{
if (Owner.TryGetComponent(out PowerReceiverComponent receiver))
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
receiver.Load = 1;
}
@@ -113,12 +114,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private void TurnOff()
{
if (Owner.TryGetComponent(out SpriteComponent sprite))
if (Owner.TryGetComponent(out SpriteComponent? sprite))
{
sprite.LayerSetState(0, "emergency_light_off");
}
if (Owner.TryGetComponent(out PointLightComponent light))
if (Owner.TryGetComponent(out PointLightComponent? light))
{
light.Enabled = false;
}
@@ -126,18 +127,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private void TurnOn()
{
if (Owner.TryGetComponent(out SpriteComponent sprite))
if (Owner.TryGetComponent(out SpriteComponent? sprite))
{
sprite.LayerSetState(0, "emergency_light_on");
}
if (Owner.TryGetComponent(out PointLightComponent light))
if (Owner.TryGetComponent(out PointLightComponent? light))
{
light.Enabled = true;
}
}
public override void HandleMessage(ComponentMessage message, IComponent component)
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using Content.Shared.Audio;
using Content.Shared.GameObjects.EntitySystems;
@@ -41,8 +42,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// <summary>
/// Invoked whenever the state of the light bulb changes.
/// </summary>
public event EventHandler<EventArgs> OnLightBulbStateChange;
public event EventHandler<EventArgs> OnLightColorChange;
public event EventHandler<EventArgs>? OnLightBulbStateChange;
public event EventHandler<EventArgs?>? OnLightColorChange;
private Color _color = Color.White;
@@ -106,7 +107,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public void UpdateColor()
{
if (!Owner.TryGetComponent(out SpriteComponent sprite))
if (!Owner.TryGetComponent(out SpriteComponent? sprite))
{
return;
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Interfaces.GameObjects.Components;
#nullable enable
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;

View File

@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.GUI;
@@ -41,16 +42,16 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
[ViewVariables] private bool _on;
private LightBulbType BulbType = LightBulbType.Tube;
[ViewVariables] private ContainerSlot _lightBulbContainer;
[ViewVariables] private ContainerSlot _lightBulbContainer = default!;
[ViewVariables]
private LightBulbComponent LightBulb
private LightBulbComponent? LightBulb
{
get
{
if (_lightBulbContainer.ContainedEntity == null) return null;
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent bulb);
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent? bulb);
return bulb;
}
@@ -65,12 +66,12 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
public bool InteractHand(InteractHandEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent(out IDamageableComponent damageableComponent))
if (!eventArgs.User.TryGetComponent(out IDamageableComponent? damageableComponent))
{
Eject();
return false;
}
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent heatResistanceComponent))
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent? heatResistanceComponent))
{
if(CanBurn(heatResistanceComponent.GetHeatResistance()))
{
@@ -83,6 +84,9 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
bool CanBurn(int heatResistance)
{
if (LightBulb == null)
return false;
return _lightState && heatResistance < LightBulb.BurningTemperature;
}
@@ -108,7 +112,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private bool InsertBulb(IEntity bulb)
{
if (LightBulb != null) return false;
if (!bulb.TryGetComponent(out LightBulbComponent lightBulb)) return false;
if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb)) return false;
if (lightBulb.Type != BulbType) return false;
var inserted = _lightBulbContainer.Insert(bulb);
@@ -135,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
if (!_lightBulbContainer.Remove(bulb.Owner)) return;
if (!user.TryGetComponent(out HandsComponent hands)
if (!user.TryGetComponent(out HandsComponent? hands)
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
}
@@ -149,7 +153,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
/// <summary>
/// For attaching UpdateLight() to events.
/// </summary>
public void UpdateLight(object sender, EventArgs e)
public void UpdateLight(object? sender, EventArgs? e)
{
UpdateLight();
}
@@ -212,7 +216,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner);
}
public override void HandleMessage(ComponentMessage message, IComponent component)
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
#nullable enable
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;