перенос общих файлов из папки White в _White

This commit is contained in:
Remuchi
2024-01-28 18:37:24 +07:00
parent 1e4ad59270
commit 3a08b81d53
370 changed files with 805 additions and 812 deletions

View File

@@ -0,0 +1,17 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared._White.ClothingGrant.Components;
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class ClothingGrantComponentComponent : Component
{
[DataField("component", required: true)]
[AlwaysPushInheritance]
public ComponentRegistry Components { get; private set; } = new();
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool IsActive = false;
}

View File

@@ -0,0 +1,16 @@
using Robust.Shared.GameStates;
namespace Content.Shared._White.ClothingGrant.Components
{
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class ClothingGrantTagComponent : Component
{
[DataField("tag", required: true), ViewVariables(VVAccess.ReadWrite)]
public string Tag = "";
[ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool IsActive = false;
}
}

View File

@@ -0,0 +1,96 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
using Robust.Shared.Serialization.Manager;
using Content.Shared.Tag;
using Content.Shared._White.ClothingGrant.Components;
using Robust.Shared.Timing;
namespace Content.Shared._White.ClothingGrant.Systems;
public sealed class ClothingGrantingSystem : EntitySystem
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ClothingGrantComponentComponent, GotEquippedEvent>(OnCompEquip);
SubscribeLocalEvent<ClothingGrantComponentComponent, GotUnequippedEvent>(OnCompUnequip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotEquippedEvent>(OnTagEquip);
SubscribeLocalEvent<ClothingGrantTagComponent, GotUnequippedEvent>(OnTagUnequip);
}
private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent component, GotEquippedEvent args)
{
if (_timing.ApplyingState)
return;
if (!TryComp<ClothingComponent>(uid, out var clothing)) return;
if (!clothing.Slots.HasFlag(args.SlotFlags)) return;
if (component.Components.Count > 8)
{
Logger.Error("Although a component registry supports multiple components, we cannot bookkeep more than 8 component for ClothingGrantComponent at this time.");
return;
}
foreach (var (name, data) in component.Components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
if (HasComp(args.Equipee, newComp.GetType()))
continue;
newComp.Owner = args.Equipee;
var temp = (object) newComp;
_serializationManager.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(args.Equipee, (Component)temp!);
}
component.IsActive = true;
Dirty(component);
}
private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent component, GotUnequippedEvent args)
{
if (!component.IsActive) return;
foreach (var (name, data) in component.Components)
{
var newComp = (Component) _componentFactory.GetComponent(name);
RemComp(args.Equipee, newComp.GetType());
}
component.IsActive = false;
Dirty(component);
}
private void OnTagEquip(EntityUid uid, ClothingGrantTagComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing)) return;
if (!clothing.Slots.HasFlag(args.SlotFlags)) return;
EnsureComp<TagComponent>(args.Equipee);
_tagSystem.AddTag(args.Equipee, component.Tag);
component.IsActive = true;
Dirty(component);
}
private void OnTagUnequip(EntityUid uid, ClothingGrantTagComponent component, GotUnequippedEvent args)
{
if (!component.IsActive) return;
_tagSystem.RemoveTag(args.Equipee, component.Tag);
component.IsActive = false;
Dirty(component);
}
}