2021-01-06 22:50:49 +11:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Light.Components;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2020-08-13 22:17:12 +10:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Robust.Shared.Localization;
|
2018-11-11 20:05:09 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Light.EntitySystems
|
2018-11-11 20:05:09 +01:00
|
|
|
{
|
2020-08-13 22:17:12 +10:00
|
|
|
[UsedImplicitly]
|
|
|
|
|
internal sealed class HandHeldLightSystem : EntitySystem
|
2018-11-11 20:05:09 +01:00
|
|
|
{
|
2021-01-06 22:50:49 +11:00
|
|
|
// TODO: Ideally you'd be able to subscribe to power stuff to get events at certain percentages.. or something?
|
|
|
|
|
// But for now this will be better anyway.
|
|
|
|
|
private HashSet<HandheldLightComponent> _activeLights = new();
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<ActivateHandheldLightMessage>(HandleActivate);
|
|
|
|
|
SubscribeLocalEvent<DeactivateHandheldLightMessage>(HandleDeactivate);
|
2021-10-05 14:29:03 +11:00
|
|
|
SubscribeLocalEvent<HandheldLightComponent, GetActivationVerbsEvent>(AddToggleLightVerb);
|
2021-01-06 22:50:49 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
_activeLights.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleActivate(ActivateHandheldLightMessage message)
|
|
|
|
|
{
|
|
|
|
|
_activeLights.Add(message.Component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleDeactivate(DeactivateHandheldLightMessage message)
|
|
|
|
|
{
|
|
|
|
|
_activeLights.Remove(message.Component);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 20:05:09 +01:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2021-01-06 22:50:49 +11:00
|
|
|
foreach (var handheld in _activeLights.ToArray())
|
2018-11-11 20:05:09 +01:00
|
|
|
{
|
2021-01-06 22:50:49 +11:00
|
|
|
if (handheld.Deleted || handheld.Paused) continue;
|
|
|
|
|
handheld.OnUpdate(frameTime);
|
2018-11-11 20:05:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-10-05 14:29:03 +11:00
|
|
|
|
|
|
|
|
private void AddToggleLightVerb(EntityUid uid, HandheldLightComponent component, GetActivationVerbsEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.CanAccess || !args.CanInteract)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Verb verb = new();
|
|
|
|
|
verb.Text = Loc.GetString("verb-toggle-light");
|
|
|
|
|
verb.IconTexture = "/Textures/Interface/VerbIcons/light.svg.192dpi.png";
|
|
|
|
|
verb.Act = component.Activated
|
|
|
|
|
? () => component.TurnOff()
|
|
|
|
|
: () => component.TurnOn(args.User);
|
|
|
|
|
|
|
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
2018-11-11 20:05:09 +01:00
|
|
|
}
|
|
|
|
|
}
|