* V1 commit * Remove PDA name and unnecessary pda state * Adds PDA to Chameleon backpack & thief toolbox * Change to use AppearanceDataInit * Add basic PDA state to ensure there's always a sprite before AppearanceData can be applied * Revert PDA name (this will be changed to another way later) * Update PDA name updating to new system * Fix yaml, and fix Agent ID chameleon * Updated based on review
111 lines
3.5 KiB
C#
111 lines
3.5 KiB
C#
using System.Linq;
|
|
using Content.Client.PDA;
|
|
using Content.Shared.Clothing.Components;
|
|
using Content.Shared.Clothing.EntitySystems;
|
|
using Content.Shared.Inventory;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Clothing.Systems;
|
|
|
|
// All valid items for chameleon are calculated on client startup and stored in dictionary.
|
|
public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
[Dependency] private readonly IComponentFactory _factory = default!;
|
|
|
|
private static readonly SlotFlags[] IgnoredSlots =
|
|
{
|
|
SlotFlags.All,
|
|
SlotFlags.PREVENTEQUIP,
|
|
SlotFlags.NONE
|
|
};
|
|
private static readonly SlotFlags[] Slots = Enum.GetValues<SlotFlags>().Except(IgnoredSlots).ToArray();
|
|
|
|
private readonly Dictionary<SlotFlags, List<string>> _data = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ChameleonClothingComponent, AfterAutoHandleStateEvent>(HandleState);
|
|
|
|
PrepareAllVariants();
|
|
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnProtoReloaded);
|
|
}
|
|
|
|
private void OnProtoReloaded(PrototypesReloadedEventArgs args)
|
|
{
|
|
if (args.WasModified<EntityPrototype>())
|
|
PrepareAllVariants();
|
|
}
|
|
|
|
private void HandleState(EntityUid uid, ChameleonClothingComponent component, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
UpdateVisuals(uid, component);
|
|
}
|
|
|
|
protected override void UpdateSprite(EntityUid uid, EntityPrototype proto)
|
|
{
|
|
base.UpdateSprite(uid, proto);
|
|
if (TryComp(uid, out SpriteComponent? sprite)
|
|
&& proto.TryGetComponent(out SpriteComponent? otherSprite, _factory))
|
|
{
|
|
sprite.CopyFrom(otherSprite);
|
|
}
|
|
|
|
// Edgecase for PDAs to include visuals when UI is open
|
|
if (TryComp(uid, out PdaBorderColorComponent? borderColor)
|
|
&& proto.TryGetComponent(out PdaBorderColorComponent? otherBorderColor, _factory))
|
|
{
|
|
borderColor.BorderColor = otherBorderColor.BorderColor;
|
|
borderColor.AccentHColor = otherBorderColor.AccentHColor;
|
|
borderColor.AccentVColor = otherBorderColor.AccentVColor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a list of valid chameleon targets for these slots.
|
|
/// </summary>
|
|
public IEnumerable<string> GetValidTargets(SlotFlags slot)
|
|
{
|
|
var set = new HashSet<string>();
|
|
foreach (var availableSlot in _data.Keys)
|
|
{
|
|
if (slot.HasFlag(availableSlot))
|
|
{
|
|
set.UnionWith(_data[availableSlot]);
|
|
}
|
|
}
|
|
return set;
|
|
}
|
|
|
|
private void PrepareAllVariants()
|
|
{
|
|
_data.Clear();
|
|
var prototypes = _proto.EnumeratePrototypes<EntityPrototype>();
|
|
|
|
foreach (var proto in prototypes)
|
|
{
|
|
// check if this is valid clothing
|
|
if (!IsValidTarget(proto))
|
|
continue;
|
|
if (!proto.TryGetComponent(out ClothingComponent? item, _factory))
|
|
continue;
|
|
|
|
// sort item by their slot flags
|
|
// one item can be placed in several buckets
|
|
foreach (var slot in Slots)
|
|
{
|
|
if (!item.Slots.HasFlag(slot))
|
|
continue;
|
|
|
|
if (!_data.ContainsKey(slot))
|
|
{
|
|
_data.Add(slot, new List<string>());
|
|
}
|
|
_data[slot].Add(proto.ID);
|
|
}
|
|
}
|
|
}
|
|
}
|