// SPDX-FileCopyrightText: 2025 GoobBot // SPDX-FileCopyrightText: 2025 deltanedas <@deltanedas:kde.org> // // SPDX-License-Identifier: AGPL-3.0-or-later using Content.Shared._Goobstation.Factory.Filters; using Content.Shared.DeviceLinking; using Content.Shared.Whitelist; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared._Goobstation.Factory.Slots; /// /// An abstraction over some way to insert/take an item from a machine. /// [ImplicitDataDefinitionForInheritors] public abstract partial class AutomationSlot { /// /// The input port for this slot, or null if can only be used as an output. /// [DataField] public ProtoId? Input; /// /// The output port for this slot, or null if can only be used as an input. /// [DataField] public ProtoId? Output; /// /// Whitelist that can be used in YML regardless of slot type. /// [DataField] public EntityWhitelist? Whitelist; /// /// Blacklist that can be used in YML regardless of slot type. /// [DataField] public EntityWhitelist? Blacklist; /// /// The automated machine this slot belongs to. /// [ViewVariables] public EntityUid Owner; [Dependency] public readonly IEntityManager EntMan = default!; protected AutomationFilterSystem _filter; protected EntityWhitelistSystem _whitelist; protected SharedDeviceLinkSystem _device; /// /// Initialize the slot after is set. /// System dependencies don't work so inheritors have to call base.Initialize() and then add their systems. /// public virtual void Initialize() { IoCManager.InjectDependencies(this); _filter = EntMan.System(); _whitelist = EntMan.System(); _device = EntMan.System(); } /// /// Try to insert an item into the slot, returning true if it was removed from its previous container. /// Inheritors must override this and use if (!base.Insert(uid, item)) return false; /// public virtual bool Insert(EntityUid item) { return CanInsert(item); } /// /// Check if an item can be inserted into the slot, returning true if it can. /// Inheritors must override this and use if (!base.CanInsert(uid, item)) return false; /// public virtual bool CanInsert(EntityUid item) { return _whitelist.CheckBoth(item, whitelist: Whitelist, blacklist: Blacklist); } /// /// Get an item that can be taken from this slot, which has to match a given filter. /// If there are multiple items, which one returned is arbitrary and should not be relied upon. /// This should be "pure" and not actually modify anything. /// public virtual EntityUid? GetItem(EntityUid? filter) { return null; } /// /// Called to add all of this slot's ports to the machine. /// public virtual void AddPorts() { if (Input is {} input) _device.EnsureSinkPorts(Owner, input); if (Output is {} output) _device.EnsureSourcePorts(Owner, output); } /// /// Called to remove all of this slot's ports from the machine. /// public virtual void RemovePorts() { if (Input is {} input) _device.RemoveSinkPort(Owner, input); if (Output is {} output) _device.RemoveSourcePort(Owner, output); } }