More ent storage ref (#19693)

This commit is contained in:
metalgearsloth
2023-08-31 22:29:11 +10:00
committed by GitHub
parent 609bf63893
commit ef5a4ec306
5 changed files with 62 additions and 26 deletions

View File

@@ -3,7 +3,7 @@ using Robust.Shared.GameStates;
namespace Content.Client.Storage.Components; namespace Content.Client.Storage.Components;
[RegisterComponent, ComponentReference(typeof(SharedEntityStorageComponent))] [RegisterComponent]
public sealed partial class EntityStorageComponent : SharedEntityStorageComponent public sealed partial class EntityStorageComponent : SharedEntityStorageComponent
{ {

View File

@@ -1,13 +1,40 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Client.Storage.Components;
using Content.Shared.Destructible;
using Content.Shared.Interaction;
using Content.Shared.Lock;
using Content.Shared.Movement.Events;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems; using Content.Shared.Storage.EntitySystems;
using Content.Shared.Verbs;
using Robust.Shared.GameStates;
namespace Content.Client.Storage.Systems; namespace Content.Client.Storage.Systems;
public sealed class EntityStorageSystem : SharedEntityStorageSystem public sealed class EntityStorageSystem : SharedEntityStorageSystem
{ {
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EntityStorageComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<EntityStorageComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<EntityStorageComponent, ActivateInWorldEvent>(OnInteract, after: new[] { typeof(LockSystem) });
SubscribeLocalEvent<EntityStorageComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
SubscribeLocalEvent<EntityStorageComponent, DestructionEventArgs>(OnDestruction);
SubscribeLocalEvent<EntityStorageComponent, GetVerbsEvent<InteractionVerb>>(AddToggleOpenVerb);
SubscribeLocalEvent<EntityStorageComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
SubscribeLocalEvent<EntityStorageComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<EntityStorageComponent, ComponentHandleState>(OnHandleState);
}
public override bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component) public override bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component)
{ {
return Resolve(uid, ref component); if (component != null)
return true;
TryComp<EntityStorageComponent>(uid, out var storage);
component = storage;
return component != null;
} }
} }

View File

@@ -4,7 +4,7 @@ using Robust.Shared.GameStates;
namespace Content.Server.Storage.Components; namespace Content.Server.Storage.Components;
[RegisterComponent, ComponentReference(typeof(SharedEntityStorageComponent))] [RegisterComponent]
public sealed partial class EntityStorageComponent : SharedEntityStorageComponent, IGasMixtureHolder public sealed partial class EntityStorageComponent : SharedEntityStorageComponent, IGasMixtureHolder
{ {
/// <summary> /// <summary>

View File

@@ -4,9 +4,15 @@ using Content.Server.Construction;
using Content.Server.Construction.Components; using Content.Server.Construction.Components;
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using Content.Server.Tools.Systems; using Content.Server.Tools.Systems;
using Content.Shared.Destructible;
using Content.Shared.Interaction;
using Content.Shared.Lock;
using Content.Shared.Movement.Events;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems; using Content.Shared.Storage.EntitySystems;
using Content.Shared.Verbs;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map; using Robust.Shared.Map;
namespace Content.Server.Storage.EntitySystems; namespace Content.Server.Storage.EntitySystems;
@@ -21,6 +27,19 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem
{ {
base.Initialize(); base.Initialize();
/* CompRef things */
SubscribeLocalEvent<EntityStorageComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<EntityStorageComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<EntityStorageComponent, ActivateInWorldEvent>(OnInteract, after: new[] { typeof(LockSystem) });
SubscribeLocalEvent<EntityStorageComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
SubscribeLocalEvent<EntityStorageComponent, DestructionEventArgs>(OnDestruction);
SubscribeLocalEvent<EntityStorageComponent, GetVerbsEvent<InteractionVerb>>(AddToggleOpenVerb);
SubscribeLocalEvent<EntityStorageComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
SubscribeLocalEvent<EntityStorageComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<EntityStorageComponent, ComponentHandleState>(OnHandleState);
/* CompRef things */
SubscribeLocalEvent<EntityStorageComponent, MapInitEvent>(OnMapInit); SubscribeLocalEvent<EntityStorageComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<EntityStorageComponent, WeldableAttemptEvent>(OnWeldableAttempt); SubscribeLocalEvent<EntityStorageComponent, WeldableAttemptEvent>(OnWeldableAttempt);
SubscribeLocalEvent<EntityStorageComponent, WeldableChangedEvent>(OnWelded); SubscribeLocalEvent<EntityStorageComponent, WeldableChangedEvent>(OnWelded);
@@ -52,7 +71,12 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem
public override bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component) public override bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component)
{ {
return Resolve(uid, ref component); if (component != null)
return true;
TryComp<EntityStorageComponent>(uid, out var storage);
component = storage;
return component != null;
} }
private void OnWeldableAttempt(EntityUid uid, EntityStorageComponent component, WeldableAttemptEvent args) private void OnWeldableAttempt(EntityUid uid, EntityStorageComponent component, WeldableAttemptEvent args)

View File

@@ -43,22 +43,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
public const string ContainerName = "entity_storage"; public const string ContainerName = "entity_storage";
/// <inheritdoc/> protected void OnGetState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentGetState args)
public override void Initialize()
{
SubscribeLocalEvent<SharedEntityStorageComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<SharedEntityStorageComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<SharedEntityStorageComponent, ActivateInWorldEvent>(OnInteract, after: new[] { typeof(LockSystem) });
SubscribeLocalEvent<SharedEntityStorageComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
SubscribeLocalEvent<SharedEntityStorageComponent, DestructionEventArgs>(OnDestruction);
SubscribeLocalEvent<SharedEntityStorageComponent, GetVerbsEvent<InteractionVerb>>(AddToggleOpenVerb);
SubscribeLocalEvent<SharedEntityStorageComponent, ContainerRelayMovementEntityEvent>(OnRelayMovement);
SubscribeLocalEvent<SharedEntityStorageComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<SharedEntityStorageComponent, ComponentHandleState>(OnHandleState);
}
private void OnGetState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentGetState args)
{ {
args.State = new EntityStorageComponentState(component.Open, args.State = new EntityStorageComponentState(component.Open,
component.Capacity, component.Capacity,
@@ -68,7 +53,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
component.IsWeldedShut); component.IsWeldedShut);
} }
private void OnHandleState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentHandleState args) protected void OnHandleState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentHandleState args)
{ {
if (args.Current is not EntityStorageComponentState state) if (args.Current is not EntityStorageComponentState state)
return; return;
@@ -92,7 +77,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
_appearance.SetData(uid, StorageVisuals.Open, component.Open); _appearance.SetData(uid, StorageVisuals.Open, component.Open);
} }
private void OnInteract(EntityUid uid, SharedEntityStorageComponent component, ActivateInWorldEvent args) protected void OnInteract(EntityUid uid, SharedEntityStorageComponent component, ActivateInWorldEvent args)
{ {
if (args.Handled) if (args.Handled)
return; return;
@@ -103,7 +88,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
public abstract bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component); public abstract bool ResolveStorage(EntityUid uid, [NotNullWhen(true)] ref SharedEntityStorageComponent? component);
private void OnLockToggleAttempt(EntityUid uid, SharedEntityStorageComponent target, ref LockToggleAttemptEvent args) protected void OnLockToggleAttempt(EntityUid uid, SharedEntityStorageComponent target, ref LockToggleAttemptEvent args)
{ {
// Cannot (un)lock open lockers. // Cannot (un)lock open lockers.
if (target.Open) if (target.Open)
@@ -114,7 +99,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
args.Cancelled = true; args.Cancelled = true;
} }
private void OnDestruction(EntityUid uid, SharedEntityStorageComponent component, DestructionEventArgs args) protected void OnDestruction(EntityUid uid, SharedEntityStorageComponent component, DestructionEventArgs args)
{ {
component.Open = true; component.Open = true;
Dirty(component); Dirty(component);
@@ -130,7 +115,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
} }
} }
private void OnRelayMovement(EntityUid uid, SharedEntityStorageComponent component, ref ContainerRelayMovementEntityEvent args) protected void OnRelayMovement(EntityUid uid, SharedEntityStorageComponent component, ref ContainerRelayMovementEntityEvent args)
{ {
if (!HasComp<HandsComponent>(args.Entity)) if (!HasComp<HandsComponent>(args.Entity))
return; return;
@@ -145,7 +130,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
} }
} }
private void AddToggleOpenVerb(EntityUid uid, SharedEntityStorageComponent component, GetVerbsEvent<InteractionVerb> args) protected void AddToggleOpenVerb(EntityUid uid, SharedEntityStorageComponent component, GetVerbsEvent<InteractionVerb> args)
{ {
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; return;