Stack components are now entirely logicless.

- GetState is handled in SharedStackSystem
- Adds friend attributes to the stack components
This commit is contained in:
Vera Aguilera Puerto
2021-08-30 11:49:09 +02:00
parent f15ed2ba50
commit d1fe278afc
5 changed files with 19 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Players;
@@ -9,7 +10,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Shared.Stacks
{
[NetworkedComponent()]
[NetworkedComponent, Friend(typeof(SharedStackSystem))]
public abstract class SharedStackComponent : Component, ISerializationHooks
{
public sealed override string Name => "Stack";
@@ -20,7 +21,7 @@ namespace Content.Shared.Stacks
/// <summary>
/// Current stack count.
/// Do NOT set this directly, raise the <see cref="StackChangeCountEvent"/> event instead.
/// Do NOT set this directly, use the <see cref="SharedStackSystem.SetCount"/> method instead.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("count")]
@@ -35,11 +36,6 @@ namespace Content.Shared.Stacks
[ViewVariables]
public int AvailableSpace => MaxCount - Count;
public override ComponentState GetComponentState(ICommonSession player)
{
return new StackComponentState(Count, MaxCount);
}
}
[Serializable, NetSerializable]

View File

@@ -13,6 +13,7 @@ namespace Content.Shared.Stacks
{
base.Initialize();
SubscribeLocalEvent<SharedStackComponent, ComponentGetState>(OnStackGetState);
SubscribeLocalEvent<SharedStackComponent, ComponentHandleState>(OnStackHandleState);
SubscribeLocalEvent<SharedStackComponent, ComponentStartup>(OnStackStarted);
SubscribeLocalEvent<SharedStackComponent, ExaminedEvent>(OnStackExamined);
@@ -62,6 +63,11 @@ namespace Content.Shared.Stacks
RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count));
}
private void OnStackGetState(EntityUid uid, SharedStackComponent component, ref ComponentGetState args)
{
args.State = new StackComponentState(component.Count, component.MaxCount);
}
private void OnStackHandleState(EntityUid uid, SharedStackComponent component, ref ComponentHandleState args)
{
if (args.Current is not StackComponentState cast)