Implemented parenting and minimum default for loadout groups (#40861)

* Implemented parenting and minimum default for loadouts

* Fix a mistake

* Apply suggestion from @iaada

Co-authored-by: āda <ss.adasts@gmail.com>

* Implement @iaada's suggestion to rename MinDefault to DefaultSelected

* happy little accidents

* Moved Parents and Abstract fields to under ID, added inheritdoc

---------

Co-authored-by: āda <ss.adasts@gmail.com>
This commit is contained in:
Atakku
2025-10-27 23:33:56 +01:00
committed by GitHub
parent ce6daea5fb
commit abd9aec8bd
2 changed files with 20 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Shared.Preferences.Loadouts;
@@ -6,11 +7,20 @@ namespace Content.Shared.Preferences.Loadouts;
/// Corresponds to a set of loadouts for a particular slot.
/// </summary>
[Prototype]
public sealed partial class LoadoutGroupPrototype : IPrototype
public sealed partial class LoadoutGroupPrototype : IPrototype, IInheritingPrototype
{
[IdDataField]
public string ID { get; private set; } = string.Empty;
/// <inheritdoc />
[ParentDataFieldAttribute(typeof(AbstractPrototypeIdArraySerializer<LoadoutGroupPrototype>))]
public string[]? Parents { get; }
/// <inheritdoc />
[NeverPushInheritance]
[AbstractDataField]
public bool Abstract { get; }
/// <summary>
/// User-friendly name for the group.
/// </summary>
@@ -23,6 +33,12 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
[DataField]
public int MinLimit = 1;
/// <summary>
/// Number of loadouts that are selected by default.
/// </summary>
[DataField]
public int DefaultSelected = 0;
/// <summary>
/// Maximum limit for the category.
/// </summary>
@@ -35,6 +51,7 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
[DataField]
public bool Hidden;
[AlwaysPushInheritance]
[DataField(required: true)]
public List<ProtoId<LoadoutPrototype>> Loadouts = new();
}

View File

@@ -228,13 +228,13 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
var loadouts = new List<Loadout>();
SelectedLoadouts[group] = loadouts;
if (groupProto.MinLimit > 0)
if (groupProto.MinLimit > 0 || loadouts.Count < groupProto.DefaultSelected)
{
// Apply any loadouts we can.
foreach (var protoId in groupProto.Loadouts)
{
// Reached the limit, time to stop
if (loadouts.Count >= groupProto.MinLimit)
if (loadouts.Count >= Math.Max(groupProto.MinLimit, groupProto.DefaultSelected))
break;
if (!protoManager.TryIndex(protoId, out var loadoutProto))