Files
OldThink/Content.Server/White/CustomGhostSpriteSystem/CustomGhostSpriteSystem.cs

69 lines
2.3 KiB
C#
Raw Normal View History

2023-05-01 17:32:16 +06:00
using Content.Server.Ghost.Components;
2024-01-13 12:24:00 +03:00
using Content.Shared.Ghost;
2023-05-01 17:32:16 +06:00
using Content.Shared.White.CustomGhostSystem;
using Robust.Server.GameObjects;
using Robust.Server.Player;
2024-01-13 12:24:00 +03:00
using Robust.Shared.Player;
2023-05-01 17:32:16 +06:00
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!;
2024-01-13 12:24:00 +03:00
[Dependency] private readonly MetaDataSystem _metaData = default!;
2023-05-01 17:32:16 +06:00
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());
2023-05-14 02:35:20 +03:00
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.SizeOverride, customGhostPrototype.SizeOverride);
2023-05-01 17:32:16 +06:00
if(customGhostPrototype.AlphaOverride > 0)
{
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.AlphaOverride, customGhostPrototype.AlphaOverride);
}
if (customGhostPrototype.GhostName != string.Empty)
{
2024-01-13 12:24:00 +03:00
_metaData.SetEntityName(ghostUid, customGhostPrototype.GhostName);
2023-05-01 17:32:16 +06:00
}
if (customGhostPrototype.GhostDescription != string.Empty)
{
2024-01-13 12:24:00 +03:00
_metaData.SetEntityDescription(ghostUid, customGhostPrototype.GhostDescription);
2023-05-01 17:32:16 +06:00
}
2023-05-14 02:35:20 +03:00
2023-05-01 17:32:16 +06:00
return;
}
}
}
}