Fix StackVisualizer mutating.

This commit is contained in:
Pieter-Jan Briers
2021-02-23 23:28:22 +01:00
parent ec9a31a723
commit 2ec0304072

View File

@@ -15,7 +15,7 @@ namespace Content.Client.GameObjects.Components
/// Visualizer for items that come in stacks and have different appearance
/// depending on the size of the stack. Visualizer can work by switching between different
/// icons in <c>_spriteLayers</c> or if the sprite layers are supposed to be composed as transparent layers.
/// The former behavior is default and the latter behavior can be defined in prototypes.
/// The former behavior is default and the latter behavior can be defined in prototypes.
///
/// <example>
/// <para>To define a Stack Visualizer prototype insert the following
@@ -72,7 +72,7 @@ namespace Content.Client.GameObjects.Components
/// <description>true: they are transparent and thus layered one over another in ascending order first</description>
/// </item>
/// </list>
///
///
/// </summary>
private bool _isComposite;
private ResourcePath? _spritePath;
@@ -108,13 +108,12 @@ namespace Content.Client.GameObjects.Components
&& _spriteLayers.Count > 0
&& entity.TryGetComponent<ISpriteComponent>(out var spriteComponent))
{
_spritePath ??= spriteComponent.BaseRSI!.Path!;
var spritePath = _spritePath ?? spriteComponent.BaseRSI!.Path!;
foreach (var sprite in _spriteLayers)
{
var rsiPath = _spritePath;
spriteComponent.LayerMapReserveBlank(sprite);
spriteComponent.LayerSetSprite(sprite, new SpriteSpecifier.Rsi(rsiPath, sprite));
spriteComponent.LayerSetSprite(sprite, new SpriteSpecifier.Rsi(spritePath, sprite));
spriteComponent.LayerSetVisible(sprite, false);
}
}