add hrp ++++ aspect (#587)

This commit is contained in:
ThereDrD
2024-08-08 21:05:25 +03:00
committed by GitHub
parent 48c86bd846
commit a6a69cc60f
10 changed files with 185 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ using System.Numerics;
using Content.Shared.Camera;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Item;
using Robust.Shared.Serialization;
namespace Content.Shared._White.Telescope;
@@ -41,19 +42,45 @@ public abstract class SharedTelescopeSystem : EntitySystem
if (!TryComp(args.User, out EyeComponent? eye))
return;
if (!HasComp<ItemComponent>(ent.Owner))
return;
SetOffset((args.User, eye), Vector2.Zero, ent);
}
public EntityUid GetRightEntity(EntityUid? ent)
{
var entity = EntityUid.Invalid;
if (TryComp<HandsComponent>(ent, out var hands) &&
HasComp<TelescopeComponent>(hands.ActiveHandEntity) &&
hands.ActiveHandEntity.HasValue)
{
entity = hands.ActiveHandEntity.Value;
}
else if (HasComp<TelescopeComponent>(ent))
{
entity = ent.Value;
}
return entity;
}
private void OnEyeOffsetChanged(EyeOffsetChangedEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not { } ent)
return;
if (!TryComp<HandsComponent>(ent, out var hands) ||
!TryComp<TelescopeComponent>(hands.ActiveHandEntity, out var telescope) ||
!TryComp(ent, out EyeComponent? eye))
if (!TryComp(ent, out EyeComponent? eye))
return;
var entity = GetRightEntity(ent);
if (entity == EntityUid.Invalid)
return;
var telescope = Comp<TelescopeComponent>(entity);
var offset = Vector2.Lerp(eye.Offset, msg.Offset, telescope.LerpAmount);
SetOffset((ent, eye), offset, telescope);
@@ -71,6 +98,19 @@ public abstract class SharedTelescopeSystem : EntitySystem
else
_eye.SetOffset(ent, offset, ent);
}
public void SetParameters(Entity<TelescopeComponent> ent, float? divisor = null, float? lerpAmount = null)
{
var telescope = ent.Comp;
divisor ??= telescope.Divisor;
lerpAmount ??= telescope.LerpAmount;
telescope.Divisor = divisor.Value;
telescope.LerpAmount = lerpAmount.Value;
Dirty(ent.Owner, telescope);
}
}
[Serializable, NetSerializable]