Move part of stack code to shared.
Meaning that ExposeData is in shared, fixing #809
This commit is contained in:
@@ -3,11 +3,9 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -23,34 +21,19 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
[Dependency] private readonly ISharedNotifyManager _sharedNotifyManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private const string SerializationCache = "stack";
|
||||
private int _count = 50;
|
||||
private int _maxCount = 50;
|
||||
private bool _throwIndividually = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Count
|
||||
public override int Count
|
||||
{
|
||||
get => _count;
|
||||
get => base.Count;
|
||||
set
|
||||
{
|
||||
_count = value;
|
||||
if (_count <= 0)
|
||||
base.Count = value;
|
||||
|
||||
if (Count <= 0)
|
||||
{
|
||||
Owner.Delete();
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public int MaxCount
|
||||
{
|
||||
get => _maxCount;
|
||||
private set
|
||||
{
|
||||
_maxCount = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +48,6 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
public int AvailableSpace => MaxCount - Count;
|
||||
|
||||
[ViewVariables]
|
||||
public object StackType { get; private set; }
|
||||
|
||||
public void Add(int amount)
|
||||
{
|
||||
Count += amount;
|
||||
@@ -91,42 +68,6 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataFieldCached(ref _maxCount, "max", 50);
|
||||
serializer.DataFieldCached(ref _count, "count", MaxCount);
|
||||
|
||||
if (!serializer.Reading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializer.TryGetCacheData(SerializationCache, out object stackType))
|
||||
{
|
||||
StackType = stackType;
|
||||
return;
|
||||
}
|
||||
|
||||
if (serializer.TryReadDataFieldCached("stacktype", out string raw))
|
||||
{
|
||||
var refl = IoCManager.Resolve<IReflectionManager>();
|
||||
if (refl.TryParseEnumReference(raw, out var @enum))
|
||||
{
|
||||
stackType = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
stackType = raw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stackType = Owner.Prototype.ID;
|
||||
}
|
||||
serializer.SetCacheData(SerializationCache, stackType);
|
||||
StackType = stackType;
|
||||
}
|
||||
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.AttackWith.TryGetComponent<StackComponent>(out var stack))
|
||||
@@ -175,20 +116,5 @@ namespace Content.Server.GameObjects.Components.Stack
|
||||
"There is [color=lightgray]1[/color] thing in the stack",
|
||||
"There are [color=lightgray]{0}[/color] things in the stack.", Count, Count));
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new StackComponentState(Count, MaxCount);
|
||||
}
|
||||
}
|
||||
|
||||
public enum StackType
|
||||
{
|
||||
Metal,
|
||||
Glass,
|
||||
Cable,
|
||||
Ointment,
|
||||
Brutepack,
|
||||
FloorTileSteel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user