ECS AsteroidRock and add a doafter to mining (#6120)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
40
Content.Server/RandomAppearance/RandomAppearanceComponent.cs
Normal file
40
Content.Server/RandomAppearance/RandomAppearanceComponent.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.RandomAppearance;
|
||||
|
||||
[RegisterComponent, ComponentProtoName("RandomAppearance")]
|
||||
[Friend(typeof(RandomAppearanceSystem))]
|
||||
public class RandomAppearanceComponent : Component, ISerializationHooks
|
||||
{
|
||||
[DataField("spriteStates")]
|
||||
public string[] SpriteStates = {"0", "1", "2", "3", "4"};
|
||||
|
||||
/// <summary>
|
||||
/// What appearance enum key should be set to the random sprite state?
|
||||
/// </summary>
|
||||
[DataField("key", required: true)]
|
||||
public string EnumKeyRaw = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The actual enum after reflection.
|
||||
/// </summary>
|
||||
public System.Enum? EnumKey;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if (IoCManager.Resolve<IReflectionManager>().TryParseEnumReference(EnumKeyRaw, out var @enum))
|
||||
{
|
||||
EnumKey = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"RandomAppearance enum key {EnumKeyRaw} could not be parsed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Content.Server/RandomAppearance/RandomAppearanceSystem.cs
Normal file
27
Content.Server/RandomAppearance/RandomAppearanceSystem.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Reflection;
|
||||
|
||||
namespace Content.Server.RandomAppearance;
|
||||
|
||||
public class RandomAppearanceSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RandomAppearanceComponent, ComponentInit>(OnComponentInit);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, RandomAppearanceComponent component, ComponentInit args)
|
||||
{
|
||||
if (TryComp(uid, out AppearanceComponent? appearance) && component.EnumKey != null)
|
||||
{
|
||||
appearance.SetData(component.EnumKey, _random.Pick(component.SpriteStates));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user