Skip to content

Commit

Permalink
Reapply "Не понимаю до сих пор, в чем проблема..."
Browse files Browse the repository at this point in the history
This reverts commit e41e664.
  • Loading branch information
aristophanivan committed Sep 6, 2024
1 parent 3198b34 commit d2f88ff
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 57 deletions.
34 changes: 7 additions & 27 deletions Content.Client/Stories/ChameleonStamp/ChameleonStampSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ public sealed class ChameleonStampSystem : SharedChameleonStampSystem
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IComponentFactory _factory = default!;

private static readonly SlotFlags[] IgnoredSlots =
{
SlotFlags.PREVENTEQUIP,
SlotFlags.NONE
};
private static readonly SlotFlags[] Slots = Enum.GetValues<SlotFlags>().Except(IgnoredSlots).ToArray();

private readonly Dictionary<SlotFlags, List<string>> _data = new();
private readonly List<string> _data = new List<string>();

public override void Initialize()
{
Expand All @@ -47,28 +40,22 @@ private void HandleState(EntityUid uid, ChameleonStampComponent component, ref A
protected override void UpdateSprite(EntityUid uid, EntityPrototype proto)
{
base.UpdateSprite(uid, proto);
Logger.Info($"Обновление спрайта для сущности с UID: {uid}, используя прототип: {proto.ID}");

if (TryComp(uid, out SpriteComponent? sprite)
&& proto.TryGetComponent(out SpriteComponent? otherSprite, _factory))
{
Logger.Info($"Копирование спрайта из другого спрайт-компонента для UID: {uid}");
sprite.CopyFrom(otherSprite);
}
}

public IEnumerable<string> GetValidTargets(SlotFlags slot)
public IEnumerable<string> GetValidTargets()
{
var set = new HashSet<string>();
Logger.Info($"Получение допустимых целей для слота: {slot}");

foreach (var availableSlot in _data.Keys)
foreach (var proto in _data)
{
if (slot.HasFlag(availableSlot))
{
Logger.Info($"Добавление целей для слота: {availableSlot}");
set.UnionWith(_data[availableSlot]);
}
Logger.Info($"Добавление прототипа {proto} в список");
set.UnionWith(_data);
}
return set;
}
Expand All @@ -89,15 +76,8 @@ private void PrepareAllVariants()
{
continue;
}
foreach (var slot in Slots)
{
if (!_data.ContainsKey(slot))
{
_data.Add(slot, new List<string>());
Logger.Info($"Создан новый слот: {slot}");
}
_data[slot].Add(proto.ID);
}
_data.Add(proto.ID);
Logger.Info($"Добавлен прототип {proto.ID}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Content.Client.Stories.ChameleonStamp;
using Content.Shared.Stories.ChameleonStamp;
namespace Content.Client.Stories.ChameleonStamp.UI;

Expand Down Expand Up @@ -38,7 +37,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
return;
}
Logger.Info($"Проверка стейтов пройдена.");
var targets = _chameleon.GetValidTargets(st.Slot);
var targets = _chameleon.GetValidTargets();
_menu?.UpdateState(targets, st.SelectedId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void UpdateUi(EntityUid uid, ChameleonStampComponent? component = null)
if (!Resolve(uid, ref component))
return;

var state = new ChameleonStampBoundUserInterfaceState(component.Slot, component.Default);
var state = new ChameleonStampBoundUserInterfaceState(component.Default);
_uiSystem.SetUiState(uid, ChameleonUiKey.Key, state);
}

Expand Down
11 changes: 1 addition & 10 deletions Content.Shared/Stories/ChameleonStamp/ChameleonStampComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace Content.Shared.Stories.ChameleonStamp;
[Access(typeof(SharedChameleonStampSystem))]
public sealed partial class ChameleonStampComponent : Component
{
/// <summary>
/// Filter possible chameleon options by their slot flag.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[DataField(required: true)]
public SlotFlags Slot = SlotFlags.All;

/// <summary>
/// EntityPrototype id that chameleon item is trying to mimic.
/// </summary>
Expand All @@ -37,12 +30,10 @@ public sealed partial class ChameleonStampComponent : Component
[Serializable, NetSerializable]
public sealed class ChameleonStampBoundUserInterfaceState : BoundUserInterfaceState
{
public readonly SlotFlags Slot;
public readonly string? SelectedId;

public ChameleonStampBoundUserInterfaceState(SlotFlags slot, string? selectedId)
public ChameleonStampBoundUserInterfaceState(string? selectedId)
{
Slot = slot;
SelectedId = selectedId;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,7 @@ protected void UpdateVisuals(EntityUid uid, ChameleonStampComponent component)
// world sprite icon
UpdateSprite(uid, proto);

// copy name and description, unless its an ID card
if (!HasComp<IdCardComponent>(uid))
{
var meta = MetaData(uid);
_metaData.SetEntityName(uid, proto.Name, meta);
_metaData.SetEntityDescription(uid, proto.Description, meta);
}

// item sprite logic
if (TryComp(uid, out ItemComponent? item) &&
proto.TryGetComponent(out ItemComponent? otherItem, _factory))
{
_itemSystem.CopyVisuals(uid, otherItem, item);
}

// clothing sprite logic
// sta sprite logic
if (TryComp(uid, out StampComponent? stamp) &&
proto.TryGetComponent("Stamp", out StampComponent? otherStamp))
{
Expand Down
1 change: 0 additions & 1 deletion Resources/Prototypes/Stories/Entities/Objects/stamps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
components:
- type: ChameleonStamp
default: RubberStampBase
slot: [all]
- type: UserInterface
interfaces:
enum.ChameleonUiKey.Key:
Expand Down

0 comments on commit d2f88ff

Please sign in to comment.