Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontier Port: Pretty Money #2398

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 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 @@ -44,7 +44,7 @@ public override void SetCount(EntityUid uid, int amount, StackComponent? compone
// TODO PREDICT ENTITY DELETION: This should really just be a normal entity deletion call.
if (component.Count <= 0 && !component.Lingering)
{
Xform.DetachEntity(uid, Transform(uid));
Xform.DetachParentToNull(uid, Transform(uid));
return;
}

Expand All @@ -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.Packaging/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}
10 changes: 9 additions & 1 deletion Content.Shared/Stacks/StackComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class StackComponent : Component
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[DataField("maxCountOverride")]
public int? MaxCountOverride { get; set; }
public int? MaxCountOverride { get; set; }

/// <summary>
/// Set to true to not reduce the count when used.
Expand Down 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
}
47 changes: 28 additions & 19 deletions Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,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 @@ -44,19 +52,20 @@
mask:
- ItemMask
- type: Appearance
- type: CargoSellBlacklist

- type: material
id: Credit
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 @@ -65,7 +74,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 @@ -76,7 +85,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 @@ -87,7 +96,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 @@ -98,7 +107,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 @@ -109,7 +118,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 @@ -120,8 +129,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 @@ -131,8 +140,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 @@ -142,8 +151,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 @@ -153,8 +162,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 @@ -164,7 +173,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
21 changes: 21 additions & 0 deletions Resources/Prototypes/_NF/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- type: entity
parent: SpaceCash
id: SpaceCash15000
suffix: 15000
components:
- type: Icon
sprite: _NF/Objects/Economy/cash.rsi
state: cash_10000
- type: Stack
count: 15000

- type: entity
parent: SpaceCash
id: SpaceCash25000
suffix: 25000
components:
- type: Icon
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
Loading