From a448e5fa567e8e781b9b3093376312cc9f654533 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Fri, 5 Jan 2024 22:19:01 -0500 Subject: [PATCH] Allow storage to specify a default orientation for stored items. (#23594) Co-authored-by: metalgearsloth --- .../EntitySystems/SharedStorageSystem.cs | 23 ++++++++++++++++++- Content.Shared/Storage/StorageComponent.cs | 15 ++++++++++++ .../Clothing/Belt/base_clothingbelt.yml | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 9092bdc741..17eb30ad50 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -890,11 +890,32 @@ public abstract class SharedStorageSystem : EntitySystem var storageBounding = storageEnt.Comp.Grid.GetBoundingBox(); + Angle startAngle; + if (storageEnt.Comp.DefaultStorageOrientation == null) + { + startAngle = Angle.FromDegrees(-itemEnt.Comp.StoredRotation); + } + else + { + if (storageBounding.Width < storageBounding.Height) + { + startAngle = storageEnt.Comp.DefaultStorageOrientation == StorageDefaultOrientation.Horizontal + ? Angle.Zero + : Angle.FromDegrees(90); + } + else + { + startAngle = storageEnt.Comp.DefaultStorageOrientation == StorageDefaultOrientation.Vertical + ? Angle.Zero + : Angle.FromDegrees(90); + } + } + for (var y = storageBounding.Bottom; y <= storageBounding.Top; y++) { for (var x = storageBounding.Left; x <= storageBounding.Right; x++) { - for (var angle = Angle.FromDegrees(-itemEnt.Comp.StoredRotation); angle <= Angle.FromDegrees(360 - itemEnt.Comp.StoredRotation); angle += Math.PI / 2f) + for (var angle = startAngle; angle <= Angle.FromDegrees(360 - startAngle); angle += Math.PI / 2f) { var location = new ItemStorageLocation(angle, (x, y)); if (ItemFitsInGridLocation(itemEnt, storageEnt, location)) diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs index e3287b20ad..796c9cb5ff 100644 --- a/Content.Shared/Storage/StorageComponent.cs +++ b/Content.Shared/Storage/StorageComponent.cs @@ -94,6 +94,14 @@ namespace Content.Shared.Storage [DataField("storageCloseSound")] public SoundSpecifier? StorageCloseSound; + /// + /// If not null, ensures that all inserted items are of the same orientation + /// Horizontal - items are stored laying down + /// Vertical - items are stored standing up + /// + [DataField, ViewVariables(VVAccess.ReadWrite)] + public StorageDefaultOrientation? DefaultStorageOrientation; + [Serializable, NetSerializable] public enum StorageUiKey { @@ -204,4 +212,11 @@ namespace Content.Shared.Storage StorageUsed, Capacity } + + [Serializable, NetSerializable] + public enum StorageDefaultOrientation : byte + { + Horizontal, + Vertical + } } diff --git a/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml b/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml index 614e739e05..2f904d3438 100644 --- a/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml +++ b/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml @@ -23,6 +23,7 @@ components: - type: Storage maxItemSize: Normal + defaultStorageOrientation: Vertical grid: - 0,0,7,1 - type: Item -- 2.51.2