Cigarette ecs (#4495)
* Reorganized Shared.Storage folder * Replace StorageCounter with Item Counter * Change stack visuals setting data * Fix mirrorcult suggestions * Fix items from upstream * Fix type formatting
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Storage.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage that spawns and counts a single item.
|
||||
/// Usually used for things like matchboxes, cigarette packs,
|
||||
/// cigar cases etc.
|
||||
/// </summary>
|
||||
/// <code>
|
||||
/// - type: StorageCounter
|
||||
/// amount: 6 # Note: this field can be omitted
|
||||
/// countTag: Cigarette # Note: field doesn't point to entity Id, but its tag
|
||||
/// </code>
|
||||
[Obsolete("Should be deprecated in favor of SharedItemCounterSystem")]
|
||||
[RegisterComponent]
|
||||
public class StorageCounterComponent : Component, ISerializationHooks
|
||||
{
|
||||
// TODO Convert to EntityWhitelist
|
||||
[DataField("countTag")]
|
||||
private string? _countTag;
|
||||
|
||||
[DataField("amount")]
|
||||
private int? _maxAmount;
|
||||
|
||||
/// <summary>
|
||||
/// Single item storage component usually have an attached StackedVisualizer.
|
||||
/// </summary>
|
||||
[ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default;
|
||||
|
||||
public override string Name => "StorageCounter";
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
if (_countTag == null)
|
||||
{
|
||||
Logger.Warning("StorageCounterComponent without a `countTag` is useless");
|
||||
}
|
||||
}
|
||||
|
||||
public void ContainerUpdateAppearance(IContainer container)
|
||||
{
|
||||
if(_appearanceComponent is null)
|
||||
return;
|
||||
|
||||
var actual = Count(container.ContainedEntities);
|
||||
_appearanceComponent.SetData(StackVisuals.Actual, actual);
|
||||
|
||||
if (_maxAmount != null)
|
||||
{
|
||||
_appearanceComponent.SetData(StackVisuals.MaxCount, _maxAmount);
|
||||
}
|
||||
}
|
||||
|
||||
private int Count(IReadOnlyList<IEntity> containerContainedEntities)
|
||||
{
|
||||
var count = 0;
|
||||
if (_countTag != null)
|
||||
{
|
||||
foreach (var entity in containerContainedEntities)
|
||||
{
|
||||
if (entity.HasTag(_countTag))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Storage.ItemCounter;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Storage.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ItemCounterSystem : SharedItemCounterSystem
|
||||
{
|
||||
protected override bool TryGetContainer(ContainerModifiedMessage msg,
|
||||
ItemCounterComponent itemCounter,
|
||||
out IReadOnlyList<string> showLayers)
|
||||
protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
|
||||
{
|
||||
if (msg.Container.Owner.TryGetComponent(out ServerStorageComponent? component))
|
||||
if (!msg.Container.Owner.TryGetComponent(out ServerStorageComponent? component)
|
||||
|| component.StoredEntities == null)
|
||||
{
|
||||
var containedLayers = component.StoredEntities ?? new List<IEntity>();
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemCounter.MapLayers.Values)
|
||||
{
|
||||
foreach (var entity in containedLayers)
|
||||
{
|
||||
if (mapLayerData.Whitelist.IsValid(entity))
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showLayers = list;
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
showLayers = new List<string>();
|
||||
return false;
|
||||
var count = 0;
|
||||
foreach (var entity in component.StoredEntities)
|
||||
{
|
||||
if (itemCounter.Count.IsValid(entity)) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Content.Server/Storage/EntitySystems/ItemMapperSystem.cs
Normal file
43
Content.Server/Storage/EntitySystems/ItemMapperSystem.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Storage.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ItemMapperSystem : SharedItemMapperSystem
|
||||
{
|
||||
protected override bool TryGetLayers(ContainerModifiedMessage msg,
|
||||
ItemMapperComponent itemMapper,
|
||||
out IReadOnlyList<string> showLayers)
|
||||
{
|
||||
if (msg.Container.Owner.TryGetComponent(out ServerStorageComponent? component))
|
||||
{
|
||||
var containedLayers = component.StoredEntities ?? new List<IEntity>();
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemMapper.MapLayers.Values)
|
||||
{
|
||||
foreach (var entity in containedLayers)
|
||||
{
|
||||
if (mapLayerData.Whitelist.IsValid(entity))
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showLayers = list;
|
||||
return true;
|
||||
}
|
||||
|
||||
showLayers = new List<string>();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,11 +39,6 @@ namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
storageComp.HandleEntityMaybeRemoved(message);
|
||||
}
|
||||
|
||||
if (oldParentEntity.TryGetComponent<StorageCounterComponent>(out var newStorageComp))
|
||||
{
|
||||
newStorageComp.ContainerUpdateAppearance(message.Container);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleEntityInsertedIntoContainer(EntInsertedIntoContainerMessage message)
|
||||
@@ -54,11 +49,6 @@ namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
storageComp.HandleEntityMaybeInserted(message);
|
||||
}
|
||||
|
||||
if (oldParentEntity.TryGetComponent<StorageCounterComponent>(out var newStorageComp))
|
||||
{
|
||||
newStorageComp.ContainerUpdateAppearance(message.Container);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckSubscribedEntities(ServerStorageComponent storageComp)
|
||||
|
||||
Reference in New Issue
Block a user