Files
tbd-station-14/Content.Shared/Stacks/SharedStackComponent.cs
Acruid 59e5cc5e3c Remove Static Component NetIds (#4247)
* Remove the unnecessary NetID property from ComponentState.

* Remove Component.NetworkSynchronizeExistence.

* Removed Component.NetID.

* Adds component netID automatic generation.

* Removed NetIdAttribute from serverside components with no corresponding clientside registration.

* Completely remove static NetIds.

* Renamed NetIDAttribute to NetworkedComponentAttribute.

* Add GenerateNetIds calls to client and server entry points.
Add test to make sure auto generated NetIds are identical.

* Component changes when rebasing that I am too lazy to rewrite into the branch.

Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
2021-07-12 10:32:10 +02:00

58 lines
1.8 KiB
C#

using System;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Stacks
{
[NetworkedComponent()]
public abstract class SharedStackComponent : Component, ISerializationHooks
{
public sealed override string Name => "Stack";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("stackType", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<StackPrototype>))]
public string StackTypeId { get; private set; } = string.Empty;
/// <summary>
/// Current stack count.
/// Do NOT set this directly, raise the <see cref="StackChangeCountEvent"/> event instead.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("count")]
public int Count { get; set; } = 30;
/// <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;
public override ComponentState GetComponentState(ICommonSession player)
{
return new StackComponentState(Count, MaxCount);
}
}
[Serializable, NetSerializable]
public sealed class StackComponentState : ComponentState
{
public int Count { get; }
public int MaxCount { get; }
public StackComponentState(int count, int maxCount)
{
Count = count;
MaxCount = maxCount;
}
}
}