using System.Diagnostics.CodeAnalysis;
using Content.Shared.Store.Components;
namespace Content.Shared.Store;
///
/// Manages general interactions with a store and different entities,
/// getting listings for stores, and interfacing with the store UI.
///
public abstract partial class SharedStoreSystem : EntitySystem
{
[Dependency] protected readonly EntityQuery StoreQuery = default!;
[Dependency] protected readonly EntityQuery RemoteStoreQuery = default!;
///
/// Attempts to find a store connected to this entity.
/// First checking for a on this entity,
/// then checking for a to find a remotely connected store.
///
/// Entity we're checking for an attached store on
/// Store entity we're returning.
/// True if a store was found.
public bool TryGetStore(Entity entity, [NotNullWhen(true)] out Entity? store)
{
store = GetStore(entity);
return store != null;
}
///
/// Attempts to find a store connected to this entity.
/// First checking for a on this entity,
/// then checking for a to find a remotely connected store.
///
/// Entity we're checking for an attached store on
/// The store entity and component if found.
public Entity? GetStore(Entity entity)
{
if (StoreQuery.TryComp(entity, out var storeComp))
return (entity, storeComp);
return GetRemoteStore(entity);
}
///
/// Attempts to find a remote store connected to this entity.
/// Checking for a with an attached store entity.
///
/// Entity we're checking for an attached store on
/// The store entity and component if found.
public Entity? GetRemoteStore(Entity entity)
{
if (RemoteStoreQuery.Resolve(entity, ref entity.Comp, false)
&& entity.Comp.Store != null
&& StoreQuery.TryComp(entity.Comp.Store, out var storeComp))
return (entity.Comp.Store.Value, storeComp);
return null;
}
}