* - Combine enum keys `ToggleableLightVisuals` and `ToggleVisuals` into `ToggleableVisuals` - Rename `ToggleableLightVisualsComponent` to `ToggleableVisualsComponent` and `ToggleableLightVisualsSystem` to `ToggleableVisualsSystem` - (The `SpriteLayer` field on the component is now required because the old default of `light` doesn't make sense anymore) - Make it so that `ToggleableVisualsComponent` works even when there's not a light attached to the entity - (Amazingly this seems to have only applied to Headphones, but I can only imagine there are many other things people would like to do with simple toggleable visuals) - Explicitly make `ItemTogglePointLightComponent`'s purpose to make `ToggleVisualsComponent` apply to `PointLightComponent`s on the same entity. - Add field `ToggleableVisualsColorModulatesLights`, which makes the `Color` appearance value of `ToggleableVisuals` modulate the color of lights on the same entity - Lots of prototype updates to uptake the above * fix bad merge * unbork robust * blindly letting rider reformat stuff * I guess I never cleaned up these imports at all
84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using Content.Client.Items;
|
|
using Content.Client.Light.Components;
|
|
using Content.Shared.Light;
|
|
using Content.Shared.Light.Components;
|
|
using Content.Shared.Toggleable;
|
|
using Robust.Client.GameObjects;
|
|
using Content.Client.Light.EntitySystems;
|
|
|
|
namespace Content.Client.Light;
|
|
|
|
public sealed class HandheldLightSystem : SharedHandheldLightSystem
|
|
{
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly LightBehaviorSystem _lightBehavior = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
|
|
SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
}
|
|
|
|
/// <remarks>
|
|
/// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
|
|
/// </remarks>
|
|
public override bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/// <remarks>
|
|
/// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
|
|
/// </remarks>
|
|
public override bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_appearance.TryGetData<bool>(uid, ToggleableVisuals.Enabled, out var enabled, args.Component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_appearance.TryGetData<HandheldLightPowerStates>(uid, HandheldLightVisuals.Power, out var state, args.Component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
|
|
{
|
|
// Reset any running behaviour to reset the animated properties back to the original value, to avoid conflicts between resets
|
|
if (_lightBehavior.HasRunningBehaviours((uid, lightBehaviour)))
|
|
{
|
|
_lightBehavior.StopLightBehaviour((uid, lightBehaviour), resetToOriginalSettings: true);
|
|
}
|
|
|
|
if (!enabled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (state)
|
|
{
|
|
case HandheldLightPowerStates.FullPower:
|
|
break; // We just needed to reset all behaviours
|
|
case HandheldLightPowerStates.LowPower:
|
|
_lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.RadiatingBehaviourId);
|
|
break;
|
|
case HandheldLightPowerStates.Dying:
|
|
_lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.BlinkingBehaviourId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|