[feat] Custom ghost sprite

This commit is contained in:
rhailrake
2023-05-01 17:32:16 +06:00
committed by Aviu00
parent 413f51d5f5
commit cc985e57be
11 changed files with 259 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
using Content.Server.Ghost.Components;
using Content.Shared.White.CustomGhostSystem;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.White.CustomGhostSpriteSystem;
public sealed class CustomGhostSpriteSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GhostComponent, PlayerAttachedEvent>(OnShit);
}
private void OnShit(EntityUid uid, GhostComponent component, PlayerAttachedEvent args)
{
if(!_playerManager.TryGetSessionByEntity(uid, out var session))
return;
TrySetCustomSprite(uid, session.Name);
}
public void TrySetCustomSprite(EntityUid ghostUid, string ckey)
{
var prototypes = _prototypeManager.EnumeratePrototypes<CustomGhostPrototype>();
foreach (var customGhostPrototype in prototypes)
{
if (string.Equals(customGhostPrototype.Ckey, ckey, StringComparison.CurrentCultureIgnoreCase))
{
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.Sprite, customGhostPrototype.CustomSpritePath.ToString());
if(customGhostPrototype.AlphaOverride > 0)
{
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.AlphaOverride, customGhostPrototype.AlphaOverride);
}
if (customGhostPrototype.GhostName != string.Empty)
{
MetaData(ghostUid).EntityName = customGhostPrototype.GhostName;
}
if (customGhostPrototype.GhostDescription != string.Empty)
{
MetaData(ghostUid).EntityDescription = customGhostPrototype.GhostDescription;
}
return;
}
}
}
}