mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description This ports Playing Cards from: Estacao Pirata... Frontier... and GoobStation... More specifically, ports https://github.com/Goob-Station/Goob-Station/pull/1215 and https://github.com/Goob-Station/Goob-Station/pull/1311 sequentially. In short... - Adds 3 skins of the playing cards: Nanotrasen, Syndicate, and Black. - NT can be obtained as an item in your loadout but is locked behind a command job. - Syndicate can be obtained as a pointless item in the uplink for 1 TC. - Black can be obtained both as an item in your loadout and from the Games Vendor. --- # TODO before review <!-- A list of everything you have to do before this PR is "complete" You probably won't have to complete everything before merging but it's good to leave future references --> - [X] De-namespace all of (_)EstacaoPirata? (not required, it is an EE fork) - [X] **_TO MAINTAINERS/CONTRIBS, NEED YOUR INPUT!!!_**: See `Content.Client/Inventory/StrippableBoundUserInterface.cs:220`'s "DRAFT TODO". Basically its me asking how to involve the thieving trait in the omission of the playing cards in the strip menu. Currently, it does not take into account the trait and simply obscures. (prolly dont take the trait into account, obscure regardless) - [X] Figure out what to do with the Nanotrasen deck variant: should it remain free like the black deck or restricted like the syndicate? Locked behind any command job? (prolly this) - [X] Get media actually filled in --- <!-- 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>  </p> </details> --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 - add: Playing Cards. You may get one in the Games Vendor or as an item in your loadout. --------- Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit 9b5cce20f185d8da3cdddd2fa6cad14ccd38db77)
168 lines
5.5 KiB
C#
168 lines
5.5 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Shared._EstacaoPirata.Cards.Hand;
|
|
using Content.Shared._EstacaoPirata.Cards.Stack;
|
|
using Robust.Client.GameObjects;
|
|
|
|
namespace Content.Client._EstacaoPirata.Cards.Hand;
|
|
|
|
/// <summary>
|
|
/// This handles...
|
|
/// </summary>
|
|
public sealed class CardHandSystem : EntitySystem
|
|
{
|
|
private readonly Dictionary<Entity<CardHandComponent>, int> _notInit = [];
|
|
[Dependency] private readonly CardSpriteSystem _cardSpriteSystem = default!;
|
|
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<CardHandComponent, ComponentStartup>(OnComponentStartupEvent);
|
|
SubscribeNetworkEvent<CardStackInitiatedEvent>(OnStackStart);
|
|
SubscribeNetworkEvent<CardStackQuantityChangeEvent>(OnStackUpdate);
|
|
SubscribeNetworkEvent<CardStackReorderedEvent>(OnStackReorder);
|
|
SubscribeNetworkEvent<CardStackFlippedEvent>(OnStackFlip);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
foreach (var (ent, value) in _notInit)
|
|
{
|
|
if (value >= 5)
|
|
{
|
|
_notInit.Remove(ent);
|
|
continue;
|
|
}
|
|
_notInit[ent] = value + 1;
|
|
if(!TryComp(ent.Owner, out CardStackComponent? stack) || stack.Cards.Count <= 0)
|
|
continue;
|
|
|
|
// If cards were correctly initialized, we update the sprite
|
|
UpdateSprite(ent.Owner, ent.Comp);
|
|
_notInit.Remove(ent);
|
|
}
|
|
}
|
|
|
|
private bool TryGetCardLayer(EntityUid card, out SpriteComponent.Layer? layer)
|
|
{
|
|
layer = null;
|
|
if (!TryComp(card, out SpriteComponent? cardSprite)
|
|
|| !cardSprite.TryGetLayer(0, out var l))
|
|
return false;
|
|
|
|
layer = l;
|
|
return true;
|
|
}
|
|
|
|
private void UpdateSprite(EntityUid uid, CardHandComponent comp)
|
|
{
|
|
if (!TryComp(uid, out SpriteComponent? sprite)
|
|
|| !TryComp(uid, out CardStackComponent? cardStack))
|
|
return;
|
|
|
|
// Prevents error appearing at spawnMenu
|
|
if (cardStack.Cards.Count <= 0 || !TryGetCardLayer(cardStack.Cards.Last(), out var cardlayer) ||
|
|
cardlayer == null)
|
|
{
|
|
_notInit[(uid, comp)] = 0;
|
|
return;
|
|
}
|
|
|
|
_cardSpriteSystem.TryAdjustLayerQuantity((uid, sprite, cardStack), comp.CardLimit);
|
|
|
|
var cardCount = Math.Min(cardStack.Cards.Count, comp.CardLimit);
|
|
|
|
// Frontier: zero/one card case
|
|
if (cardCount <= 0)
|
|
{
|
|
// Placeholder - we need to have a valid sprite.
|
|
sprite.LayerSetVisible(0, true);
|
|
sprite.LayerSetState(0, "singlecard_down_black");
|
|
sprite.LayerSetOffset(0, new Vector2(0f, 0f));
|
|
sprite.LayerSetScale(0, new Vector2(1f, 1f));
|
|
}
|
|
else if (cardCount == 1)
|
|
{
|
|
_cardSpriteSystem.TryHandleLayerConfiguration(
|
|
(uid, sprite, cardStack),
|
|
cardCount,
|
|
(sprt, cardIndex, layerIndex) =>
|
|
{
|
|
sprt.Comp.LayerSetRotation(layerIndex, Angle.FromDegrees(0));
|
|
sprt.Comp.LayerSetOffset(layerIndex, new Vector2(0, 0.10f));
|
|
sprt.Comp.LayerSetScale(layerIndex, new Vector2(comp.Scale, comp.Scale));
|
|
return true;
|
|
}
|
|
);
|
|
}
|
|
else
|
|
{
|
|
var intervalAngle = comp.Angle / (cardCount-1);
|
|
var intervalSize = comp.XOffset / (cardCount - 1);
|
|
|
|
_cardSpriteSystem.TryHandleLayerConfiguration(
|
|
(uid, sprite, cardStack),
|
|
cardCount,
|
|
(sprt, cardIndex, layerIndex) =>
|
|
{
|
|
var angle = (-(comp.Angle/2)) + cardIndex * intervalAngle;
|
|
var x = (-(comp.XOffset / 2)) + cardIndex * intervalSize;
|
|
var y = -(x * x) + 0.10f;
|
|
|
|
sprt.Comp.LayerSetRotation(layerIndex, Angle.FromDegrees(-angle));
|
|
sprt.Comp.LayerSetOffset(layerIndex, new Vector2(x, y));
|
|
sprt.Comp.LayerSetScale(layerIndex, new Vector2(comp.Scale, comp.Scale));
|
|
return true;
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
private void OnStackUpdate(CardStackQuantityChangeEvent args)
|
|
{
|
|
if (!TryComp(GetEntity(args.Stack), out CardHandComponent? comp))
|
|
return;
|
|
UpdateSprite(GetEntity(args.Stack), comp);
|
|
}
|
|
|
|
private void OnStackStart(CardStackInitiatedEvent args)
|
|
{
|
|
var entity = GetEntity(args.CardStack);
|
|
if (!TryComp(entity, out CardHandComponent? comp))
|
|
return;
|
|
|
|
UpdateSprite(entity, comp);
|
|
}
|
|
private void OnComponentStartupEvent(EntityUid uid, CardHandComponent comp, ComponentStartup args)
|
|
{
|
|
if (!TryComp(uid, out CardStackComponent? stack))
|
|
{
|
|
_notInit[(uid, comp)] = 0;
|
|
return;
|
|
}
|
|
if(stack.Cards.Count <= 0)
|
|
_notInit[(uid, comp)] = 0;
|
|
UpdateSprite(uid, comp);
|
|
}
|
|
|
|
// Frontier
|
|
private void OnStackReorder(CardStackReorderedEvent args)
|
|
{
|
|
if (!TryComp(GetEntity(args.Stack), out CardHandComponent? comp))
|
|
return;
|
|
UpdateSprite(GetEntity(args.Stack), comp);
|
|
}
|
|
|
|
private void OnStackFlip(CardStackFlippedEvent args)
|
|
{
|
|
var entity = GetEntity(args.CardStack);
|
|
if (!TryComp(entity, out CardHandComponent? comp))
|
|
return;
|
|
|
|
UpdateSprite(entity, comp);
|
|
}
|
|
}
|