more component ref removal + combining server/client comps (#13178)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -26,30 +26,30 @@ namespace Content.Shared.Stacks
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedStackComponent, ComponentGetState>(OnStackGetState);
|
||||
SubscribeLocalEvent<SharedStackComponent, ComponentHandleState>(OnStackHandleState);
|
||||
SubscribeLocalEvent<SharedStackComponent, ComponentStartup>(OnStackStarted);
|
||||
SubscribeLocalEvent<SharedStackComponent, ExaminedEvent>(OnStackExamined);
|
||||
SubscribeLocalEvent<SharedStackComponent, InteractUsingEvent>(OnStackInteractUsing);
|
||||
SubscribeLocalEvent<StackComponent, ComponentGetState>(OnStackGetState);
|
||||
SubscribeLocalEvent<StackComponent, ComponentHandleState>(OnStackHandleState);
|
||||
SubscribeLocalEvent<StackComponent, ComponentStartup>(OnStackStarted);
|
||||
SubscribeLocalEvent<StackComponent, ExaminedEvent>(OnStackExamined);
|
||||
SubscribeLocalEvent<StackComponent, InteractUsingEvent>(OnStackInteractUsing);
|
||||
|
||||
_vvm.GetTypeHandler<SharedStackComponent>()
|
||||
.AddPath(nameof(SharedStackComponent.Count), (_, comp) => comp.Count, SetCount);
|
||||
_vvm.GetTypeHandler<StackComponent>()
|
||||
.AddPath(nameof(StackComponent.Count), (_, comp) => comp.Count, SetCount);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_vvm.GetTypeHandler<SharedStackComponent>()
|
||||
.RemovePath(nameof(SharedStackComponent.Count));
|
||||
_vvm.GetTypeHandler<StackComponent>()
|
||||
.RemovePath(nameof(StackComponent.Count));
|
||||
}
|
||||
|
||||
private void OnStackInteractUsing(EntityUid uid, SharedStackComponent stack, InteractUsingEvent args)
|
||||
private void OnStackInteractUsing(EntityUid uid, StackComponent stack, InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Used, out SharedStackComponent? recipientStack))
|
||||
if (!TryComp(args.Used, out StackComponent? recipientStack))
|
||||
return;
|
||||
|
||||
if (!TryMergeStacks(uid, args.Used, out var transfered, stack, recipientStack))
|
||||
@@ -92,8 +92,8 @@ namespace Content.Shared.Stacks
|
||||
EntityUid donor,
|
||||
EntityUid recipient,
|
||||
out int transfered,
|
||||
SharedStackComponent? donorStack = null,
|
||||
SharedStackComponent? recipientStack = null)
|
||||
StackComponent? donorStack = null,
|
||||
StackComponent? recipientStack = null)
|
||||
{
|
||||
transfered = 0;
|
||||
if (!Resolve(recipient, ref recipientStack, false) || !Resolve(donor, ref donorStack, false))
|
||||
@@ -118,7 +118,7 @@ namespace Content.Shared.Stacks
|
||||
public void TryMergeToHands(
|
||||
EntityUid item,
|
||||
EntityUid user,
|
||||
SharedStackComponent? itemStack = null,
|
||||
StackComponent? itemStack = null,
|
||||
SharedHandsComponent? hands = null)
|
||||
{
|
||||
if (!Resolve(user, ref hands, false))
|
||||
@@ -143,7 +143,7 @@ namespace Content.Shared.Stacks
|
||||
HandsSystem.PickupOrDrop(user, item, handsComp: hands);
|
||||
}
|
||||
|
||||
public virtual void SetCount(EntityUid uid, int amount, SharedStackComponent? component = null)
|
||||
public virtual void SetCount(EntityUid uid, int amount, StackComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
@@ -169,7 +169,7 @@ namespace Content.Shared.Stacks
|
||||
/// <summary>
|
||||
/// Try to use an amount of items on this stack. Returns whether this succeeded.
|
||||
/// </summary>
|
||||
public bool Use(EntityUid uid, int amount, SharedStackComponent? stack = null)
|
||||
public bool Use(EntityUid uid, int amount, StackComponent? stack = null)
|
||||
{
|
||||
if (!Resolve(uid, ref stack))
|
||||
return false;
|
||||
@@ -199,7 +199,7 @@ namespace Content.Shared.Stacks
|
||||
public int GetMaxCount(string entityId)
|
||||
{
|
||||
var entProto = _prototype.Index<EntityPrototype>(entityId);
|
||||
entProto.TryGetComponent<SharedStackComponent>(out var stackComp);
|
||||
entProto.TryGetComponent<StackComponent>(out var stackComp);
|
||||
return GetMaxCount(stackComp);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Content.Shared.Stacks
|
||||
[PublicAPI]
|
||||
public int GetMaxCount(EntityUid uid)
|
||||
{
|
||||
return GetMaxCount(CompOrNull<SharedStackComponent>(uid));
|
||||
return GetMaxCount(CompOrNull<StackComponent>(uid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -227,7 +227,7 @@ namespace Content.Shared.Stacks
|
||||
/// </remarks>
|
||||
/// <param name="component"></param>
|
||||
/// <returns></returns>
|
||||
public int GetMaxCount(SharedStackComponent? component)
|
||||
public int GetMaxCount(StackComponent? component)
|
||||
{
|
||||
if (component == null)
|
||||
return 1;
|
||||
@@ -249,12 +249,12 @@ namespace Content.Shared.Stacks
|
||||
/// <param name="component"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public int GetAvailableSpace(SharedStackComponent component)
|
||||
public int GetAvailableSpace(StackComponent component)
|
||||
{
|
||||
return GetMaxCount(component) - component.Count;
|
||||
}
|
||||
|
||||
private void OnStackStarted(EntityUid uid, SharedStackComponent component, ComponentStartup args)
|
||||
private void OnStackStarted(EntityUid uid, StackComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!TryComp(uid, out AppearanceComponent? appearance))
|
||||
return;
|
||||
@@ -264,12 +264,12 @@ namespace Content.Shared.Stacks
|
||||
Appearance.SetData(uid, StackVisuals.Hide, false, appearance);
|
||||
}
|
||||
|
||||
private void OnStackGetState(EntityUid uid, SharedStackComponent component, ref ComponentGetState args)
|
||||
private void OnStackGetState(EntityUid uid, StackComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new StackComponentState(component.Count, GetMaxCount(component));
|
||||
}
|
||||
|
||||
private void OnStackHandleState(EntityUid uid, SharedStackComponent component, ref ComponentHandleState args)
|
||||
private void OnStackHandleState(EntityUid uid, StackComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not StackComponentState cast)
|
||||
return;
|
||||
@@ -279,7 +279,7 @@ namespace Content.Shared.Stacks
|
||||
SetCount(uid, cast.Count, component);
|
||||
}
|
||||
|
||||
private void OnStackExamined(EntityUid uid, SharedStackComponent component, ExaminedEvent args)
|
||||
private void OnStackExamined(EntityUid uid, StackComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user