Convert ItemSize to prototypes (#21481)
* item sizes are prototypes * eek
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Item;
|
||||
@@ -15,7 +16,7 @@ public sealed partial class ItemComponent : Component
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[Access(typeof(SharedItemSystem))]
|
||||
public ItemSize Size = ItemSize.Small;
|
||||
public ProtoId<ItemSizePrototype> Size = "Small";
|
||||
|
||||
[Access(typeof(SharedItemSystem))]
|
||||
[DataField]
|
||||
@@ -38,10 +39,10 @@ public sealed partial class ItemComponent : Component
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ItemComponentState : ComponentState
|
||||
{
|
||||
public ItemSize Size { get; }
|
||||
public ProtoId<ItemSizePrototype> Size { get; }
|
||||
public string? HeldPrefix { get; }
|
||||
|
||||
public ItemComponentState(ItemSize size, string? heldPrefix)
|
||||
public ItemComponentState(ProtoId<ItemSizePrototype> size, string? heldPrefix)
|
||||
{
|
||||
Size = size;
|
||||
HeldPrefix = heldPrefix;
|
||||
@@ -64,40 +65,3 @@ public sealed class VisualsChangedEvent : EntityEventArgs
|
||||
ContainerId = containerId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstracted sizes for items.
|
||||
/// Used to determine what can fit into inventories.
|
||||
/// </summary>
|
||||
public enum ItemSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Items that can be held completely in one's hand.
|
||||
/// </summary>
|
||||
Tiny = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Items that can fit inside of a standard pocket.
|
||||
/// </summary>
|
||||
Small = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Items that can fit inside of a standard bag.
|
||||
/// </summary>
|
||||
Normal = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Items that are too large to fit inside of standard bags, but can worn in exterior slots or placed in custom containers.
|
||||
/// </summary>
|
||||
Large = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Items that are too large to place inside of any kind of container.
|
||||
/// </summary>
|
||||
Huge = 16,
|
||||
|
||||
/// <summary>
|
||||
/// Picture furry gf
|
||||
/// </summary>
|
||||
Ginormous = 32
|
||||
}
|
||||
|
||||
53
Content.Shared/Item/ItemSizePrototype.cs
Normal file
53
Content.Shared/Item/ItemSizePrototype.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Item;
|
||||
|
||||
/// <summary>
|
||||
/// This is a prototype for a category of an item's size.
|
||||
/// </summary>
|
||||
[Prototype("itemSize")]
|
||||
public sealed partial class ItemSizePrototype : IPrototype, IComparable<ItemSizePrototype>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[IdDataField]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of space in a bag an item of this size takes.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public readonly int Weight = 1;
|
||||
|
||||
/// <summary>
|
||||
/// A player-facing name used to describe this size.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public readonly LocId Name;
|
||||
|
||||
public int CompareTo(ItemSizePrototype? other)
|
||||
{
|
||||
if (other is not { } otherItemSize)
|
||||
return 0;
|
||||
return Weight.CompareTo(otherItemSize.Weight);
|
||||
}
|
||||
|
||||
public static bool operator <(ItemSizePrototype a, ItemSizePrototype b)
|
||||
{
|
||||
return a.Weight < b.Weight;
|
||||
}
|
||||
|
||||
public static bool operator >(ItemSizePrototype a, ItemSizePrototype b)
|
||||
{
|
||||
return a.Weight > b.Weight;
|
||||
}
|
||||
|
||||
public static bool operator <=(ItemSizePrototype a, ItemSizePrototype b)
|
||||
{
|
||||
return a.Weight <= b.Weight;
|
||||
}
|
||||
|
||||
public static bool operator >=(ItemSizePrototype a, ItemSizePrototype b)
|
||||
{
|
||||
return a.Weight >= b.Weight;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.ItemToggle;
|
||||
|
||||
@@ -21,11 +22,11 @@ public sealed partial class ItemToggleComponent : Component
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offSize")]
|
||||
public ItemSize OffSize = ItemSize.Small;
|
||||
public ProtoId<ItemSizePrototype> OffSize = "Small";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("onSize")]
|
||||
public ItemSize OnSize = ItemSize.Huge;
|
||||
public ProtoId<ItemSizePrototype> OnSize = "Huge";
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
|
||||
@@ -6,12 +6,14 @@ using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Item;
|
||||
|
||||
public abstract class SharedItemSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] protected readonly SharedContainerSystem Container = default!;
|
||||
|
||||
@@ -30,7 +32,7 @@ public abstract class SharedItemSystem : EntitySystem
|
||||
|
||||
#region Public API
|
||||
|
||||
public void SetSize(EntityUid uid, ItemSize size, ItemComponent? component = null)
|
||||
public void SetSize(EntityUid uid, ProtoId<ItemSizePrototype> size, ItemComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
@@ -128,6 +130,11 @@ public abstract class SharedItemSystem : EntitySystem
|
||||
("size", GetItemSizeLocale(component.Size))));
|
||||
}
|
||||
|
||||
public ItemSizePrototype GetSizePrototype(ProtoId<ItemSizePrototype> id)
|
||||
{
|
||||
return _prototype.Index(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notifies any entity that is holding or wearing this item that they may need to update their sprite.
|
||||
/// </summary>
|
||||
@@ -140,14 +147,14 @@ public abstract class SharedItemSystem : EntitySystem
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static string GetItemSizeLocale(ItemSize size)
|
||||
public string GetItemSizeLocale(ProtoId<ItemSizePrototype> size)
|
||||
{
|
||||
return Robust.Shared.Localization.Loc.GetString($"item-component-size-{size.ToString()}");
|
||||
return Loc.GetString(GetSizePrototype(size).Name);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static int GetItemSizeWeight(ItemSize size)
|
||||
public int GetItemSizeWeight(ProtoId<ItemSizePrototype> size)
|
||||
{
|
||||
return (int) size;
|
||||
return GetSizePrototype(size).Weight;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user