Skip to content

Commit

Permalink
Multicoloured spesos: add layer function in StackComponent (new-front…
Browse files Browse the repository at this point in the history
…iers-14#1496)

* Show amount of spesos in a stack properly

* Refactor stack functions

* Larger cash denominations, Frontier cash sprites

* Modify Frontier cash.rsi copyright

* Remove 500k cash file

* cash.rsi: center cash_100k, fix name in meta.json

* Cash: all bills scroll left (easy to read)

* Recolour 10-100k bills, adjust order of 250k

* ThresholdStackLayerFunction: comment inaccuracy

* fix space_cash.yml icons

* Stack cleanup

* StackSystem: cleanup

* Rename stack threshold component
  • Loading branch information
whatston3 authored Jun 14, 2024
1 parent 113f236 commit b946f57
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 31 deletions.
21 changes: 13 additions & 8 deletions Content.Client/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Content.Client.Stack
{
[UsedImplicitly]
public sealed class StackSystem : SharedStackSystem
public sealed partial class StackSystem : SharedStackSystem // Frontier: add partial to class definition
{
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly ItemCounterSystem _counterSystem = default!;
Expand Down Expand Up @@ -56,20 +56,25 @@ private void OnAppearanceChange(EntityUid uid, StackComponent comp, ref Appearan
if (args.Sprite == null || comp.LayerStates.Count < 1)
return;

StackLayerData data = new StackLayerData(); // Frontier: use structure to store StackLayerData

// Skip processing if no actual
if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.Actual, out var actual, args.Component))
if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.Actual, out data.Actual, args.Component))
return;

if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.MaxCount, out var maxCount, args.Component))
maxCount = comp.LayerStates.Count;
if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.MaxCount, out data.MaxCount, args.Component))
data.MaxCount = comp.LayerStates.Count;

if (!_appearanceSystem.TryGetData<bool>(uid, StackVisuals.Hide, out data.Hidden, args.Component))
data.Hidden = false;

if (!_appearanceSystem.TryGetData<bool>(uid, StackVisuals.Hide, out var hidden, args.Component))
hidden = false;
if (comp.LayerFunction != StackLayerFunction.None) // Frontier: use stack layer function to modify appearance if provided.
ApplyLayerFunction(uid, comp, ref data); // Frontier: definition in _NF/Stack/StackSystem.Layers.cs

if (comp.IsComposite)
_counterSystem.ProcessCompositeSprite(uid, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
_counterSystem.ProcessCompositeSprite(uid, data.Actual, data.MaxCount, comp.LayerStates, data.Hidden, sprite: args.Sprite);
else
_counterSystem.ProcessOpaqueSprite(uid, comp.BaseLayer, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
_counterSystem.ProcessOpaqueSprite(uid, comp.BaseLayer, data.Actual, data.MaxCount, comp.LayerStates, data.Hidden, sprite: args.Sprite);
}
}
}
56 changes: 56 additions & 0 deletions Content.Client/_NF/Stack/StackSystem.Layers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Shared.Stacks.Components;
using Content.Shared.Stacks;

namespace Content.Client.Stack
{
/// <summary>
/// Data used to determine which layers of a stack's sprite are visible.
/// </summary>
public struct StackLayerData
{
public int Actual;
public int MaxCount;
public bool Hidden;
}

public sealed partial class StackSystem : SharedStackSystem
{
// Modifies a given stack component to adjust the layers to display.
private bool ApplyLayerFunction(EntityUid uid, StackComponent comp, ref StackLayerData data)
{
switch (comp.LayerFunction)
{
case StackLayerFunction.Threshold:
if (TryComp<StackLayerThresholdComponent>(uid, out var threshold))
{
ApplyThreshold(threshold, ref data);
return true;
}
break;
}
// No function applied.
return false;
}

/// <summary>
/// Sets Actual to the number of thresholds that Actual exceeds from the beginning of the list.
/// Sets MaxCount to the total number of thresholds plus one (for values under thresholds).
/// </summary>
private static void ApplyThreshold(StackLayerThresholdComponent comp, ref StackLayerData data)
{
// We must stop before we run out of thresholds or layers, whichever's smaller.
data.MaxCount = Math.Min(comp.Thresholds.Count + 1, data.MaxCount);
int newActual = 0;
foreach (var threshold in comp.Thresholds)
{
//If our value exceeds threshold, the next layer should be displayed.
//Note: we must ensure actual <= MaxCount.
if (data.Actual >= threshold && newActual < data.MaxCount)
newActual++;
else
break;
}
data.Actual = newActual;
}
}
}
8 changes: 8 additions & 0 deletions Content.Shared/Stacks/StackComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public sealed partial class StackComponent : Component
[DataField("layerStates")]
[ViewVariables(VVAccess.ReadWrite)]
public List<string> LayerStates = new();

// Frontier: transforming Amount, MaxCount in speso stacks
/// <summary>
/// An optional function to adjust the layers used for a stack's appearance.
/// </summary>
[DataField]
public StackLayerFunction LayerFunction = StackLayerFunction.None;
// End Frontier
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Shared.Stacks.Components;

[RegisterComponent]
public sealed partial class StackLayerThresholdComponent : Component
{
/// <summary>
/// A list of thresholds to check against the number of things in the stack.
/// Each exceeded threshold will cause the next layer to be displayed.
/// Should be sorted in ascending order.
/// </summary>
[DataField(required: true)]
public List<int> Thresholds = new List<int>();
}
7 changes: 7 additions & 0 deletions Content.Shared/_NF/Stacks/StackLayerFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Shared.Stacks;

public enum StackLayerFunction
{
None,
Threshold
}
46 changes: 27 additions & 19 deletions Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@
- cash_100
- cash_500
- cash_1000
- cash_1000000
- cash_5000 # Frontier: larger denominations
- cash_10000 # Frontier: larger denominations
- cash_25000 # Frontier: larger denominations
- cash_50000 # Frontier: larger denominations
- cash_100000 # Frontier: larger denominations
- cash_250000 # Frontier: larger denominations (cash_1000000<cash_250000)
layerFunction: Threshold # Frontier: multicolour cash
- type: StackLayerThreshold # Frontier
thresholds: [10, 100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000] # Frontier
- type: Sprite
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: larger denominations
state: cash
layers:
- state: cash
Expand All @@ -54,13 +62,13 @@
name: speso
unit: materials-unit-bill
stackEntity: SpaceCash
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
icon: { sprite: _NF/Objects/Economy/cash.rsi, state: cash } # Frontier: use Frontier sprite set
price: 1

- type: stack
id: Credit
name: speso
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
icon: { sprite: _NF/Objects/Economy/cash.rsi, state: cash } # Frontier: use Frontier sprite set
spawn: SpaceCash

- type: entity
Expand All @@ -69,7 +77,7 @@
suffix: 10
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_10
- type: Stack
count: 10
Expand All @@ -80,7 +88,7 @@
suffix: 100
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_100
- type: Stack
count: 100
Expand All @@ -91,7 +99,7 @@
suffix: 500
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_500
- type: Stack
count: 500
Expand All @@ -102,7 +110,7 @@
suffix: 1000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_1000
- type: Stack
count: 1000
Expand All @@ -113,7 +121,7 @@
suffix: 2500
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_1000
- type: Stack
count: 2500
Expand All @@ -124,8 +132,8 @@
suffix: 5000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_5000 # Frontier: cash_1000<cash_5000
- type: Stack
count: 5000

Expand All @@ -135,8 +143,8 @@
suffix: 10000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_10000 # Frontier: cash_1000<cash_10000
- type: Stack
count: 10000

Expand All @@ -146,8 +154,8 @@
suffix: 20000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_10000 # Frontier: cash_1000<cash_10000
- type: Stack
count: 20000

Expand All @@ -157,8 +165,8 @@
suffix: 30000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_25000 # Frontier: cash_1000<cash_25000
- type: Stack
count: 30000

Expand All @@ -168,7 +176,7 @@
suffix: 1000000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000000
sprite: _NF/Objects/Economy/cash.rsi # Frontier: use Frontier sprite set
state: cash_250000 # Frontier: cash_1000000<cash_250000
- type: Stack
count: 1000000
8 changes: 4 additions & 4 deletions Resources/Prototypes/_NF/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
suffix: 15000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi
state: cash_10000
- type: Stack
count: 15000

Expand All @@ -15,7 +15,7 @@
suffix: 25000
components:
- type: Icon
sprite: Objects/Economy/cash.rsi
state: cash_1000
sprite: _NF/Objects/Economy/cash.rsi
state: cash_25000
- type: Stack
count: 25000
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b946f57

Please sign in to comment.