fix cigar case visuals (#5570)

* fix cigar

* newline
This commit is contained in:
Leon Friedrich
2021-11-27 19:43:19 +13:00
committed by GitHub
parent 3fa33fc54d
commit 7a843fa830
3 changed files with 27 additions and 46 deletions

View File

@@ -14,7 +14,9 @@ using Content.Shared.Item;
using Content.Shared.Placeable;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Content.Shared.Whitelist;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -41,6 +43,8 @@ namespace Content.Server.Storage.Components
[ComponentReference(typeof(IStorageComponent))]
public class ServerStorageComponent : SharedStorageComponent, IInteractUsing, IUse, IActivate, IStorageComponent, IDestroyAct, IExAct, IAfterInteract
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private const string LoggerName = "Storage";
private Container? _storage;
@@ -86,6 +90,20 @@ namespace Content.Server.Storage.Components
}
}
private void UpdateStorageVisualization()
{
if (!_entityManager.TryGetComponent(OwnerUid, out AppearanceComponent appearance))
return;
bool open = SubscribedSessions.Count != 0;
appearance.SetData(StorageVisuals.Open, open);
appearance.SetData(SharedBagOpenVisuals.BagState, open ? SharedBagState.Open : SharedBagState.Closed);
if (_entityManager.HasComponent<ItemCounterComponent>(OwnerUid))
appearance.SetData(StackVisuals.Hide, !open);
}
private void EnsureInitialCalculated()
{
if (_storageInitialCalculated)
@@ -341,9 +359,10 @@ namespace Content.Server.Storage.Components
session.PlayerStatusChanged += HandlePlayerSessionChangeEvent;
SubscribedSessions.Add(session);
UpdateDoorState();
}
if (SubscribedSessions.Count == 1)
UpdateStorageVisualization();
}
/// <summary>
@@ -360,9 +379,10 @@ namespace Content.Server.Storage.Components
#pragma warning disable 618
SendNetworkMessage(new CloseStorageUIMessage(), session.ConnectedClient);
#pragma warning restore 618
UpdateDoorState();
}
if (SubscribedSessions.Count == 0)
UpdateStorageVisualization();
}
private void HandlePlayerSessionChangeEvent(object? obj, SessionStatusEventArgs sessionStatus)
@@ -375,14 +395,6 @@ namespace Content.Server.Storage.Components
}
}
private void UpdateDoorState()
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(StorageVisuals.Open, SubscribedSessions.Count != 0);
}
}
protected override void Initialize()
{
base.Initialize();
@@ -390,6 +402,7 @@ namespace Content.Server.Storage.Components
// ReSharper disable once StringLiteralTypo
_storage = Owner.EnsureContainer<Container>("storagebase");
_storage.OccludesLight = _occludesLight;
UpdateStorageVisualization();
}
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]