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:
@@ -1,4 +1,5 @@
|
|||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
|
||||||
|
|
||||||
namespace Content.Shared.Preferences.Loadouts;
|
namespace Content.Shared.Preferences.Loadouts;
|
||||||
|
|
||||||
@@ -6,11 +7,20 @@ namespace Content.Shared.Preferences.Loadouts;
|
|||||||
/// Corresponds to a set of loadouts for a particular slot.
|
/// Corresponds to a set of loadouts for a particular slot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Prototype]
|
[Prototype]
|
||||||
public sealed partial class LoadoutGroupPrototype : IPrototype
|
public sealed partial class LoadoutGroupPrototype : IPrototype, IInheritingPrototype
|
||||||
{
|
{
|
||||||
[IdDataField]
|
[IdDataField]
|
||||||
public string ID { get; private set; } = string.Empty;
|
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>
|
/// <summary>
|
||||||
/// User-friendly name for the group.
|
/// User-friendly name for the group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,6 +33,12 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
|
|||||||
[DataField]
|
[DataField]
|
||||||
public int MinLimit = 1;
|
public int MinLimit = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Number of loadouts that are selected by default.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public int DefaultSelected = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maximum limit for the category.
|
/// Maximum limit for the category.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -35,6 +51,7 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
|
|||||||
[DataField]
|
[DataField]
|
||||||
public bool Hidden;
|
public bool Hidden;
|
||||||
|
|
||||||
|
[AlwaysPushInheritance]
|
||||||
[DataField(required: true)]
|
[DataField(required: true)]
|
||||||
public List<ProtoId<LoadoutPrototype>> Loadouts = new();
|
public List<ProtoId<LoadoutPrototype>> Loadouts = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,13 +228,13 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
|
|||||||
var loadouts = new List<Loadout>();
|
var loadouts = new List<Loadout>();
|
||||||
SelectedLoadouts[group] = loadouts;
|
SelectedLoadouts[group] = loadouts;
|
||||||
|
|
||||||
if (groupProto.MinLimit > 0)
|
if (groupProto.MinLimit > 0 || loadouts.Count < groupProto.DefaultSelected)
|
||||||
{
|
{
|
||||||
// Apply any loadouts we can.
|
// Apply any loadouts we can.
|
||||||
foreach (var protoId in groupProto.Loadouts)
|
foreach (var protoId in groupProto.Loadouts)
|
||||||
{
|
{
|
||||||
// Reached the limit, time to stop
|
// Reached the limit, time to stop
|
||||||
if (loadouts.Count >= groupProto.MinLimit)
|
if (loadouts.Count >= Math.Max(groupProto.MinLimit, groupProto.DefaultSelected))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!protoManager.TryIndex(protoId, out var loadoutProto))
|
if (!protoManager.TryIndex(protoId, out var loadoutProto))
|
||||||
|
|||||||
Reference in New Issue
Block a user