Allow storage to specify a default orientation for stored items. (#23594)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Nemanja
2024-01-05 22:19:01 -05:00
committed by GitHub
parent a9075e5d24
commit a448e5fa56
3 changed files with 38 additions and 1 deletions

View File

@@ -890,11 +890,32 @@ public abstract class SharedStorageSystem : EntitySystem
var storageBounding = storageEnt.Comp.Grid.GetBoundingBox(); 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 y = storageBounding.Bottom; y <= storageBounding.Top; y++)
{ {
for (var x = storageBounding.Left; x <= storageBounding.Right; x++) 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)); var location = new ItemStorageLocation(angle, (x, y));
if (ItemFitsInGridLocation(itemEnt, storageEnt, location)) if (ItemFitsInGridLocation(itemEnt, storageEnt, location))

View File

@@ -94,6 +94,14 @@ namespace Content.Shared.Storage
[DataField("storageCloseSound")] [DataField("storageCloseSound")]
public SoundSpecifier? StorageCloseSound; public SoundSpecifier? StorageCloseSound;
/// <summary>
/// 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
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public StorageDefaultOrientation? DefaultStorageOrientation;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum StorageUiKey public enum StorageUiKey
{ {
@@ -204,4 +212,11 @@ namespace Content.Shared.Storage
StorageUsed, StorageUsed,
Capacity Capacity
} }
[Serializable, NetSerializable]
public enum StorageDefaultOrientation : byte
{
Horizontal,
Vertical
}
} }

View File

@@ -23,6 +23,7 @@
components: components:
- type: Storage - type: Storage
maxItemSize: Normal maxItemSize: Normal
defaultStorageOrientation: Vertical
grid: grid:
- 0,0,7,1 - 0,0,7,1
- type: Item - type: Item