Light bulbs can now be colored! (#154)
-Also fixes a bug where bulb type didn't matter when inserting a new bulb into a light fixture. -And a bug where bulb state changing didn't change the light itself. P.S. Also note I didn't add any colored lightbulb prototypes, as I don't think they're necessary right now. To see the changes, please use VV! In the future, it might be possible to change the lightbulb's color with a multitool or something in-game.
This commit is contained in:
committed by
Pieter-Jan Briers
parent
5c234c1de4
commit
4f2ae14b3f
@@ -193,4 +193,4 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="GameObjects\Components\Healing\" />
|
<Folder Include="GameObjects\Components\Healing\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using SS14.Server.GameObjects;
|
|
||||||
using SS14.Shared.Enums;
|
|
||||||
using SS14.Shared.GameObjects;
|
using SS14.Shared.GameObjects;
|
||||||
|
using SS14.Shared.Maths;
|
||||||
using SS14.Shared.Serialization;
|
using SS14.Shared.Serialization;
|
||||||
|
using SS14.Shared.ViewVariables;
|
||||||
|
using SpriteComponent = SS14.Server.GameObjects.SpriteComponent;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Power
|
namespace Content.Server.GameObjects.Components.Power
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,20 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
/// Invoked whenever the state of the light bulb changes.
|
/// Invoked whenever the state of the light bulb changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<EventArgs> OnLightBulbStateChange;
|
public event EventHandler<EventArgs> OnLightBulbStateChange;
|
||||||
|
public event EventHandler<EventArgs> OnLightColorChange;
|
||||||
|
|
||||||
|
private Color _color = Color.White;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)] public Color Color
|
||||||
|
{
|
||||||
|
get { return _color; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_color = value;
|
||||||
|
OnLightColorChange?.Invoke(this, null);
|
||||||
|
UpdateColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override string Name => "LightBulb";
|
public override string Name => "LightBulb";
|
||||||
|
|
||||||
@@ -37,7 +52,7 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
/// The current state of the light bulb. Invokes the OnLightBulbStateChange event when set.
|
/// The current state of the light bulb. Invokes the OnLightBulbStateChange event when set.
|
||||||
/// It also updates the bulb's sprite accordingly.
|
/// It also updates the bulb's sprite accordingly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LightBulbState State
|
[ViewVariables(VVAccess.ReadWrite)] public LightBulbState State
|
||||||
{
|
{
|
||||||
get { return _state; }
|
get { return _state; }
|
||||||
set
|
set
|
||||||
@@ -65,7 +80,19 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
serializer.DataField(ref Type, "bulb", LightBulbType.Tube);
|
serializer.DataField(ref Type, "bulb", LightBulbType.Tube);
|
||||||
|
serializer.DataField(ref _color, "color", Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateColor()
|
||||||
|
{
|
||||||
|
var sprite = Owner.GetComponent<SpriteComponent>();
|
||||||
|
sprite.Color = Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
UpdateColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,16 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
|
|
||||||
[ViewVariables] private float Load = 40;
|
[ViewVariables] private float Load = 40;
|
||||||
|
|
||||||
[ViewVariables] private ContainerSlot LightBulbContainer;
|
[ViewVariables] private ContainerSlot _lightBulbContainer;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private LightBulbComponent LightBulb
|
private LightBulbComponent LightBulb
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (LightBulbContainer.ContainedEntity == null) return null;
|
if (_lightBulbContainer.ContainedEntity == null) return null;
|
||||||
|
|
||||||
LightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent bulb);
|
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent bulb);
|
||||||
|
|
||||||
return bulb;
|
return bulb;
|
||||||
}
|
}
|
||||||
@@ -51,17 +51,7 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
|
|
||||||
bool IAttackby.Attackby(IEntity user, IEntity attackwith)
|
bool IAttackby.Attackby(IEntity user, IEntity attackwith)
|
||||||
{
|
{
|
||||||
if (!attackwith.HasComponent<LightBulbComponent>()) return false;
|
return InsertBulb(attackwith);
|
||||||
|
|
||||||
if (LightBulb != null) return false;
|
|
||||||
|
|
||||||
user.GetComponent<IHandsComponent>().Drop(attackwith, LightBulbContainer);
|
|
||||||
|
|
||||||
var inserted = LightBulbContainer.Insert(attackwith);
|
|
||||||
|
|
||||||
UpdateLight();
|
|
||||||
|
|
||||||
return inserted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IAttackHand.Attackhand(IEntity user)
|
bool IAttackHand.Attackhand(IEntity user)
|
||||||
@@ -83,6 +73,26 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts the bulb if possible.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if it could insert it, false if it couldn't.</returns>
|
||||||
|
private bool InsertBulb(IEntity bulb)
|
||||||
|
{
|
||||||
|
if (LightBulb != null) return false;
|
||||||
|
if (!bulb.TryGetComponent(out LightBulbComponent lightBulb)) return false;
|
||||||
|
if (lightBulb.Type != BulbType) return false;
|
||||||
|
|
||||||
|
var inserted = _lightBulbContainer.Insert(bulb);
|
||||||
|
|
||||||
|
lightBulb.OnLightBulbStateChange += UpdateLight;
|
||||||
|
lightBulb.OnLightColorChange += UpdateLight;
|
||||||
|
|
||||||
|
UpdateLight();
|
||||||
|
|
||||||
|
return inserted;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ejects the bulb to a mob's hand if possible.
|
/// Ejects the bulb to a mob's hand if possible.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -92,7 +102,10 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
|
|
||||||
var bulb = LightBulb;
|
var bulb = LightBulb;
|
||||||
|
|
||||||
if (!LightBulbContainer.Remove(bulb.Owner)) return;
|
bulb.OnLightBulbStateChange -= UpdateLight;
|
||||||
|
bulb.OnLightColorChange -= UpdateLight;
|
||||||
|
|
||||||
|
if (!_lightBulbContainer.Remove(bulb.Owner)) return;
|
||||||
|
|
||||||
if (!user.TryGetComponent(out HandsComponent hands)
|
if (!user.TryGetComponent(out HandsComponent hands)
|
||||||
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
||||||
@@ -137,6 +150,7 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
device.Load = Load;
|
device.Load = Load;
|
||||||
sprite.LayerSetState(0, "on");
|
sprite.LayerSetState(0, "on");
|
||||||
light.State = LightState.On;
|
light.State = LightState.On;
|
||||||
|
light.Color = LightBulb.Color;
|
||||||
var time = IoCManager.Resolve<IGameTiming>().CurTime;
|
var time = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||||
if (time > _lastThunk + _thunkDelay)
|
if (time > _lastThunk + _thunkDelay)
|
||||||
{
|
{
|
||||||
@@ -172,11 +186,11 @@ namespace Content.Server.GameObjects.Components.Power
|
|||||||
var device = Owner.GetComponent<PowerDeviceComponent>();
|
var device = Owner.GetComponent<PowerDeviceComponent>();
|
||||||
device.OnPowerStateChanged += UpdateLight;
|
device.OnPowerStateChanged += UpdateLight;
|
||||||
|
|
||||||
LightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner, out var existed);
|
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner, out var existed);
|
||||||
|
|
||||||
if (!existed) // Insert a light tube if there wasn't any.
|
if (!existed) // Insert a light tube if there wasn't any.
|
||||||
{
|
{
|
||||||
LightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightTube"));
|
_lightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightTube"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user