Toggleable items shape change on toggle state (#25392)

* Toggleable items now can change their shape depends on toggle state

* Update Content.Shared/Item/SharedItemSystem.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
MilenVolf
2024-02-25 16:20:28 +03:00
committed by GitHub
parent a440ccfc7c
commit 1a5f7c39b2
2 changed files with 33 additions and 0 deletions

View File

@@ -18,9 +18,21 @@ public sealed partial class ItemToggleSizeComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public ProtoId<ItemSizePrototype>? ActivatedSize = null; public ProtoId<ItemSizePrototype>? ActivatedSize = null;
/// <summary>
/// Item's shape when activated
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public List<Box2i>? ActivatedShape = null;
/// <summary> /// <summary>
/// Item's size when deactivated. If none is mentioned, it uses the item's default size instead. /// Item's size when deactivated. If none is mentioned, it uses the item's default size instead.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public ProtoId<ItemSizePrototype>? DeactivatedSize = null; public ProtoId<ItemSizePrototype>? DeactivatedSize = null;
/// <summary>
/// Item's shape when deactivated. If none is mentioned, it uses the item's default shape instead.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField]
public List<Box2i>? DeactivatedShape = null;
} }

View File

@@ -46,6 +46,15 @@ public abstract class SharedItemSystem : EntitySystem
Dirty(uid, component); Dirty(uid, component);
} }
public void SetShape(EntityUid uid, List<Box2i>? shape, ItemComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
component.Shape = shape;
Dirty(uid, component);
}
public void SetHeldPrefix(EntityUid uid, string? heldPrefix, bool force = false, ItemComponent? component = null) public void SetHeldPrefix(EntityUid uid, string? heldPrefix, bool force = false, ItemComponent? component = null)
{ {
if (!Resolve(uid, ref component, false)) if (!Resolve(uid, ref component, false))
@@ -209,6 +218,13 @@ public abstract class SharedItemSystem : EntitySystem
if (args.Activated) if (args.Activated)
{ {
if (itemToggleSize.ActivatedShape != null)
{
// Set the deactivated shape to the default item's shape before it gets changed.
itemToggleSize.DeactivatedShape ??= new List<Box2i>(GetItemShape(item));
SetShape(uid, itemToggleSize.ActivatedShape, item);
}
if (itemToggleSize.ActivatedSize != null) if (itemToggleSize.ActivatedSize != null)
{ {
// Set the deactivated size to the default item's size before it gets changed. // Set the deactivated size to the default item's size before it gets changed.
@@ -218,6 +234,11 @@ public abstract class SharedItemSystem : EntitySystem
} }
else else
{ {
if (itemToggleSize.DeactivatedShape != null)
{
SetShape(uid, itemToggleSize.DeactivatedShape, item);
}
if (itemToggleSize.DeactivatedSize != null) if (itemToggleSize.DeactivatedSize != null)
{ {
SetSize(uid, (ProtoId<ItemSizePrototype>) itemToggleSize.DeactivatedSize, item); SetSize(uid, (ProtoId<ItemSizePrototype>) itemToggleSize.DeactivatedSize, item);