From f2fa647523ec6ff1b89832b67cd501ed74abcf4c Mon Sep 17 00:00:00 2001 From: Fluffiest Floofers Date: Thu, 5 Oct 2023 21:26:41 +0200 Subject: [PATCH] it works? (#100) --- .../Nyanotrasen/Overlays/DogVisionOverlay.cs | 44 ++++++++++++++++ .../Nyanotrasen/Overlays/DogVisionSystem.cs | 51 +++++++++++++++++++ .../Abilities/DogVisionComponent.cs | 9 ++++ .../Nyanotrasen/Shaders/dogvision.yml | 4 ++ .../Nyanotrasen/Traits/disabilities.yml | 5 ++ .../Nyanotrasen/Shaders/dogvision.swsl | 14 +++++ 6 files changed, 127 insertions(+) create mode 100644 Content.Client/Nyanotrasen/Overlays/DogVisionOverlay.cs create mode 100644 Content.Client/Nyanotrasen/Overlays/DogVisionSystem.cs create mode 100644 Content.Shared/Nyanotrasen/Abilities/DogVisionComponent.cs create mode 100644 Resources/Prototypes/Nyanotrasen/Shaders/dogvision.yml create mode 100644 Resources/Prototypes/Nyanotrasen/Traits/disabilities.yml create mode 100644 Resources/Textures/Nyanotrasen/Shaders/dogvision.swsl diff --git a/Content.Client/Nyanotrasen/Overlays/DogVisionOverlay.cs b/Content.Client/Nyanotrasen/Overlays/DogVisionOverlay.cs new file mode 100644 index 00000000000..95cfc683e09 --- /dev/null +++ b/Content.Client/Nyanotrasen/Overlays/DogVisionOverlay.cs @@ -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.Nyanotrasen.Overlays; + +public sealed partial class DogVisionOverlay : 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 _dogVisionShader; + + public DogVisionOverlay() + { + IoCManager.InjectDependencies(this); + _dogVisionShader = _prototypeManager.Index("DogVision").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(player)) + return; + + _dogVisionShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture); + + + var worldHandle = args.WorldHandle; + var viewport = args.WorldBounds; + worldHandle.SetTransform(Matrix3.Identity); + worldHandle.UseShader(_dogVisionShader); + worldHandle.DrawRect(viewport, Color.White); + } +} diff --git a/Content.Client/Nyanotrasen/Overlays/DogVisionSystem.cs b/Content.Client/Nyanotrasen/Overlays/DogVisionSystem.cs new file mode 100644 index 00000000000..8c252132a36 --- /dev/null +++ b/Content.Client/Nyanotrasen/Overlays/DogVisionSystem.cs @@ -0,0 +1,51 @@ +using Content.Shared.Abilities; +using Robust.Client.GameObjects; +using Robust.Client.Graphics; +using Robust.Client.Player; + +namespace Content.Client.Nyanotrasen.Overlays; + +public sealed partial class DogVisionSystem : EntitySystem +{ + [Dependency] private readonly IPlayerManager _player = default!; + [Dependency] private readonly IOverlayManager _overlayMan = default!; + + private DogVisionOverlay _overlay = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnDogVisionInit); + SubscribeLocalEvent(OnDogVisionShutdown); + + SubscribeLocalEvent(OnPlayerAttached); + SubscribeLocalEvent(OnPlayerDetached); + + _overlay = new(); + } + + private void OnPlayerAttached(EntityUid uid, DogVisionComponent component, PlayerAttachedEvent args) + { + _overlayMan.AddOverlay(_overlay); + } + + private void OnPlayerDetached(EntityUid uid, DogVisionComponent component, PlayerDetachedEvent args) + { + _overlayMan.RemoveOverlay(_overlay); + } + + private void OnDogVisionInit(EntityUid uid, DogVisionComponent component, ComponentInit args) + { + if (_player.LocalPlayer?.ControlledEntity == uid) + _overlayMan.AddOverlay(_overlay); + } + + private void OnDogVisionShutdown(EntityUid uid, DogVisionComponent component, ComponentShutdown args) + { + if (_player.LocalPlayer?.ControlledEntity == uid) + { + _overlayMan.RemoveOverlay(_overlay); + } + } +} diff --git a/Content.Shared/Nyanotrasen/Abilities/DogVisionComponent.cs b/Content.Shared/Nyanotrasen/Abilities/DogVisionComponent.cs new file mode 100644 index 00000000000..0d0a7f6580a --- /dev/null +++ b/Content.Shared/Nyanotrasen/Abilities/DogVisionComponent.cs @@ -0,0 +1,9 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Abilities; + +[RegisterComponent] +[NetworkedComponent] + +public sealed partial class DogVisionComponent : Component +{} diff --git a/Resources/Prototypes/Nyanotrasen/Shaders/dogvision.yml b/Resources/Prototypes/Nyanotrasen/Shaders/dogvision.yml new file mode 100644 index 00000000000..aa5f453ed89 --- /dev/null +++ b/Resources/Prototypes/Nyanotrasen/Shaders/dogvision.yml @@ -0,0 +1,4 @@ +- type: shader + id: DogVision + kind: source + path: "/Textures/Nyanotrasen/Shaders/dogvision.swsl" diff --git a/Resources/Prototypes/Nyanotrasen/Traits/disabilities.yml b/Resources/Prototypes/Nyanotrasen/Traits/disabilities.yml new file mode 100644 index 00000000000..dda6e58d744 --- /dev/null +++ b/Resources/Prototypes/Nyanotrasen/Traits/disabilities.yml @@ -0,0 +1,5 @@ +- type: trait + id: Colorblindness + name: Colorblindness + components: + - type: DogVision diff --git a/Resources/Textures/Nyanotrasen/Shaders/dogvision.swsl b/Resources/Textures/Nyanotrasen/Shaders/dogvision.swsl new file mode 100644 index 00000000000..1e8c7d2ed35 --- /dev/null +++ b/Resources/Textures/Nyanotrasen/Shaders/dogvision.swsl @@ -0,0 +1,14 @@ +uniform sampler2D SCREEN_TEXTURE; + +void fragment() { + highp vec4 color = zTextureSpec(SCREEN_TEXTURE, UV); + + highp mat3 m = mat3( + vec3(0.625,0.375,0.000), + vec3(0.700,0.300,0.000), + vec3(0.000,0.300,0.700) + ); + highp vec3 result = color.rgb * m; + + COLOR = vec4(result, 1); +}