]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Implemented parenting and minimum default for loadout groups (#40861)
authorAtakku <atakkudev+github.atakku@gmail.com>
Mon, 27 Oct 2025 22:33:56 +0000 (23:33 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 22:33:56 +0000 (22:33 +0000)
* 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>
Content.Shared/Preferences/Loadouts/LoadoutGroupPrototype.cs
Content.Shared/Preferences/Loadouts/RoleLoadout.cs

index 990f1b74a2ee283780b8d85873fec29a66284bc6..b65f332885ef63b35d88418b5d728cd4f56725a8 100644 (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>
@@ -22,6 +32,12 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
     /// </summary>
     [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.
@@ -35,6 +51,7 @@ public sealed partial class LoadoutGroupPrototype : IPrototype
     [DataField]
     public bool Hidden;
 
+    [AlwaysPushInheritance]
     [DataField(required: true)]
     public List<ProtoId<LoadoutPrototype>> Loadouts = new();
 }
index 9b7f4ae05e37671c92fb8f74f132b90d2db7c2b5..d9f79f543a928b08a799209d6aac5a8c114d1b58 100644 (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))