Files
RobustToolbox/Robust.Shared/GameObjects/Systems/SharedEyeSystem.cs
T
bd489e9218 A compilation of simple one-line fixes (#5661)
* Fix warnings in SharedJointSystem

* Fix reference to EC TransformComponent method
Replaces call to TransformComponent.GetMapUid with SharedTransformSystem.GetMap

* Fix obsolete calls in SharedPhysicsSystem.Contacts.cs
Fixes a couple calls to obsolete varients of SetAwake and an obsolete call to RegenerateContacts by converting them to their Entity<T> varients

* Fix obsolete call in SharedPhysicsSystem.Components.cs
Adds one set of parenthesis to convert a 'uid, comp, comp, comp' call to an 'Entity<T, T, T> call.

* Removes unused local var
Removes an unused list of broadphases that was being allocated in TryCollideRect

* One-line fixes in SharedPhysicsSystem.Islands.cs
Fixes all of the easy warnings regarding physics island processing, the rest require more complicated changes than a simple argument rearrangement

* Fix obsolete method call in SharedMapSystem

* Fix a few obsolete ToMap calls in EntityLookup.Queries

* Fix calls to obsolete EntityCoordinate methods in SharedMapSystem.Grids

* Fix calls to obsolete EntityCoordinate methods in SharedLookupSystem.ComponentQueries

* Fix a few obsolete method calls in entity spawning

* Fix obsolete method calls in MapLoaderSystem

* Fix obsolete method call in GridFixtureSystem

* Fix obsolete IsMapInitialized call in SaveMap command

* Fix obsolete MapPosition reference in Client.EyeSystem

* Fix obsolete EntitySystem.Get<TSystem> references in DebugLightTreeSystem

* Fix obsolete EntitySystem.Get<TSystem> reference in DebugEntityLookup command

* Fix obsolete method calls in SpriteBoundsOverlay
Slightly more complicated than the rest, but it's really just changing an unused dependency over to use SharedTransformSystem

* Remove unused IClyde references from controls
LineEdit and TextEdit never use their IClyde dependencies and it generates a warning so yeet

* Remove use of EntitySystem.Get from lightbb command

* Fix DebugDrawingSystem
Removes a bunch of unused private IEntityManager vars
Also removes an obsolete use of TransformComponent.GetWorldPositionRotation

* Removes duplicate position set when splitting grids
There's nothing saying why this is this way and the blame looks like it was an oversight when replacing a bit where they set position and then rotation
Please, oh Chesterton's Fence, spare me your wrath

* Fix obsolete method use in PlacementMode

* Fix obsolete method use in Placement Modes

* Removes unused local var in gamestate management

* Fix unreachable code warnings in gamestate management
Use #else sections to make sure they don't complain about being on the wrong side of a throw

* Fix obsolete ToMap use in EyeManager

* Make InputManager use a sawmill to log

* Fix obsolete ContainerManagerComponent method calls in ContainerSystem

* Make ClientPrototypeManager use a sawmill for logging

* poke tests

* Use LocalizedEntityCommands for SpriteBoundsOverlay toggle

* Use LocalizedEntityCommands for system toggles

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2025-04-17 11:57:03 +10:00

207 lines
6.2 KiB
C#

using System;
using System.Numerics;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Player;
namespace Robust.Shared.GameObjects;
public abstract class SharedEyeSystem : EntitySystem
{
[Dependency] private readonly SharedViewSubscriberSystem _views = default!;
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EyeComponent, PlayerAttachedEvent>(OnEyePlayerAttached);
SubscribeLocalEvent<EyeComponent, PlayerDetachedEvent>(OnEyePlayerDetached);
}
private void OnEyePlayerAttached(Entity<EyeComponent> ent, ref PlayerAttachedEvent args)
{
var value = ent.Comp.Target;
if (value != null && TryComp(ent.Owner, out ActorComponent? actorComp))
{
_views.AddViewSubscriber(value.Value, actorComp.PlayerSession);
}
}
private void OnEyePlayerDetached(Entity<EyeComponent> ent, ref PlayerDetachedEvent args)
{
var value = ent.Comp.Target;
if (value != null && TryComp(ent.Owner, out ActorComponent? actorComp))
{
_views.RemoveViewSubscriber(value.Value, actorComp.PlayerSession);
}
}
/// <summary>
/// Refreshes all values for IEye with the component.
/// </summary>
public void UpdateEye(Entity<EyeComponent?> entity)
{
var component = entity.Comp;
if (!Resolve(entity, ref component))
return;
component.Eye.Offset = component.Offset;
component.Eye.DrawFov = component.DrawFov;
component.Eye.DrawLight = component.DrawLight;
component.Eye.Rotation = component.Rotation;
component.Eye.Zoom = component.Zoom;
}
public void SetOffset(EntityUid uid, Vector2 value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.Offset.Equals(value))
return;
eyeComponent.Offset = value;
eyeComponent.Eye.Offset = value;
DirtyField(uid, eyeComponent, nameof(EyeComponent.Offset));
}
public void SetDrawFov(EntityUid uid, bool value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.DrawFov.Equals(value))
return;
eyeComponent.DrawFov = value;
eyeComponent.Eye.DrawFov = value;
DirtyField(uid, eyeComponent, nameof(EyeComponent.DrawFov));
}
public void SetDrawLight(Entity<EyeComponent?> entity, bool value)
{
if (!Resolve(entity, ref entity.Comp))
return;
if (entity.Comp.DrawLight == value)
return;
entity.Comp.DrawLight = value;
entity.Comp.Eye.DrawLight = value;
DirtyField(entity, nameof(EyeComponent.DrawLight));
}
public void SetRotation(EntityUid uid, Angle rotation, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.Rotation.Equals(rotation))
return;
eyeComponent.Rotation = rotation;
eyeComponent.Eye.Rotation = rotation;
}
/// <summary>
/// Sets the eye component as tracking another entity.
/// Will also add the target to view subscribers so they can leave range and still work with PVS.
/// </summary>
public void SetTarget(EntityUid uid, EntityUid? value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.Target.Equals(value))
return;
// Automatically handle view subs.
if (TryComp(uid, out ActorComponent? actorComp))
{
if (value != null)
_views.AddViewSubscriber(value.Value, actorComp.PlayerSession);
if (eyeComponent.Target is { } old)
_views.RemoveViewSubscriber(old, actorComp.PlayerSession);
}
eyeComponent.Target = value;
DirtyField(uid, eyeComponent, nameof(EyeComponent.Target));
}
public void SetZoom(EntityUid uid, Vector2 value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.Zoom.Equals(value))
return;
eyeComponent.Zoom = value;
eyeComponent.Eye.Zoom = value;
}
public void SetPvsScale(Entity<EyeComponent?> eye, float scale)
{
if (!Resolve(eye.Owner, ref eye.Comp, false))
return;
// Prevent a admin or some other fuck-up from causing exception spam in PVS system due to divide-by-zero or
// other such issues
if (!float.IsFinite(scale))
{
Log.Error($"Attempted to set pvs scale to invalid value: {scale}. Eye: {ToPrettyString(eye)}");
SetPvsScale(eye, 1);
return;
}
eye.Comp.PvsScale = Math.Clamp(scale, 0.1f, 100f);
}
/// <summary>
/// Overwrites visibility mask of an entity's eye.
/// If you wish for other systems to potentially change it consider raising <see cref="RefreshVisibilityMask"/>.
/// </summary>
public void SetVisibilityMask(EntityUid uid, int value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
return;
if (eyeComponent.VisibilityMask.Equals(value))
return;
eyeComponent.VisibilityMask = value;
DirtyField(uid, eyeComponent, nameof(EyeComponent.VisibilityMask));
}
/// <summary>
/// Updates the visibility mask for an entity by raising a <see cref="GetVisMaskEvent"/>
/// </summary>
public void RefreshVisibilityMask(Entity<EyeComponent?> entity)
{
if (!Resolve(entity.Owner, ref entity.Comp, false))
return;
var ev = new GetVisMaskEvent()
{
Entity = entity.Owner,
};
RaiseLocalEvent(entity.Owner, ref ev, true);
SetVisibilityMask(entity.Owner, ev.VisibilityMask, entity.Comp);
}
}
/// <summary>
/// Event raised to update the vismask of an entity's eye.
/// </summary>
[ByRefEvent]
public record struct GetVisMaskEvent()
{
public EntityUid Entity;
public int VisibilityMask = EyeComponent.DefaultVisibilityMask;
}