Added mapped storage for things like crayon belts and tools (#4201)
* Added mapped storage for things like crayon belts and tools * Attempt to get StorageFillEvent to work * Managed to get it working with Visualizer logi * Improved PR and did some light refactoring of components * Update Content.Client/Storage/Visualizers/MappedItemVisualizer.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Removed event, went with stateful ApperanceData * Removed ids in favor of whitelist * Refactor YAML, Moved functionality to Shared and renamed it. * Changed so insert/remove always send full state. * Move logic to component * Fix some issues on MappedVisualizer and few nitpicks - Fix mapped visualizer only doing init or update layers - Fixed naming of systems - Fixed sort of crayons * Forgot to apply Vera's suggestion * Fix the data to be more strict and to avoid unnecessary clearing Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
24
Content.Shared/Storage/ItemCounter/ItemCounterComponent.cs
Normal file
24
Content.Shared/Storage/ItemCounter/ItemCounterComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Storage.ItemCounter
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ItemCounterComponent : Component, ISerializationHooks
|
||||
{
|
||||
public override string Name => "ItemCounter";
|
||||
|
||||
[DataField("mapLayers")] public readonly Dictionary<string, SharedMapLayerData> MapLayers = new();
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
foreach (var (layerName, val) in MapLayers)
|
||||
{
|
||||
val.Layer = layerName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Storage.ItemCounter
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public abstract class SharedItemCounterSystem : EntitySystem
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ItemCounterComponent, ComponentInit>(InitLayers);
|
||||
SubscribeLocalEvent<ItemCounterComponent, EntInsertedIntoContainerMessage>(HandleEntityInsert);
|
||||
SubscribeLocalEvent<ItemCounterComponent, EntRemovedFromContainerMessage>(HandleEntityRemoved);
|
||||
}
|
||||
|
||||
private void InitLayers(EntityUid uid, ItemCounterComponent component, ComponentInit args)
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent))
|
||||
{
|
||||
var list = new List<string>(component.MapLayers.Keys);
|
||||
appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEntityRemoved(EntityUid uid, ItemCounterComponent itemCounter,
|
||||
EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (itemCounter.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent)
|
||||
&& TryGetContainer(args, itemCounter, out var containedLayers))
|
||||
{
|
||||
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEntityInsert(EntityUid uid, ItemCounterComponent itemCounter,
|
||||
EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (itemCounter.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent)
|
||||
&& TryGetContainer(args, itemCounter, out var containedLayers))
|
||||
{
|
||||
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract bool TryGetContainer(ContainerModifiedMessage msg,
|
||||
ItemCounterComponent itemCounter,
|
||||
out IReadOnlyList<string> containedLayers);
|
||||
}
|
||||
}
|
||||
46
Content.Shared/Storage/ItemCounter/SharedMapLayerData.cs
Normal file
46
Content.Shared/Storage/ItemCounter/SharedMapLayerData.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Storage.ItemCounter
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum StorageMapVisuals : sbyte
|
||||
{
|
||||
InitLayers,
|
||||
LayerChanged,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataDefinition]
|
||||
public class SharedMapLayerData
|
||||
{
|
||||
public string Layer = string.Empty;
|
||||
|
||||
[DataField("whitelist", required: true)]
|
||||
public EntityWhitelist Whitelist { get; set; } = new();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class ShowLayerData
|
||||
{
|
||||
public IReadOnlyList<string> QueuedEntities { get; internal set; }
|
||||
|
||||
public ShowLayerData()
|
||||
{
|
||||
QueuedEntities = new List<string>();
|
||||
}
|
||||
|
||||
public ShowLayerData(IReadOnlyList<string> other)
|
||||
{
|
||||
QueuedEntities = other;
|
||||
}
|
||||
|
||||
public ShowLayerData(ShowLayerData other)
|
||||
{
|
||||
QueuedEntities = other.QueuedEntities;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user