Move part of stack code to shared.
Meaning that ExposeData is in shared, fixing #809
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface.Stylesheets;
|
||||||
using Content.Client.UserInterface.Stylesheets;
|
|
||||||
using Content.Client.Utility;
|
using Content.Client.Utility;
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
@@ -14,22 +13,20 @@ namespace Content.Client.GameObjects.Components
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class StackComponent : SharedStackComponent, IItemStatus
|
public class StackComponent : SharedStackComponent, IItemStatus
|
||||||
{
|
{
|
||||||
[ViewVariables] public int Count { get; private set; }
|
|
||||||
[ViewVariables] public int MaxCount { get; private set; }
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
||||||
|
|
||||||
public Control MakeControl() => new StatusControl(this);
|
public Control MakeControl() => new StatusControl(this);
|
||||||
|
|
||||||
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
public override int Count
|
||||||
{
|
{
|
||||||
if (!(curState is StackComponentState cast))
|
get => base.Count;
|
||||||
return;
|
set
|
||||||
|
{
|
||||||
|
base.Count = value;
|
||||||
|
|
||||||
Count = cast.Count;
|
|
||||||
MaxCount = cast.MaxCount;
|
|
||||||
_uiUpdateNeeded = true;
|
_uiUpdateNeeded = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class StatusControl : Control
|
private sealed class StatusControl : Control
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components.Stack;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Shared.Construction;
|
using Content.Shared.Construction;
|
||||||
|
using Content.Shared.GameObjects.Components;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
@@ -14,7 +15,6 @@ using Robust.Shared.Interfaces.GameObjects.Components;
|
|||||||
using Robust.Shared.Interfaces.Random;
|
using Robust.Shared.Interfaces.Random;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using static Content.Shared.Construction.ConstructionStepMaterial;
|
using static Content.Shared.Construction.ConstructionStepMaterial;
|
||||||
using static Content.Shared.Construction.ConstructionStepTool;
|
using static Content.Shared.Construction.ConstructionStepTool;
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ using Content.Server.GameObjects.EntitySystems;
|
|||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Content.Shared.Interfaces;
|
using Content.Shared.Interfaces;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Reflection;
|
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
using Robust.Shared.Timers;
|
using Robust.Shared.Timers;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
@@ -23,34 +21,19 @@ namespace Content.Server.GameObjects.Components.Stack
|
|||||||
[Dependency] private readonly ISharedNotifyManager _sharedNotifyManager;
|
[Dependency] private readonly ISharedNotifyManager _sharedNotifyManager;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private const string SerializationCache = "stack";
|
|
||||||
private int _count = 50;
|
|
||||||
private int _maxCount = 50;
|
|
||||||
private bool _throwIndividually = false;
|
private bool _throwIndividually = false;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
public override int Count
|
||||||
public int Count
|
|
||||||
{
|
{
|
||||||
get => _count;
|
get => base.Count;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_count = value;
|
base.Count = value;
|
||||||
if (_count <= 0)
|
|
||||||
|
if (Count <= 0)
|
||||||
{
|
{
|
||||||
Owner.Delete();
|
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)
|
public void Add(int amount)
|
||||||
{
|
{
|
||||||
Count += amount;
|
Count += amount;
|
||||||
@@ -91,42 +68,6 @@ namespace Content.Server.GameObjects.Components.Stack
|
|||||||
return false;
|
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)
|
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (eventArgs.AttackWith.TryGetComponent<StackComponent>(out var stack))
|
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 is [color=lightgray]1[/color] thing in the stack",
|
||||||
"There are [color=lightgray]{0}[/color] things in the stack.", Count, Count));
|
"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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,109 @@
|
|||||||
using System;
|
using System;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Reflection;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.Components
|
namespace Content.Shared.GameObjects.Components
|
||||||
{
|
{
|
||||||
public abstract class SharedStackComponent : Component
|
public abstract class SharedStackComponent : Component
|
||||||
{
|
{
|
||||||
|
private const string SerializationCache = "stack";
|
||||||
|
|
||||||
public sealed override string Name => "Stack";
|
public sealed override string Name => "Stack";
|
||||||
public sealed override uint? NetID => ContentNetIDs.STACK;
|
public sealed override uint? NetID => ContentNetIDs.STACK;
|
||||||
|
|
||||||
|
private int _count;
|
||||||
|
private int _maxCount;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public virtual int Count
|
||||||
|
{
|
||||||
|
get => _count;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_count = value;
|
||||||
|
if (_count <= 0)
|
||||||
|
{
|
||||||
|
Owner.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public int MaxCount
|
||||||
|
{
|
||||||
|
get => _maxCount;
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
_maxCount = value;
|
||||||
|
Dirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ViewVariables] public int AvailableSpace => MaxCount - Count;
|
||||||
|
|
||||||
|
[ViewVariables] public object StackType { get; private set; }
|
||||||
|
|
||||||
|
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 override ComponentState GetComponentState()
|
||||||
|
{
|
||||||
|
return new StackComponentState(Count, MaxCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
||||||
|
{
|
||||||
|
if (!(curState is StackComponentState cast))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Count = cast.Count;
|
||||||
|
MaxCount = cast.MaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
protected sealed class StackComponentState : ComponentState
|
private sealed class StackComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public int Count { get; }
|
public int Count { get; }
|
||||||
public int MaxCount { get; }
|
public int MaxCount { get; }
|
||||||
@@ -22,4 +115,14 @@ namespace Content.Shared.GameObjects.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum StackType
|
||||||
|
{
|
||||||
|
Metal,
|
||||||
|
Glass,
|
||||||
|
Cable,
|
||||||
|
Ointment,
|
||||||
|
Brutepack,
|
||||||
|
FloorTileSteel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user