From 86f1ce217c62702af841af4983b274b31569ceb1 Mon Sep 17 00:00:00 2001 From: Moony Date: Tue, 30 Nov 2021 08:54:51 -0600 Subject: [PATCH] Adds gamer flare to the game. (#4998) --- .../Light/RgbLightControllerSystem.cs | 37 +++++++++++++++++++ .../Component/RgbLightControllerComponent.cs | 21 +++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Content.Client/Light/RgbLightControllerSystem.cs create mode 100644 Content.Shared/Light/Component/RgbLightControllerComponent.cs diff --git a/Content.Client/Light/RgbLightControllerSystem.cs b/Content.Client/Light/RgbLightControllerSystem.cs new file mode 100644 index 0000000000..be0b7ab4b0 --- /dev/null +++ b/Content.Client/Light/RgbLightControllerSystem.cs @@ -0,0 +1,37 @@ +using System; +using Content.Shared.Light; +using Content.Shared.Light.Component; +using Robust.Client.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Maths; +using Robust.Shared.Timing; + +namespace Content.Client.Light +{ + public class RgbLightControllerSystem : EntitySystem + { + [Dependency] private IGameTiming _gameTiming = default!; + + public override void Update(float frameTime) + { + base.Update(frameTime); + var curTime = _gameTiming.CurTime; + foreach (var (rgb, light, sprite) in EntityManager.EntityQuery()) + { + light.Color = GetCurrentRgbColor(curTime, TimeSpan.FromSeconds(rgb.CreationTick.Value * _gameTiming.TickPeriod.TotalSeconds), rgb); + sprite.Color = GetCurrentRgbColor(curTime, TimeSpan.FromSeconds(rgb.CreationTick.Value * _gameTiming.TickPeriod.TotalSeconds), rgb); + } + } + + public static Color GetCurrentRgbColor(TimeSpan curTime, TimeSpan offset, RgbLightControllerComponent rgb) + { + return Color.FromHsv(new Vector4( + (float) (((curTime.TotalSeconds - offset.TotalSeconds) / rgb.CycleRate + Math.Abs(rgb.Owner.Uid.GetHashCode() * 0.1)) % 1), + 1.0f, + 1.0f, + 1.0f + )); + } + } +} diff --git a/Content.Shared/Light/Component/RgbLightControllerComponent.cs b/Content.Shared/Light/Component/RgbLightControllerComponent.cs new file mode 100644 index 0000000000..08c03f2fdf --- /dev/null +++ b/Content.Shared/Light/Component/RgbLightControllerComponent.cs @@ -0,0 +1,21 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Content.Shared.Light.Component +{ + /// + /// Networked solely for admemes. + /// + [NetworkedComponent] + [RegisterComponent] + public class RgbLightControllerComponent : Robust.Shared.GameObjects.Component + { + public override string Name => "RgbLightController"; + + [DataField("cycleRate")] + [ViewVariables(VVAccess.ReadWrite)] + public float CycleRate { get; set; } = 10.0f; + } +}