-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description This ports Playing Cards from: Estacao Pirata... Frontier... and GoobStation... More specifically, ports Goob-Station/Goob-Station#1215 and Goob-Station/Goob-Station#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> ![image](https://github.com/user-attachments/assets/66c94a1d-4389-4a65-a547-c11c54efac42) </p> </details> --- # Changelog <!-- You can add an author after the `:cl:` to change the name that appears in the changelog (ex: `:cl: Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> :cl: - add: Playing Cards. You may get one in the Games Vendor or as an item in your loadout. --------- Co-authored-by: VMSolidus <[email protected]>
- Loading branch information
Showing
251 changed files
with
4,949 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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 | ||
{ | ||
[Dependency] private readonly SpriteSystem _spriteSystem = default!; | ||
[Dependency] private readonly CardSpriteSystem _cardSpriteSystem = default!; | ||
/// <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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Linq; | ||
using Content.Shared._EstacaoPirata.Cards.Stack; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client._EstacaoPirata.Cards; | ||
|
||
/// <summary> | ||
/// This handles... | ||
/// </summary> | ||
public sealed class CardSpriteSystem : EntitySystem | ||
{ | ||
/// <inheritdoc/> | ||
public override void Initialize() { } | ||
|
||
public bool TryAdjustLayerQuantity(Entity<SpriteComponent, CardStackComponent> uid, int? cardLimit = null) | ||
{ | ||
var sprite = uid.Comp1; | ||
var stack = uid.Comp2; | ||
var cardCount = cardLimit == null ? stack.Cards.Count : Math.Min(stack.Cards.Count, cardLimit.Value); | ||
|
||
var layerCount = 0; | ||
//Gets the quantity of layers | ||
var relevantCards = stack.Cards.TakeLast(cardCount).ToList(); | ||
foreach (var card in relevantCards) | ||
{ | ||
if (!TryComp(card, out SpriteComponent? cardSprite)) | ||
return false; | ||
|
||
layerCount += cardSprite.AllLayers.Count(); | ||
} | ||
layerCount = int.Max(1, layerCount); // Frontier: you need one layer. | ||
//inserts Missing Layers | ||
if (sprite.AllLayers.Count() < layerCount) | ||
for (var i = sprite.AllLayers.Count(); i < layerCount; i++) | ||
sprite.AddBlankLayer(i); | ||
|
||
//Removes extra layers | ||
else if (sprite.AllLayers.Count() > layerCount) | ||
for (var i = sprite.AllLayers.Count() - 1; i >= layerCount; i--) | ||
sprite.RemoveLayer(i); | ||
|
||
return true; | ||
} | ||
|
||
public bool TryHandleLayerConfiguration(Entity<SpriteComponent, CardStackComponent> uid, int cardCount, Func<Entity<SpriteComponent>, int, int, bool> layerFunc) | ||
{ | ||
var sprite = uid.Comp1; | ||
var stack = uid.Comp2; | ||
|
||
// int = index of what card it is from | ||
List<(int, ISpriteLayer)> layers = []; | ||
|
||
var i = 0; | ||
var cards = stack.Cards.TakeLast(cardCount).ToList(); | ||
foreach (var card in cards) | ||
{ | ||
if (!TryComp(card, out SpriteComponent? cardSprite)) | ||
return false; | ||
layers.AddRange(cardSprite.AllLayers.Select(layer => (i, layer))); | ||
i++; | ||
} | ||
|
||
var j = 0; | ||
foreach (var obj in layers) | ||
{ | ||
var (cardIndex, layer) = obj; | ||
sprite.LayerSetVisible(j, true); | ||
sprite.LayerSetTexture(j, layer.Texture); | ||
sprite.LayerSetState(j, layer.RsiState.Name); | ||
layerFunc.Invoke((uid, sprite), cardIndex, j); | ||
j++; | ||
} | ||
|
||
return true; | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
Content.Client/_EstacaoPirata/Cards/Deck/CardDeckSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System.Linq; | ||
using System.Numerics; | ||
using Content.Shared._EstacaoPirata.Cards.Deck; | ||
using Content.Shared._EstacaoPirata.Cards.Stack; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client._EstacaoPirata.Cards.Deck; | ||
|
||
/// <summary> | ||
/// This handles... | ||
/// </summary> | ||
public sealed class CardDeckSystem : EntitySystem | ||
{ | ||
private readonly Dictionary<Entity<CardDeckComponent>, int> _notInitialized = []; | ||
[Dependency] private readonly CardSpriteSystem _cardSpriteSystem = default!; | ||
|
||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
UpdatesOutsidePrediction = false; | ||
SubscribeLocalEvent<CardDeckComponent, ComponentStartup>(OnComponentStartupEvent); | ||
SubscribeNetworkEvent<CardStackInitiatedEvent>(OnStackStart); | ||
SubscribeNetworkEvent<CardStackQuantityChangeEvent>(OnStackUpdate); | ||
SubscribeNetworkEvent<CardStackReorderedEvent>(OnReorder); | ||
SubscribeNetworkEvent<CardStackFlippedEvent>(OnStackFlip); | ||
SubscribeLocalEvent<CardDeckComponent, AppearanceChangeEvent>(OnAppearanceChanged); | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
// Lazy way to make sure the sprite starts correctly | ||
foreach (var kv in _notInitialized) | ||
{ | ||
var ent = kv.Key; | ||
|
||
if (kv.Value >= 5) | ||
{ | ||
_notInitialized.Remove(ent); | ||
continue; | ||
} | ||
|
||
_notInitialized[ent] = kv.Value + 1; | ||
|
||
if (!TryComp(ent.Owner, out CardStackComponent? stack) || stack.Cards.Count <= 0) | ||
continue; | ||
|
||
|
||
// If the card was STILL not initialized, we skip it | ||
if (!TryGetCardLayer(stack.Cards.Last(), out var _)) | ||
continue; | ||
|
||
// If cards were correctly initialized, we update the sprite | ||
UpdateSprite(ent.Owner, ent.Comp); | ||
_notInitialized.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, CardDeckComponent 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) | ||
{ | ||
_notInitialized[(uid, comp)] = 0; | ||
return; | ||
} | ||
|
||
_cardSpriteSystem.TryAdjustLayerQuantity((uid, sprite, cardStack), comp.CardLimit); | ||
|
||
_cardSpriteSystem.TryHandleLayerConfiguration( | ||
(uid, sprite, cardStack), | ||
comp.CardLimit, | ||
(_, cardIndex, layerIndex) => | ||
{ | ||
sprite.LayerSetRotation(layerIndex, Angle.FromDegrees(90)); | ||
sprite.LayerSetOffset(layerIndex, new Vector2(0, (comp.YOffset * cardIndex))); | ||
sprite.LayerSetScale(layerIndex, new Vector2(comp.Scale, comp.Scale)); | ||
return true; | ||
} | ||
); | ||
} | ||
|
||
private void OnStackUpdate(CardStackQuantityChangeEvent args) | ||
{ | ||
if (!TryComp(GetEntity(args.Stack), out CardDeckComponent? comp)) | ||
return; | ||
UpdateSprite(GetEntity(args.Stack), comp); | ||
} | ||
|
||
private void OnStackFlip(CardStackFlippedEvent args) | ||
{ | ||
if (!TryComp(GetEntity(args.CardStack), out CardDeckComponent? comp)) | ||
return; | ||
UpdateSprite(GetEntity(args.CardStack), comp); | ||
} | ||
|
||
private void OnReorder(CardStackReorderedEvent args) | ||
{ | ||
if (!TryComp(GetEntity(args.Stack), out CardDeckComponent? comp)) | ||
return; | ||
UpdateSprite(GetEntity(args.Stack), comp); | ||
} | ||
|
||
private void OnAppearanceChanged(EntityUid uid, CardDeckComponent comp, AppearanceChangeEvent args) | ||
{ | ||
UpdateSprite(uid, comp); | ||
} | ||
private void OnComponentStartupEvent(EntityUid uid, CardDeckComponent comp, ComponentStartup args) | ||
{ | ||
if (!TryComp(uid, out CardStackComponent? stack)) | ||
{ | ||
_notInitialized[(uid, comp)] = 0; | ||
return; | ||
} | ||
|
||
if(stack.Cards.Count <= 0) | ||
_notInitialized[(uid, comp)] = 0; | ||
UpdateSprite(uid, comp); | ||
} | ||
|
||
|
||
private void OnStackStart(CardStackInitiatedEvent args) | ||
{ | ||
var entity = GetEntity(args.CardStack); | ||
if (!TryComp(entity, out CardDeckComponent? comp)) | ||
return; | ||
|
||
UpdateSprite(entity, comp); | ||
} | ||
|
||
} |
Oops, something went wrong.