Make EyeComponent.Eye not nullable (#4564)

This commit is contained in:
Leon Friedrich
2023-11-13 04:20:09 +11:00
committed by GitHub
parent 68753d15e0
commit 216292c849
3 changed files with 24 additions and 43 deletions

View File

@@ -1,8 +1,6 @@
using Robust.Client.Graphics;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Player;
@@ -27,17 +25,13 @@ public sealed class EyeSystem : SharedEyeSystem
private void OnEyeAutoState(EntityUid uid, EyeComponent component, ref AfterAutoHandleStateEvent args)
{
UpdateEye(component);
UpdateEye((uid, component));
}
private void OnEyeAttached(EntityUid uid, EyeComponent component, LocalPlayerAttachedEvent args)
{
// TODO: This probably shouldn't be nullable bruv.
if (component._eye != null)
{
_eyeManager.CurrentEye = component._eye;
}
UpdateEye((uid, component));
_eyeManager.CurrentEye = component.Eye;
var ev = new EyeAttachedEvent(uid, component);
RaiseLocalEvent(uid, ref ev, true);
}
@@ -49,13 +43,7 @@ public sealed class EyeSystem : SharedEyeSystem
private void OnInit(EntityUid uid, EyeComponent component, ComponentInit args)
{
component._eye = new Eye
{
Position = Transform(uid).MapPosition,
Zoom = component.Zoom,
DrawFov = component.DrawFov,
Rotation = component.Rotation,
};
UpdateEye((uid, component));
}
/// <inheritdoc />
@@ -65,7 +53,7 @@ public sealed class EyeSystem : SharedEyeSystem
while (query.MoveNext(out var uid, out var eyeComponent))
{
if (eyeComponent._eye == null)
if (eyeComponent.Eye == null)
continue;
if (!TryComp<TransformComponent>(eyeComponent.Target, out var xform))
@@ -74,7 +62,7 @@ public sealed class EyeSystem : SharedEyeSystem
eyeComponent.Target = null;
}
eyeComponent._eye.Position = xform.MapPosition;
eyeComponent.Eye.Position = xform.MapPosition;
}
}
}

View File

@@ -12,16 +12,10 @@ namespace Robust.Shared.GameObjects
[RegisterComponent, NetworkedComponent, Access(typeof(SharedEyeSystem)), AutoGenerateComponentState(true)]
public sealed partial class EyeComponent : Component
{
#region Client
[ViewVariables] internal Eye? _eye = default!;
public IEye? Eye => _eye;
public const int DefaultVisibilityMask = 1;
[ViewVariables]
public MapCoordinates? Position => _eye?.Position;
#endregion
public readonly Eye Eye = new();
/// <summary>
/// If not null, this entity is used to update the eye's position instead of just using the component's owner.
@@ -47,8 +41,6 @@ namespace Robust.Shared.GameObjects
[ViewVariables(VVAccess.ReadWrite), DataField("offset"), AutoNetworkedField]
public Vector2 Offset;
public const int DefaultVisibilityMask = 1;
/// <summary>
/// The visibility mask for this eye.
/// The player will be able to get updates for entities whose layers match the mask.
@@ -58,7 +50,7 @@ namespace Robust.Shared.GameObjects
}
/// <summary>
/// Single layer used for Eye visiblity. Controls what entities they are allowed to see.
/// Single layer used for Eye visibility. Controls what entities they are allowed to see.
/// </summary>
public sealed class VisibilityMaskLayer {}
}

View File

@@ -11,15 +11,16 @@ public abstract class SharedEyeSystem : EntitySystem
/// <summary>
/// Refreshes all values for IEye with the component.
/// </summary>
public void UpdateEye(EyeComponent component)
public void UpdateEye(Entity<EyeComponent?> entity)
{
if (component._eye == null)
var component = entity.Comp;
if (!Resolve(entity, ref component))
return;
component._eye.Offset = component.Offset;
component._eye.DrawFov = component.DrawFov;
component._eye.Rotation = component.Rotation;
component._eye.Zoom = component.Zoom;
component.Eye.Offset = component.Offset;
component.Eye.DrawFov = component.DrawFov;
component.Eye.Rotation = component.Rotation;
component.Eye.Zoom = component.Zoom;
}
public void SetOffset(EntityUid uid, Vector2 value, EyeComponent? eyeComponent = null)
@@ -31,9 +32,9 @@ public abstract class SharedEyeSystem : EntitySystem
return;
eyeComponent.Offset = value;
if (eyeComponent._eye != null)
if (eyeComponent.Eye != null)
{
eyeComponent._eye.Offset = value;
eyeComponent.Eye.Offset = value;
}
Dirty(uid, eyeComponent);
}
@@ -47,9 +48,9 @@ public abstract class SharedEyeSystem : EntitySystem
return;
eyeComponent.DrawFov = value;
if (eyeComponent._eye != null)
if (eyeComponent.Eye != null)
{
eyeComponent._eye.DrawFov = value;
eyeComponent.Eye.DrawFov = value;
}
Dirty(uid, eyeComponent);
}
@@ -63,9 +64,9 @@ public abstract class SharedEyeSystem : EntitySystem
return;
eyeComponent.Rotation = rotation;
if (eyeComponent._eye != null)
if (eyeComponent.Eye != null)
{
eyeComponent._eye.Rotation = rotation;
eyeComponent.Eye.Rotation = rotation;
}
}
@@ -90,9 +91,9 @@ public abstract class SharedEyeSystem : EntitySystem
return;
eyeComponent.Zoom = value;
if (eyeComponent._eye != null)
if (eyeComponent.Eye != null)
{
eyeComponent._eye.Zoom = value;
eyeComponent.Eye.Zoom = value;
}
}