mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Halfway commit * Finishing commit, maybe? * Fix test, update ringtone UI to look nicer * Fix command, add failsafe * Documentation * Can we just mark ValidatePrototypeId as obsolete please * I'm too tired and my bones hurt * Change uplink code generation method * Move RingerAccessUplinkComponent to Server, because cheat clients could make use of it * Fix uplink implant changes, review changes, repair broken serialization. * cleanup and master merge * forgot the Linq * Linqd * Our store system is pretty goddamn awful wow --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
59 lines
2.5 KiB
C#
59 lines
2.5 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Shared.Store.Components;
|
|
|
|
namespace Content.Shared.Store;
|
|
|
|
/// <summary>
|
|
/// Manages general interactions with a store and different entities,
|
|
/// getting listings for stores, and interfacing with the store UI.
|
|
/// </summary>
|
|
public abstract partial class SharedStoreSystem : EntitySystem
|
|
{
|
|
[Dependency] protected readonly EntityQuery<StoreComponent> StoreQuery = default!;
|
|
[Dependency] protected readonly EntityQuery<RemoteStoreComponent> RemoteStoreQuery = default!;
|
|
|
|
/// <summary>
|
|
/// Attempts to find a store connected to this entity.
|
|
/// First checking for a <see cref="StoreComponent"/> on this entity,
|
|
/// then checking for a <see cref="RemoteStoreComponent"/> to find a remotely connected store.
|
|
/// </summary>
|
|
/// <param name="entity">Entity we're checking for an attached store on</param>
|
|
/// <param name="store">Store entity we're returning.</param>
|
|
/// <returns>True if a store was found.</returns>
|
|
public bool TryGetStore(Entity<RemoteStoreComponent?> entity, [NotNullWhen(true)] out Entity<StoreComponent>? store)
|
|
{
|
|
store = GetStore(entity);
|
|
return store != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to find a store connected to this entity.
|
|
/// First checking for a <see cref="StoreComponent"/> on this entity,
|
|
/// then checking for a <see cref="RemoteStoreComponent"/> to find a remotely connected store.
|
|
/// </summary>
|
|
/// <param name="entity">Entity we're checking for an attached store on</param>
|
|
/// <returns>The store entity and component if found.</returns>
|
|
public Entity<StoreComponent>? GetStore(Entity<RemoteStoreComponent?> entity)
|
|
{
|
|
if (StoreQuery.TryComp(entity, out var storeComp))
|
|
return (entity, storeComp);
|
|
|
|
return GetRemoteStore(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to find a remote store connected to this entity.
|
|
/// Checking for a <see cref="RemoteStoreComponent"/> with an attached store entity.
|
|
/// </summary>
|
|
/// <param name="entity">Entity we're checking for an attached store on</param>
|
|
/// <returns>The store entity and component if found.</returns>
|
|
public Entity<StoreComponent>? GetRemoteStore(Entity<RemoteStoreComponent?> 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;
|
|
}
|
|
}
|