Files
tbd-station-14/Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs
Centronias 9053c9692f Decouple Lights from Toggleable Visuals (and headphone music notes bugfix) (#35341)
* - 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
2025-05-30 19:53:56 -04:00

62 lines
2.1 KiB
C#

using Content.Shared.Interaction;
using Content.Shared.Light;
using Content.Shared.Light.Components;
using Content.Shared.Toggleable;
using Content.Shared.Tools.Systems;
using Robust.Shared.Random;
namespace Content.Shared.Weapons.Melee.EnergySword;
public sealed class EnergySwordSystem : EntitySystem
{
[Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
}
// Used to pick a random color for the blade on map init.
private void OnMapInit(Entity<EnergySwordComponent> entity, ref MapInitEvent args)
{
if (entity.Comp.ColorOptions.Count != 0)
{
entity.Comp.ActivatedColor = _random.Pick(entity.Comp.ColorOptions);
Dirty(entity);
}
if (!TryComp(entity, out AppearanceComponent? appearanceComponent))
return;
_appearance.SetData(entity, ToggleableVisuals.Color, entity.Comp.ActivatedColor, appearanceComponent);
}
// Used to make the blade multicolored when using a multitool on it.
private void OnInteractUsing(Entity<EnergySwordComponent> entity, ref InteractUsingEvent args)
{
if (args.Handled)
return;
if (!_toolSystem.HasQuality(args.Used, SharedToolSystem.PulseQuality))
return;
args.Handled = true;
entity.Comp.Hacked = !entity.Comp.Hacked;
if (entity.Comp.Hacked)
{
var rgb = EnsureComp<RgbLightControllerComponent>(entity);
_rgbSystem.SetCycleRate(entity, entity.Comp.CycleRate, rgb);
}
else
RemComp<RgbLightControllerComponent>(entity);
Dirty(entity);
}
}