mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
PinpointerSystem&Component cleanup (#42463)
* cleanup * make some stuff nullable again * Apply suggestions from code review Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> * fix and remove a dependency --------- Co-authored-by: seanpimble <149889301+seanpimble@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
committed by
Coryler
co-authored by
slarticodefast
seanpimble
parent
f889c9f817
commit
da240861a4
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Server.Shuttles.Events;
|
||||
using Content.Shared.IdentityManagement;
|
||||
|
||||
namespace Content.Server.Pinpointer;
|
||||
|
||||
public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
@@ -23,34 +23,35 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
SubscribeLocalEvent<FTLCompletedEvent>(OnLocateTarget);
|
||||
}
|
||||
|
||||
public override bool TogglePinpointer(EntityUid uid, PinpointerComponent? pinpointer = null)
|
||||
public override bool TogglePinpointer(Entity<PinpointerComponent?> ent)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return false;
|
||||
|
||||
var isActive = !pinpointer.IsActive;
|
||||
SetActive(uid, isActive, pinpointer);
|
||||
UpdateAppearance(uid, pinpointer);
|
||||
var isActive = !ent.Comp.IsActive;
|
||||
SetActive(ent, isActive);
|
||||
UpdateAppearance(ent);
|
||||
return isActive;
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, PinpointerComponent pinpointer, AppearanceComponent? appearance = null)
|
||||
private void UpdateAppearance(Entity<PinpointerComponent?, AppearanceComponent?> ent)
|
||||
{
|
||||
if (!Resolve(uid, ref appearance))
|
||||
if (!Resolve(ent, ref ent.Comp1) || !Resolve(ent, ref ent.Comp2))
|
||||
return;
|
||||
_appearance.SetData(uid, PinpointerVisuals.IsActive, pinpointer.IsActive, appearance);
|
||||
_appearance.SetData(uid, PinpointerVisuals.TargetDistance, pinpointer.DistanceToTarget, appearance);
|
||||
|
||||
_appearance.SetData(ent, PinpointerVisuals.IsActive, ent.Comp1.IsActive, ent.Comp2);
|
||||
_appearance.SetData(ent, PinpointerVisuals.TargetDistance, ent.Comp1.DistanceToTarget, ent.Comp2);
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, PinpointerComponent component, ActivateInWorldEvent args)
|
||||
private void OnActivate(Entity<PinpointerComponent> ent, ref ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !args.Complex)
|
||||
return;
|
||||
|
||||
TogglePinpointer(uid, component);
|
||||
TogglePinpointer(ent.AsNullable());
|
||||
|
||||
if (!component.CanRetarget)
|
||||
LocateTarget(uid, component, args); //#IMP args
|
||||
if (!ent.Comp.CanRetarget)
|
||||
LocateTarget(ent, args); // #IMP args
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
@@ -68,13 +69,15 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
if (pinpointer.CanRetarget)
|
||||
continue;
|
||||
|
||||
LocateTarget(uid, pinpointer);
|
||||
LocateTarget((uid, pinpointer));
|
||||
}
|
||||
}
|
||||
|
||||
//#IMP ActivateInWorldEvent args: added this
|
||||
private void LocateTarget(EntityUid uid, PinpointerComponent component, ActivateInWorldEvent? args = null)
|
||||
private void LocateTarget(Entity<PinpointerComponent> ent, ActivateInWorldEvent? args = null)
|
||||
{
|
||||
var component = ent.Comp;
|
||||
|
||||
// try to find target from whitelist
|
||||
if (component.IsActive && component.Component != null)
|
||||
{
|
||||
@@ -85,8 +88,8 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
return;
|
||||
}
|
||||
|
||||
var target = FindTargetFromComponent(uid, reg.Type);
|
||||
SetTarget(uid, target, component);
|
||||
var target = FindTargetFromComponent(ent.Owner, reg.Type);
|
||||
SetTarget(ent.AsNullable(), target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +102,7 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
var query = EntityQueryEnumerator<PinpointerComponent>();
|
||||
while (query.MoveNext(out var uid, out var pinpointer))
|
||||
{
|
||||
UpdateDirectionToTarget(uid, pinpointer);
|
||||
UpdateDirectionToTarget((uid, pinpointer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,17 +110,15 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
/// Try to find the closest entity from whitelist on a current map
|
||||
/// Will return null if can't find anything
|
||||
/// </summary>
|
||||
private EntityUid? FindTargetFromComponent(EntityUid uid, Type whitelist, TransformComponent? transform = null)
|
||||
private EntityUid? FindTargetFromComponent(Entity<TransformComponent?> ent, Type whitelist)
|
||||
{
|
||||
_xformQuery.Resolve(uid, ref transform, false);
|
||||
|
||||
if (transform == null)
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return null;
|
||||
|
||||
// sort all entities in distance increasing order
|
||||
var mapId = transform.MapID;
|
||||
var mapId = ent.Comp.MapID;
|
||||
var l = new SortedList<float, EntityUid>();
|
||||
var worldPos = _transform.GetWorldPosition(transform);
|
||||
var worldPos = _transform.GetWorldPosition(ent.Comp);
|
||||
|
||||
foreach (var (otherUid, _) in EntityManager.GetAllComponents(whitelist))
|
||||
{
|
||||
@@ -135,36 +136,38 @@ public sealed class PinpointerSystem : SharedPinpointerSystem
|
||||
/// <summary>
|
||||
/// Update direction from pinpointer to selected target (if it was set)
|
||||
/// </summary>
|
||||
protected override void UpdateDirectionToTarget(EntityUid uid, PinpointerComponent? pinpointer = null)
|
||||
protected override void UpdateDirectionToTarget(Entity<PinpointerComponent?> ent)
|
||||
{
|
||||
if (!Resolve(uid, ref pinpointer))
|
||||
if (!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
|
||||
var pinpointer = ent.Comp;
|
||||
|
||||
if (!pinpointer.IsActive)
|
||||
return;
|
||||
|
||||
var target = pinpointer.Target;
|
||||
if (target == null || !Exists(target.Value))
|
||||
{
|
||||
SetDistance(uid, Distance.Unknown, pinpointer);
|
||||
SetDistance(ent, Distance.Unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
var dirVec = CalculateDirection(uid, target.Value);
|
||||
var dirVec = CalculateDirection(ent, target.Value);
|
||||
var oldDist = pinpointer.DistanceToTarget;
|
||||
if (dirVec != null)
|
||||
{
|
||||
var angle = dirVec.Value.ToWorldAngle();
|
||||
TrySetArrowAngle(uid, angle, pinpointer);
|
||||
TrySetArrowAngle(ent, angle);
|
||||
var dist = CalculateDistance(dirVec.Value, pinpointer);
|
||||
SetDistance(uid, dist, pinpointer);
|
||||
SetDistance(ent, dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDistance(uid, Distance.Unknown, pinpointer);
|
||||
SetDistance(ent, Distance.Unknown);
|
||||
}
|
||||
if (oldDist != pinpointer.DistanceToTarget)
|
||||
UpdateAppearance(uid, pinpointer);
|
||||
UpdateAppearance(ent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user