Allow items spawned in the smart fridge to show up as an entry. (#42268)

* Allow items spawned in the smart fridge to show up in the view

* AAAAAAAAAAAAAAAAAA

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2026-01-08 16:35:39 -08:00
committed by GitHub
parent b406193372
commit 8ec4669bf9
5 changed files with 53 additions and 37 deletions

View File

@@ -0,0 +1,18 @@
using Content.Shared.SmartFridge;
namespace Content.Client.SmartFridge;
public sealed class SmartFridgeSystem : SharedSmartFridgeSystem
{
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
protected override void UpdateUI(Entity<SmartFridgeComponent> ent)
{
base.UpdateUI(ent);
if (!_uiSystem.TryGetOpenUi<SmartFridgeBoundUserInterface>(ent.Owner, SmartFridgeUiKey.Key, out var bui))
return;
bui.Refresh();
}
}

View File

@@ -1,24 +0,0 @@
using Content.Shared.SmartFridge;
using Robust.Shared.Analyzers;
namespace Content.Client.SmartFridge;
public sealed class SmartFridgeUISystem : EntitySystem
{
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SmartFridgeComponent, AfterAutoHandleStateEvent>(OnSmartFridgeAfterState);
}
private void OnSmartFridgeAfterState(Entity<SmartFridgeComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!_uiSystem.TryGetOpenUi<SmartFridgeBoundUserInterface>(ent.Owner, SmartFridgeUiKey.Key, out var bui))
return;
bui.Refresh();
}
}

View File

@@ -0,0 +1,5 @@
using Content.Shared.SmartFridge;
namespace Content.Server.SmartFridge;
public sealed class SmartFridgeSystem : SharedSmartFridgeSystem;

View File

@@ -14,7 +14,7 @@ using Robust.Shared.Utility;
namespace Content.Shared.SmartFridge;
public sealed class SmartFridgeSystem : EntitySystem
public abstract class SharedSmartFridgeSystem : EntitySystem
{
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
@@ -29,7 +29,9 @@ public sealed class SmartFridgeSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<SmartFridgeComponent, InteractUsingEvent>(OnInteractUsing, after: [typeof(AnchorableSystem)]);
SubscribeLocalEvent<SmartFridgeComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<SmartFridgeComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
SubscribeLocalEvent<SmartFridgeComponent, AfterAutoHandleStateEvent>((ent, ref _) => UpdateUI(ent));
SubscribeLocalEvent<SmartFridgeComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerb);
SubscribeLocalEvent<SmartFridgeComponent, GetDumpableVerbEvent>(OnGetDumpableVerb);
@@ -58,16 +60,6 @@ public sealed class SmartFridgeSystem : EntitySystem
anyInserted = true;
_container.Insert(used, container);
var key = new SmartFridgeEntry(Identity.Name(used, EntityManager));
if (!ent.Comp.Entries.Contains(key))
ent.Comp.Entries.Add(key);
ent.Comp.ContainedEntries.TryAdd(key, new());
var entries = ent.Comp.ContainedEntries[key];
if (!entries.Contains(GetNetEntity(used)))
entries.Add(GetNetEntity(used));
Dirty(ent);
}
if (anyInserted && playSound)
@@ -86,6 +78,24 @@ public sealed class SmartFridgeSystem : EntitySystem
args.Handled = DoInsert(ent, args.User, [args.Used], true);
}
private void OnItemInserted(Entity<SmartFridgeComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (args.Container.ID != ent.Comp.Container || _timing.ApplyingState)
return;
var key = new SmartFridgeEntry(Identity.Name(args.Entity, EntityManager));
if (!ent.Comp.Entries.Contains(key))
ent.Comp.Entries.Add(key);
ent.Comp.ContainedEntries.TryAdd(key, new());
var entries = ent.Comp.ContainedEntries[key];
if (!entries.Contains(GetNetEntity(args.Entity)))
entries.Add(GetNetEntity(args.Entity));
Dirty(ent);
UpdateUI(ent);
}
private void OnItemRemoved(Entity<SmartFridgeComponent> ent, ref EntRemovedFromContainerMessage args)
{
var key = new SmartFridgeEntry(Identity.Name(args.Entity, EntityManager));
@@ -96,6 +106,7 @@ public sealed class SmartFridgeSystem : EntitySystem
}
Dirty(ent);
UpdateUI(ent);
}
private bool Allowed(Entity<SmartFridgeComponent> machine, EntityUid user)
@@ -131,6 +142,7 @@ public sealed class SmartFridgeSystem : EntitySystem
_audio.PlayPredicted(ent.Comp.SoundVend, ent, args.Actor);
contained.Remove(item);
Dirty(ent);
UpdateUI(ent);
return;
}
@@ -174,4 +186,9 @@ public sealed class SmartFridgeSystem : EntitySystem
DoInsert(ent, args.User, args.DumpQueue, false);
}
protected virtual void UpdateUI(Entity<SmartFridgeComponent> ent)
{
}
}

View File

@@ -9,7 +9,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.SmartFridge;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
[Access(typeof(SmartFridgeSystem))]
[Access(typeof(SharedSmartFridgeSystem))]
public sealed partial class SmartFridgeComponent : Component
{
/// <summary>
@@ -46,7 +46,7 @@ public sealed partial class SmartFridgeComponent : Component
/// A mapping of smart fridge entries to the actual contained contents
/// </summary>
[DataField, AutoNetworkedField]
[Access(typeof(SmartFridgeSystem), Other = AccessPermissions.ReadExecute)]
[Access(typeof(SharedSmartFridgeSystem), Other = AccessPermissions.ReadExecute)]
public Dictionary<SmartFridgeEntry, HashSet<NetEntity>> ContainedEntries = new();
/// <summary>