Files
tbd-station-14/Content.Server/GameObjects/Components/Power/LightBulbComponent.cs
Víctor Aguilera Puerto b3aa1f6dcd Wall lights now require light bulbs. (#151)
* Adds light_tube.rsi

Sprites taken from CEV Eris!

* Adds LightBulbComponent

* Wall lights now use light bulbs!

* Light bulb now updates its sprite when it changes.

* Comments the code.

* Adds license and copyright to new sprites
2019-03-22 23:59:13 +01:00

72 lines
2.0 KiB
C#

using System;
using SS14.Server.GameObjects;
using SS14.Shared.Enums;
using SS14.Shared.GameObjects;
using SS14.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Power
{
public enum LightBulbState
{
Normal,
Broken,
Burned,
}
public enum LightBulbType
{
Tube,
}
/// <summary>
/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
/// </summary>
public class LightBulbComponent : Component
{
/// <summary>
/// Invoked whenever the state of the light bulb changes.
/// </summary>
public event EventHandler<EventArgs> OnLightBulbStateChange;
public override string Name => "LightBulb";
public LightBulbType Type = LightBulbType.Tube;
/// <summary>
/// The current state of the light bulb. Invokes the OnLightBulbStateChange event when set.
/// It also updates the bulb's sprite accordingly.
/// </summary>
public LightBulbState State
{
get { return _state; }
set
{
var sprite = Owner.GetComponent<SpriteComponent>();
OnLightBulbStateChange?.Invoke(this, EventArgs.Empty);
_state = value;
switch (value)
{
case LightBulbState.Normal:
sprite.LayerSetState(0, "normal");
break;
case LightBulbState.Broken:
sprite.LayerSetState(0, "broken");
break;
case LightBulbState.Burned:
sprite.LayerSetState(0, "burned");
break;
}
}
}
private LightBulbState _state = LightBulbState.Normal;
public override void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref Type, "bulb", LightBulbType.Tube);
}
}
}