Stacks now use ComponentHandleState.
This commit is contained in:
@@ -14,9 +14,6 @@ namespace Content.Shared.Stacks
|
||||
public sealed override string Name => "Stack";
|
||||
public sealed override uint? NetID => ContentNetIDs.STACK;
|
||||
|
||||
[DataField("max")]
|
||||
private int _maxCount = 30;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("stackType", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<StackPrototype>))]
|
||||
public string StackTypeId { get; private set; } = string.Empty;
|
||||
@@ -29,19 +26,12 @@ namespace Content.Shared.Stacks
|
||||
[DataField("count")]
|
||||
public int Count { get; set; } = 30;
|
||||
|
||||
[ViewVariables]
|
||||
public int MaxCount
|
||||
{
|
||||
get => _maxCount;
|
||||
private set
|
||||
{
|
||||
if (_maxCount == value)
|
||||
return;
|
||||
|
||||
_maxCount = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Max amount of things that can be in the stack.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("max")]
|
||||
public int MaxCount { get; set; } = 30;
|
||||
|
||||
[ViewVariables]
|
||||
public int AvailableSpace => MaxCount - Count;
|
||||
@@ -50,20 +40,10 @@ namespace Content.Shared.Stacks
|
||||
{
|
||||
return new StackComponentState(Count, MaxCount);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not StackComponentState cast)
|
||||
return;
|
||||
|
||||
// This will change the count and call events.
|
||||
EntitySystem.Get<SharedStackSystem>().SetCount(Owner.Uid, this, cast.Count);
|
||||
MaxCount = cast.MaxCount;
|
||||
}
|
||||
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class StackComponentState : ComponentState
|
||||
public sealed class StackComponentState : ComponentState
|
||||
{
|
||||
public int Count { get; }
|
||||
public int MaxCount { get; }
|
||||
@@ -74,5 +54,4 @@ namespace Content.Shared.Stacks
|
||||
MaxCount = maxCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Shared.Stacks
|
||||
@@ -12,6 +13,7 @@ namespace Content.Shared.Stacks
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedStackComponent, ComponentHandleState>(OnStackHandleState);
|
||||
SubscribeLocalEvent<SharedStackComponent, ComponentStartup>(OnStackStarted);
|
||||
SubscribeLocalEvent<SharedStackComponent, ExaminedEvent>(OnStackExamined);
|
||||
}
|
||||
@@ -60,6 +62,16 @@ namespace Content.Shared.Stacks
|
||||
RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count));
|
||||
}
|
||||
|
||||
private void OnStackHandleState(EntityUid uid, SharedStackComponent component, ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not StackComponentState cast)
|
||||
return;
|
||||
|
||||
// This will change the count and call events.
|
||||
SetCount(uid, component, cast.Count);
|
||||
component.MaxCount = cast.MaxCount;
|
||||
}
|
||||
|
||||
private void OnStackExamined(EntityUid uid, SharedStackComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
|
||||
Reference in New Issue
Block a user