Randomize wirecutter and screwdriver colors.

This commit is contained in:
Pieter-Jan Briers
2020-05-23 02:14:11 +02:00
parent ee47f72508
commit 1cb1bd5a8f
13 changed files with 92 additions and 5 deletions

View File

@@ -0,0 +1,59 @@
using System.Collections.Generic;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components
{
[RegisterComponent]
public class RandomToolColorComponent : Component, IMapInit
{
public override string Name => "RandomToolColor";
private string _selectedColor;
private string _baseState;
private Dictionary<string, Color> _colors;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _selectedColor, "selected", null);
serializer.DataField(ref _baseState, "state", "error");
serializer.DataFieldCached(ref _colors, "colors", new Dictionary<string, Color>());
}
void IMapInit.MapInit()
{
if (_colors == null)
{
return;
}
var random = IoCManager.Resolve<IRobustRandom>();
_selectedColor = random.Pick(_colors.Keys);
UpdateColor();
}
protected override void Startup()
{
base.Startup();
UpdateColor();
}
private void UpdateColor()
{
if (Owner.TryGetComponent(out SpriteComponent spriteComponent) && _colors != null && _selectedColor != null)
{
spriteComponent.LayerSetState(0, _baseState);
spriteComponent.LayerSetColor(0, _colors[_selectedColor]);
}
}
}
}