2023-09-04 06:31:10 +01:00
|
|
|
using Content.Shared.Light.Components;
|
2025-08-12 07:06:28 +10:00
|
|
|
using Content.Shared.Light.EntitySystems;
|
2023-02-13 19:43:51 -08:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
namespace Content.Client.Light.EntitySystems;
|
2023-02-13 19:43:51 -08:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
public sealed class LightBulbSystem : SharedLightBulbSystem
|
2023-02-13 19:43:51 -08:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
|
|
|
|
[Dependency] private readonly SpriteSystem _sprite = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<LightBulbComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAppearanceChange(EntityUid uid, LightBulbComponent comp, ref AppearanceChangeEvent args)
|
2023-02-13 19:43:51 -08:00
|
|
|
{
|
|
|
|
|
if (args.Sprite == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// update sprite state
|
2025-08-12 07:06:28 +10:00
|
|
|
if (_appearance.TryGetData<LightBulbState>(uid, LightBulbVisuals.State, out var state, args.Component))
|
2023-02-13 19:43:51 -08:00
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case LightBulbState.Normal:
|
2025-08-12 07:06:28 +10:00
|
|
|
_sprite.LayerSetRsiState((uid, args.Sprite), LightBulbVisualLayers.Base, comp.NormalSpriteState);
|
2023-02-13 19:43:51 -08:00
|
|
|
break;
|
|
|
|
|
case LightBulbState.Broken:
|
2025-08-12 07:06:28 +10:00
|
|
|
_sprite.LayerSetRsiState((uid, args.Sprite), LightBulbVisualLayers.Base, comp.BrokenSpriteState);
|
2023-02-13 19:43:51 -08:00
|
|
|
break;
|
|
|
|
|
case LightBulbState.Burned:
|
2025-08-12 07:06:28 +10:00
|
|
|
_sprite.LayerSetRsiState((uid, args.Sprite), LightBulbVisualLayers.Base, comp.BurnedSpriteState);
|
2023-02-13 19:43:51 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// also update sprites color
|
2025-08-12 07:06:28 +10:00
|
|
|
if (_appearance.TryGetData<Color>(uid, LightBulbVisuals.Color, out var color, args.Component))
|
2023-02-13 19:43:51 -08:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
_sprite.SetColor((uid, args.Sprite), color);
|
2023-02-13 19:43:51 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|