Revert "Near-sighted trait from SIMPLE STATION 14 (#73)"

This reverts commit 54f65e30
This commit is contained in:
vorkathbruh 2024-05-09 08:48:53 +02:00 committed by null
parent 51c06a3613
commit 6e95cdda68
No known key found for this signature in database
GPG Key ID: 212F05528FD678BE
11 changed files with 0 additions and 370 deletions

View File

@ -1,130 +0,0 @@
using Content.Shared.SimpleStation14.Traits.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.SimpleStation14.Overlays.Shaders;
public sealed class NearsightedOverlay : Overlay
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _nearsightShader;
public float Radius;
private float _oldRadius;
public float Darkness;
private float _oldDarkness;
private float _lerpTime;
public float LerpDuration;
public NearsightedOverlay()
{
IoCManager.InjectDependencies(this);
_nearsightShader = _prototypeManager.Index<ShaderPrototype>("GradientCircleMask").InstanceUnique();
}
protected override bool BeforeDraw(in OverlayDrawArgs args)
{
// Check if the player has a NearsightedComponent and is controlling it
if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out NearsightedComponent? nearComp) ||
_playerManager.LocalPlayer?.ControlledEntity != nearComp.Owner)
return false;
// Check if the player has an EyeComponent and if the overlay should be drawn for this eye
if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out EyeComponent? eyeComp) ||
args.Viewport.Eye != eyeComp.Eye)
return false;
return true;
}
protected override void Draw(in OverlayDrawArgs args)
{
// We already checked if they have a NearsightedComponent and are controlling it in BeforeDraw, so we assume this hasn't changed
var nearComp = _entityManager.GetComponent<NearsightedComponent>(_playerManager.LocalPlayer!.ControlledEntity!.Value);
// Set LerpDuration based on nearComp.LerpDuration
LerpDuration = nearComp.LerpDuration;
// Set the radius and darkness values based on whether the player is wearing glasses or not
if (nearComp.Active)
{
Radius = nearComp.EquippedRadius;
Darkness = nearComp.EquippedAlpha;
}
else
{
Radius = nearComp.Radius;
Darkness = nearComp.Alpha;
}
var viewport = args.WorldAABB;
var handle = args.WorldHandle;
var distance = args.ViewportBounds.Width;
var lastFrameTime = (float) _timing.FrameTime.TotalSeconds;
// If the current radius value is different from the previous one, lerp between them
if (!MathHelper.CloseTo(_oldRadius, Radius, 0.001f))
{
_lerpTime += lastFrameTime;
var t = MathHelper.Clamp(_lerpTime / LerpDuration, 0f, 1f); // Calculate lerp time
_oldRadius = MathHelper.Lerp(_oldRadius, Radius, t); // Lerp between old and new radius values
}
// If the current radius value is the same as the previous one, reset the lerp time and old radius value
else
{
_lerpTime = 0f;
_oldRadius = Radius;
}
// If the current darkness value is different from the previous one, lerp between them
if (!MathHelper.CloseTo(_oldDarkness, Darkness, 0.001f))
{
_lerpTime += lastFrameTime;
var t = MathHelper.Clamp(_lerpTime / LerpDuration, 0f, 1f); // Calculate lerp time
_oldDarkness = MathHelper.Lerp(_oldDarkness, Darkness, t); // Lerp between old and new darkness values
}
// If the current darkness value is the same as the previous one, reset the lerp time and old darkness value
else
{
_lerpTime = 0f;
_oldDarkness = Darkness;
}
// Calculate the outer and inner radii based on the current radius value
var outerMaxLevel = 0.6f * distance;
var outerMinLevel = 0.06f * distance;
var innerMaxLevel = 0.02f * distance;
var innerMinLevel = 0.02f * distance;
var outerRadius = outerMaxLevel - _oldRadius * (outerMaxLevel - outerMinLevel);
var innerRadius = innerMaxLevel - _oldRadius * (innerMaxLevel - innerMinLevel);
// Set the shader parameters and draw the overlay
_nearsightShader.SetParameter("time", 0.0f);
_nearsightShader.SetParameter("color", new Vector3(1f, 1f, 1f));
_nearsightShader.SetParameter("darknessAlphaOuter", _oldDarkness);
_nearsightShader.SetParameter("innerCircleRadius", innerRadius);
_nearsightShader.SetParameter("innerCircleMaxRadius", innerRadius);
_nearsightShader.SetParameter("outerCircleRadius", outerRadius);
_nearsightShader.SetParameter("outerCircleMaxRadius", outerRadius + 0.2f * distance);
handle.UseShader(_nearsightShader);
handle.DrawRect(viewport, Color.Black);
handle.UseShader(null);
}
}

View File

@ -1,58 +0,0 @@
using Content.Client.SimpleStation14.Overlays.Shaders;
using Content.Shared.Inventory.Events;
using Content.Shared.SimpleStation14.Traits;
using Content.Shared.SimpleStation14.Traits.Components;
using Content.Shared.Tag;
using Robust.Client.Graphics;
namespace Content.Client.SimpleStation14.Overlays.Systems;
public sealed class NearsightedSystem : EntitySystem
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
private NearsightedOverlay _overlay = default!;
public override void Initialize()
{
base.Initialize();
_overlay = new NearsightedOverlay();
SubscribeLocalEvent<NearsightedComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<GotEquippedEvent>(OnEquip);
SubscribeLocalEvent<GotUnequippedEvent>(OnUnEquip);
}
private void OnStartup(EntityUid uid, NearsightedComponent component, ComponentStartup args)
{
UpdateShader(component, false);
}
private void OnEquip(GotEquippedEvent args)
{
if (TryComp<NearsightedComponent>(args.Equipee, out var nearsighted) &&
EnsureComp<TagComponent>(args.Equipment).Tags.Contains("GlassesNearsight"))
UpdateShader(nearsighted, true);
}
private void OnUnEquip(GotUnequippedEvent args)
{
if (TryComp<NearsightedComponent>(args.Equipee, out var nearsighted) &&
EnsureComp<TagComponent>(args.Equipment).Tags.Contains("GlassesNearsight"))
UpdateShader(nearsighted, false);
}
private void UpdateShader(NearsightedComponent component, bool booLean)
{
while (_overlayMan.HasOverlay<NearsightedOverlay>())
{
_overlayMan.RemoveOverlay(_overlay);
}
component.Active = booLean;
_overlayMan.AddOverlay(_overlay);
}
}

View File

@ -1,15 +0,0 @@
using Robust.Shared.Prototypes;
namespace Content.Shared.SimpleStation14.Clothing
{
[RegisterComponent]
public sealed partial class ClothingGrantComponentComponent : Component
{
[DataField("component", required: true)]
[AlwaysPushInheritance]
public ComponentRegistry Components { get; private set; } = new();
[ViewVariables(VVAccess.ReadWrite)]
public bool IsActive = false;
}
}

View File

@ -1,11 +0,0 @@
namespace Content.Shared.SimpleStation14.Clothing;
[RegisterComponent]
public sealed partial class ClothingGrantTagComponent : Component
{
[DataField("tag", required: true), ViewVariables(VVAccess.ReadWrite)]
public string Tag = "";
[ViewVariables(VVAccess.ReadWrite)]
public bool IsActive = false;
}

View File

@ -1,92 +0,0 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Tag;
namespace Content.Shared.SimpleStation14.Clothing;
public sealed class ClothingGrantingSystem : EntitySystem
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ClothingGrantComponentComponent, GotEquippedEvent>(OnCompEquip);
SubscribeLocalEvent<ClothingGrantComponentComponent, GotUnequippedEvent>(OnCompUnequip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotEquippedEvent>(OnTagEquip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotUnequippedEvent>(OnTagUnequip);
}
private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing)) return;
if (!clothing.Slots.HasFlag(args.SlotFlags)) return;
if (component.Components.Count > 1)
{
Logger.Error("Although a component registry supports multiple components, we cannot bookkeep more than 1 component for ClothingGrantComponent at this time.");
return;
}
foreach (var (name, data) in component.Components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
if (HasComp(args.Equipee, newComp.GetType()))
continue;
newComp.Owner = args.Equipee;
var temp = (object) newComp;
_serializationManager.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(args.Equipee, (Component)temp!);
component.IsActive = true;
}
}
private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent component, GotUnequippedEvent args)
{
if (!component.IsActive) return;
foreach (var (name, data) in component.Components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
RemComp(args.Equipee, newComp.GetType());
}
component.IsActive = false;
}
private void OnTagEquip(EntityUid uid, ClothingGrantTagComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing))
return;
if (!clothing.Slots.HasFlag(args.SlotFlags))
return;
EnsureComp<TagComponent>(args.Equipee);
_tagSystem.AddTag(args.Equipee, component.Tag);
component.IsActive = true;
}
private void OnTagUnequip(EntityUid uid, ClothingGrantTagComponent component, GotUnequippedEvent args)
{
if (!component.IsActive)
return;
_tagSystem.RemoveTag(args.Equipee, component.Tag);
component.IsActive = false;
}
}

View File

@ -1,49 +0,0 @@
using Robust.Shared.GameStates;
namespace Content.Shared.SimpleStation14.Traits.Components;
/// <summary>
/// Owner entity cannot see well, without prescription glasses.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class NearsightedComponent : Component
{
/// <summary>
/// Distance from the edge of the screen to the center
/// </summary>
/// <remarks>
/// I don't know how the distance is measured, 1 is very close to the center, 0 is maybe visible around the edge
/// </remarks>
[DataField("radius"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Radius = 0.8f;
/// <summary>
/// How dark the circle mask is from <see cref="Radius"/>
/// </summary>
/// <remarks>
/// I also don't know how this works, it only starts getting noticeably dark at 0.7, and is definitely noticeable at 0.9, 1 is black
/// </remarks>
[DataField("alpha"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Alpha = 0.995f;
/// <inheritdoc cref="Radius"/>
[DataField("equippedRadius"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float EquippedRadius = 0.45f;
/// <inheritdoc cref="Alpha"/>
[DataField("equippedAlpha"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float EquippedAlpha = 0.93f;
/// <summary>
/// How long the lerp animation should go on for in seconds.
/// </summary>
[DataField("lerpDuration"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float LerpDuration = 0.25f;
/// <summary>
/// If true, uses the variables prefixed "Equipped"
/// If false, uses the variables without a prefix
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] // Make the system shared if you want this networked, I don't wanna do that
public bool Active = false;
}

View File

@ -1,3 +0,0 @@
trait-nearsighted-name = Nearsighted
trait-nearsighted-desc = You require glasses to see properly.
trait-nearsighted-examined = [color=lightblue]{CAPITALIZE(POSS-ADJ($target))} eyes are pretty unfocused. It doesn't seem like {SUBJECT($target)} can see things that well.[/color]

View File

@ -8,7 +8,6 @@
EpinephrineChemistryBottle: 3
Syringe: 5
Portafib: 1 # DeltaV - Add Portafibs, see Prototypes/DeltaV/Entities/Objects/Devices/Medical/portafib.yml
ClothingEyesGlasses: 5 # SimpleStation14 NearsightedTrait
ClothingEyesHudMedical: 2
ClothingEyesEyepatchHudMedical: 2

View File

@ -82,7 +82,6 @@
tags:
- HamsterWearable
- WhitelistChameleon
- GlassesNearsight # SimpleStation14 NearsightedTrait
- type: entity
parent: ClothingEyesBase

View File

@ -1,8 +0,0 @@
- type: trait
id: Nearsighted
name: trait-nearsighted-name
description: You require glasses to see properly.
traitGear: ClothingEyesGlasses
components:
- type: Nearsighted

View File

@ -1,2 +0,0 @@
- type: Tag
id: GlassesNearsight