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 BarryNorfolk
parent 04b9645b62
commit 865277156b
6 changed files with 54 additions and 26 deletions

View File

@ -0,0 +1,18 @@
using Content.Shared._DV.SmartFridge;
namespace Content.Client._DV.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._DV.SmartFridge;
using Robust.Shared.Analyzers;
namespace Content.Client._DV.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._DV.SmartFridge;
namespace Content.Server._DV.SmartFridge;
public sealed class SmartFridgeSystem : SharedSmartFridgeSystem;

View File

@ -26,7 +26,7 @@ public sealed class DumpableSystem : EntitySystem
[Dependency] private readonly SharedDisposalUnitSystem _disposalUnitSystem = default!; [Dependency] private readonly SharedDisposalUnitSystem _disposalUnitSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!; [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SmartFridgeSystem _fridge = default!; // DeltaV - ough why do you not use events for this [Dependency] private readonly SharedSmartFridgeSystem _fridge = default!; // DeltaV - ough why do you not use events for this
private EntityQuery<ItemComponent> _itemQuery; private EntityQuery<ItemComponent> _itemQuery;

View File

@ -10,7 +10,7 @@ using Robust.Shared.Timing;
namespace Content.Shared._DV.SmartFridge; namespace Content.Shared._DV.SmartFridge;
public sealed class SmartFridgeSystem : EntitySystem public abstract class SharedSmartFridgeSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly AccessReaderSystem _accessReader = default!;
@ -25,7 +25,9 @@ public sealed class SmartFridgeSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<SmartFridgeComponent, InteractUsingEvent>(OnInteractUsing); SubscribeLocalEvent<SmartFridgeComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<SmartFridgeComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<SmartFridgeComponent, EntRemovedFromContainerMessage>(OnItemRemoved); SubscribeLocalEvent<SmartFridgeComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
SubscribeLocalEvent<SmartFridgeComponent, AfterAutoHandleStateEvent>((ent, ref _) => UpdateUI(ent));
Subs.BuiEvents<SmartFridgeComponent>(SmartFridgeUiKey.Key, Subs.BuiEvents<SmartFridgeComponent>(SmartFridgeUiKey.Key,
sub => sub =>
@ -119,6 +121,24 @@ public sealed class SmartFridgeSystem : EntitySystem
_audio.PlayPredicted(ent.Comp.InsertSound, ent, args.User); _audio.PlayPredicted(ent.Comp.InsertSound, ent, args.User);
} }
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) private void OnItemRemoved(Entity<SmartFridgeComponent> ent, ref EntRemovedFromContainerMessage args)
{ {
var key = new SmartFridgeEntry(Identity.Name(args.Entity, EntityManager)); var key = new SmartFridgeEntry(Identity.Name(args.Entity, EntityManager));
@ -129,6 +149,7 @@ public sealed class SmartFridgeSystem : EntitySystem
} }
Dirty(ent); Dirty(ent);
UpdateUI(ent);
} }
private bool Allowed(Entity<SmartFridgeComponent> machine, EntityUid user) private bool Allowed(Entity<SmartFridgeComponent> machine, EntityUid user)
@ -162,6 +183,7 @@ public sealed class SmartFridgeSystem : EntitySystem
contained.Remove(item); contained.Remove(item);
ent.Comp.EjectEnd = _timing.CurTime + ent.Comp.EjectCooldown; ent.Comp.EjectEnd = _timing.CurTime + ent.Comp.EjectCooldown;
Dirty(ent); Dirty(ent);
UpdateUI(ent);
return; return;
} }
@ -182,4 +204,9 @@ public sealed class SmartFridgeSystem : EntitySystem
ent.Comp.Entries.Remove(args.Entry); ent.Comp.Entries.Remove(args.Entry);
Dirty(ent); Dirty(ent);
} }
protected virtual void UpdateUI(Entity<SmartFridgeComponent> ent)
{
}
} }

View File

@ -10,6 +10,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared._DV.SmartFridge; namespace Content.Shared._DV.SmartFridge;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true), AutoGenerateComponentPause] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true), AutoGenerateComponentPause]
[Access(typeof(SharedSmartFridgeSystem))]
public sealed partial class SmartFridgeComponent : Component public sealed partial class SmartFridgeComponent : Component
{ {
[DataField] [DataField]
@ -28,6 +29,7 @@ public sealed partial class SmartFridgeComponent : Component
public HashSet<SmartFridgeEntry> Entries = new(); public HashSet<SmartFridgeEntry> Entries = new();
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
[Access(typeof(SharedSmartFridgeSystem), Other = AccessPermissions.ReadExecute)]
public Dictionary<SmartFridgeEntry, HashSet<NetEntity>> ContainedEntries = new(); public Dictionary<SmartFridgeEntry, HashSet<NetEntity>> ContainedEntries = new();
[DataField] [DataField]