Skip to content

Commit

Permalink
Harpy Ultravision trait
Browse files Browse the repository at this point in the history
TODO: Optional trait that disables it
  • Loading branch information
VMSolidus committed Feb 5, 2024
1 parent 40cb95a commit aa2cd07
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 1 deletion.
44 changes: 44 additions & 0 deletions Content.Client/DeltaV/Overlays/UltraVisionOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Content.Shared.Abilities;

namespace Content.Client.DeltaV.Overlays;

public sealed partial class UltraVisionOverlay : Overlay
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] IEntityManager _entityManager = default!;


public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private readonly ShaderInstance _ultraVisionShader;

public UltraVisionOverlay()
{
IoCManager.InjectDependencies(this);
_ultraVisionShader = _prototypeManager.Index<ShaderPrototype>("UltraVision").Instance().Duplicate();
}

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player)
return;
if (!_entityManager.HasComponent<UltraVisionComponent>(player))
return;

_ultraVisionShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);


var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;
worldHandle.SetTransform(Matrix3.Identity);
worldHandle.UseShader(_ultraVisionShader);
worldHandle.DrawRect(viewport, Color.White);
}
}
46 changes: 46 additions & 0 deletions Content.Client/DeltaV/Overlays/UltraVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Shared.Abilities;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;

namespace Content.Client.DeltaV.Overlays;

public sealed partial class UltraVisionSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IOverlayManager _overlayMan = default!;

private UltraVisionOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<UltraVisionComponent, ComponentInit>(OnUltraVisionInit);
SubscribeLocalEvent<UltraVisionComponent, ComponentShutdown>(OnUltraVisionShutdown);

_player.LocalPlayerAttached += OnAttachedChanged;
_player.LocalPlayerDetached += OnAttachedChanged;

_overlay = new();
}

private void OnAttachedChanged(EntityUid uid)
{
_overlayMan.AddOverlay(_overlay);
}

private void OnUltraVisionInit(EntityUid uid, UltraVisionComponent component, ComponentInit args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
_overlayMan.AddOverlay(_overlay);
}

private void OnUltraVisionShutdown(EntityUid uid, UltraVisionComponent component, ComponentShutdown args)
{
if (_player.LocalPlayer?.ControlledEntity == uid)
{
_overlayMan.RemoveOverlay(_overlay);
}
}
}
8 changes: 8 additions & 0 deletions Content.Shared/DeltaV/Abilities/UltraVisionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Abilities;

[RegisterComponent]
[NetworkedComponent]

public sealed partial class UltraVisionComponent : Component
{}
4 changes: 3 additions & 1 deletion Resources/Locale/en-US/deltav/traits/traits.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
trait-scottish-accent-name = Scottish Accent
trait-scottish-accent-desc = Fer tha folk who come frae Hielan clan.
trait-scottish-accent-desc = Fer tha folk who come frae Hielan clan.
trait-ultravision-desc = Whether through custom bionic eyes, random mutation,
or being a Harpy, you perceive the world with ultraviolet light.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
- type: Inventory
speciesId: harpy
- type: HarpyVisuals
- type: UltraVision

- type: entity
save: false
Expand Down
4 changes: 4 additions & 0 deletions Resources/Prototypes/DeltaV/Shaders/birdvision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- type: shader
id: UltraVision
kind: source
path: "/Textures/DeltaV/Shaders/ultravision.swsl"
6 changes: 6 additions & 0 deletions Resources/Prototypes/DeltaV/Traits/altvision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- type: trait
id: UltraVision
name: Ultraviolet Vision
description: trait-ultravision-desc
components:
- type: UltraVision
14 changes: 14 additions & 0 deletions Resources/Textures/DeltaV/Shaders/ultravision.swsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uniform sampler2D SCREEN_TEXTURE;

void fragment() {
highp vec4 color = zTextureSpec(SCREEN_TEXTURE, UV);

highp mat3 m = mat3(
vec3(0.000,1.000,0.000),
vec3(0.000,0.000,1.000),
vec3(-0.165,0.165,1.000)
);
highp vec3 result = color.rgb * m;

COLOR = vec4(result, 1);
}

0 comments on commit aa2cd07

Please sign in to comment.