Files
crystall-punk-14/Content.Shared/GameObjects/Components/SharedStackComponent.cs

150 lines
3.7 KiB
C#
Raw Normal View History

using System;
2020-01-09 00:27:52 +01:00
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Players;
using Robust.Shared.Reflection;
2020-01-09 00:27:52 +01:00
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
2020-01-09 00:27:52 +01:00
namespace Content.Shared.GameObjects.Components
{
public abstract class SharedStackComponent : Component
{
private const string SerializationCache = "stack";
2020-01-09 00:27:52 +01:00
public sealed override string Name => "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.Writing)
{
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(ICommonSession player)
{
return new StackComponentState(Count, MaxCount);
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (curState is not StackComponentState cast)
{
return;
}
Count = cast.Count;
MaxCount = cast.MaxCount;
}
2020-01-09 00:27:52 +01:00
[Serializable, NetSerializable]
private sealed class StackComponentState : ComponentState
2020-01-09 00:27:52 +01:00
{
public int Count { get; }
public int MaxCount { get; }
public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK)
2020-01-09 00:27:52 +01:00
{
Count = count;
MaxCount = maxCount;
}
}
}
public enum StackType
{
Metal,
Glass,
(Smaller) Construction PR - (IC Construction) (#2575) * Disable Pulling When Buckling an entity * Projectile Improvements If you shoot at a person that is critted now it will only hit if you aim at that person otherwise go "above" him and hit other targets. - Dead people are still unhitable * Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> * Firelock In Progress * Revert "Projectile Improvements" This reverts commit 5821afc798e49e530d4086d7a9ddbe097805fdc4. * Firelock Graph * Revert "Merge branch 'master' into test2" This reverts commit c69661cc7d9dcdc6d8c0dd45770f9eb94b231463, reversing changes made to 5f1de8b8d24cd52190addb3df5617cb1012fd52c. * Bunch of stuff - Metal Rods - Reinforced Glass - SetStackCount Condition - Tables - Lattice * Output2 to FloorTileItemComponent * Plating, Underplating and Tiles (+FloorTile Improvements) * Turf Fixes + APC Electronics * Reinforced Glass In-hand textures * All the fixes * Final Changes * (Hopefully) Last commit * Update Resources/Prototypes/Entities/Constructible/Doors/firelock_frame.yml Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * A Few more things * Edit FirelockComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-11-20 16:58:06 +02:00
ReinforcedGlass,
Plasteel,
Cable,
Wood,
Auto lathe branch (#3284) * My first contribution in a while.Change AddAccent command to be case insensitive (#3112) * got rid of the bottle of nothingness. thought it was an empty bottle. * new correction * Delete SpaceStation14.sln I honestly don't know what happened here. I didn't code those lines. * Revert "Delete SpaceStation14.sln" This reverts commit 68876841dce9c6e2ce9d21996e4caef3512b1385. * new attempt at fixing * Revert "new attempt at fixing" This reverts commit 780f66fda3d66b6d4d086871d0b2ea2f6d4ee004. * Revert "My first contribution in a while.Change AddAccent command to be case insensitive (#3112)" This reverts commit 08041a30365331b82309aedaf2136d7631459887. * Revert "Revert "My first contribution in a while.Change AddAccent command to be case insensitive (#3112)"" This reverts commit b2dc76a6683e8df88188d37a836f9ab9a54287b5. * Revert "Revert "Revert "My first contribution in a while.Change AddAccent command to be case insensitive (#3112)""" This reverts commit 478d2bfe5daf6098d2f5665249ce0f161704dd73. * Revert "Revert "Revert "Revert "My first contribution in a while.Change AddAccent command to be case insensitive (#3112)"""" This reverts commit 23c195143e1e3d05cb5f344329c01754432684a9. * Revert "Revert "Revert "Revert "My first contribution in a while.Change AddAccent command to be case insensitive (#3112)"""" This reverts commit 23c195143e1e3d05cb5f344329c01754432684a9. * still having figured what happened with the sln file * please work * -Added wood as a material. -Made a few changes in the material requirements for some of the recipes. * ok. added a small correction for wood at material_stacks.yml * ok added another correction for misc.yml because for some reason a : just disappeared. * -added plastic as a material, complete with a png (credits: tgstation) -replaced glass with plastic for material requirements for some of the latherecipes * for some reason the shovel was duplicate, being in both botany.yml and in tools.yml. deleted it from tools * ok. one last try. noticed that the sprite path for shovel was weird even though it already has its own sprite at Objects/Tools/shovel.rsi . so I decided to fix the path then move the shovel back to tools.yml while deleting it from botany.yml. maybe that was the problem? * corrected the extra space on the type: material for plastic discovered by Peptide90. * noticed that wood also had a bad icon path. * another attempt * weird. I don't remember messing with the flashlight requirements. * added plastic in the SharedStakedComponent and the meta.json from materials.rsi is back to how it was * hopefully this icon is valid. * small corrections concerning double space. Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
2021-02-23 04:30:50 +02:00
Plastic,
MVCable,
HVCable,
2020-05-24 16:56:19 +00:00
Gold,
Plasma,
Ointment,
Gauze,
Brutepack,
2020-04-22 17:49:42 +02:00
FloorTileSteel,
FloorTileCarpet,
FloorTileWhite,
FloorTileDark,
(Smaller) Construction PR - (IC Construction) (#2575) * Disable Pulling When Buckling an entity * Projectile Improvements If you shoot at a person that is critted now it will only hit if you aim at that person otherwise go "above" him and hit other targets. - Dead people are still unhitable * Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> * Firelock In Progress * Revert "Projectile Improvements" This reverts commit 5821afc798e49e530d4086d7a9ddbe097805fdc4. * Firelock Graph * Revert "Merge branch 'master' into test2" This reverts commit c69661cc7d9dcdc6d8c0dd45770f9eb94b231463, reversing changes made to 5f1de8b8d24cd52190addb3df5617cb1012fd52c. * Bunch of stuff - Metal Rods - Reinforced Glass - SetStackCount Condition - Tables - Lattice * Output2 to FloorTileItemComponent * Plating, Underplating and Tiles (+FloorTile Improvements) * Turf Fixes + APC Electronics * Reinforced Glass In-hand textures * All the fixes * Final Changes * (Hopefully) Last commit * Update Resources/Prototypes/Entities/Constructible/Doors/firelock_frame.yml Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * A Few more things * Edit FirelockComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-11-20 16:58:06 +02:00
FloorTileWood,
MetalRod,
PaperRolling,
CigaretteFilter,
GroundTobacco,
GroundCannabis,
LeavesTobaccoDried,
LeavesCannabisDried
}
2020-01-09 00:27:52 +01:00
}