mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-05-01 04:27:58 +03:00
Removed all unused variables i could find, built and tested on a simple upstart and clicking trough most systems. Change Loc references to localization. <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p> "using Robust.Shared.Prototypes;" to "" "[dependency] private readonly ISpriteComponent" to "" </p> </details> --- No CL this isn't player facing. --------- Co-authored-by: ilmenwe <no@mail.com>
77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System.Linq;
|
|
using Content.Shared._EstacaoPirata.Cards.Card;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._EstacaoPirata.Cards.Card;
|
|
|
|
/// <summary>
|
|
/// This handles...
|
|
/// </summary>
|
|
public sealed class CardSystem : EntitySystem
|
|
{
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<CardComponent, ComponentStartup>(OnComponentStartupEvent);
|
|
SubscribeNetworkEvent<CardFlipUpdatedEvent>(OnFlip);
|
|
}
|
|
|
|
private void OnComponentStartupEvent(EntityUid uid, CardComponent comp, ComponentStartup args)
|
|
{
|
|
if (!TryComp(uid, out SpriteComponent? spriteComponent))
|
|
return;
|
|
|
|
for (var i = 0; i < spriteComponent.AllLayers.Count(); i++)
|
|
{
|
|
//Log.Debug($"Layer {i}");
|
|
if (!spriteComponent.TryGetLayer(i, out var layer) || layer.State.Name == null)
|
|
continue;
|
|
|
|
var rsi = layer.RSI ?? spriteComponent.BaseRSI;
|
|
if (rsi == null)
|
|
continue;
|
|
|
|
//Log.Debug("FOI");
|
|
comp.FrontSprite.Add(new SpriteSpecifier.Rsi(rsi.Path, layer.State.Name));
|
|
}
|
|
|
|
comp.BackSprite ??= comp.FrontSprite;
|
|
DirtyEntity(uid);
|
|
UpdateSprite(uid, comp);
|
|
}
|
|
|
|
private void OnFlip(CardFlipUpdatedEvent args)
|
|
{
|
|
if (!TryComp(GetEntity(args.Card), out CardComponent? comp))
|
|
return;
|
|
UpdateSprite(GetEntity(args.Card), comp);
|
|
}
|
|
|
|
private void UpdateSprite(EntityUid uid, CardComponent comp)
|
|
{
|
|
var newSprite = comp.Flipped ? comp.BackSprite : comp.FrontSprite;
|
|
//if (newSprite == null)
|
|
// return;
|
|
|
|
if (!TryComp(uid, out SpriteComponent? spriteComponent))
|
|
return;
|
|
var layerCount = newSprite.Count();
|
|
|
|
//inserts Missing Layers
|
|
if (spriteComponent.AllLayers.Count() < layerCount)
|
|
for (var i = spriteComponent.AllLayers.Count(); i < layerCount; i++)
|
|
spriteComponent.AddBlankLayer(i);
|
|
//Removes extra layers
|
|
else if (spriteComponent.AllLayers.Count() > layerCount)
|
|
for (var i = spriteComponent.AllLayers.Count() - 1; i >= layerCount; i--)
|
|
spriteComponent.RemoveLayer(i);
|
|
|
|
for (var i = 0; i < newSprite.Count(); i++)
|
|
{
|
|
var layer = newSprite[i];
|
|
spriteComponent.LayerSetSprite(i, layer);
|
|
}
|
|
}
|
|
}
|