1
0

HandheldLightSystem.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Content.Client.Items;
  2. using Content.Client.Light.Components;
  3. using Content.Shared.Light;
  4. using Content.Shared.Light.Components;
  5. using Content.Shared.Toggleable;
  6. using Robust.Client.GameObjects;
  7. using Content.Client.Light.EntitySystems;
  8. namespace Content.Client.Light;
  9. public sealed class HandheldLightSystem : SharedHandheldLightSystem
  10. {
  11. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  12. [Dependency] private readonly LightBehaviorSystem _lightBehavior = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
  17. SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
  18. }
  19. /// <remarks>
  20. /// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
  21. /// </remarks>
  22. public override bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true)
  23. {
  24. return true;
  25. }
  26. /// <remarks>
  27. /// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
  28. /// </remarks>
  29. public override bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid)
  30. {
  31. return true;
  32. }
  33. private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
  34. {
  35. if (!Resolve(uid, ref component))
  36. {
  37. return;
  38. }
  39. if (!_appearance.TryGetData<bool>(uid, ToggleableLightVisuals.Enabled, out var enabled, args.Component))
  40. {
  41. return;
  42. }
  43. if (!_appearance.TryGetData<HandheldLightPowerStates>(uid, HandheldLightVisuals.Power, out var state, args.Component))
  44. {
  45. return;
  46. }
  47. if (TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
  48. {
  49. // Reset any running behaviour to reset the animated properties back to the original value, to avoid conflicts between resets
  50. if (_lightBehavior.HasRunningBehaviours((uid, lightBehaviour)))
  51. {
  52. _lightBehavior.StopLightBehaviour((uid, lightBehaviour), resetToOriginalSettings: true);
  53. }
  54. if (!enabled)
  55. {
  56. return;
  57. }
  58. switch (state)
  59. {
  60. case HandheldLightPowerStates.FullPower:
  61. break; // We just needed to reset all behaviours
  62. case HandheldLightPowerStates.LowPower:
  63. _lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.RadiatingBehaviourId);
  64. break;
  65. case HandheldLightPowerStates.Dying:
  66. _lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.BlinkingBehaviourId);
  67. break;
  68. }
  69. }
  70. }
  71. }