]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
reduce lathe recipe copy pasta (#31515)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Thu, 29 Aug 2024 19:36:29 +0000 (19:36 +0000)
committerGitHub <noreply@github.com>
Thu, 29 Aug 2024 19:36:29 +0000 (15:36 -0400)
* add inheritance to lathe recipes and make result an override

* add GetResult method to lathe system

* make other parts of the code use GetResult

* clean up the stock parts yml

* remove unused apu boards from dynamic recipes

* make inverse dictionary public so test doesnt have to copy paste

* revert result override stuff

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.IntegrationTests/Tests/MaterialArbitrageTest.cs
Content.Shared/Lathe/SharedLatheSystem.cs
Content.Shared/Research/Prototypes/LatheRecipePrototype.cs
Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Resources/Prototypes/Recipes/Lathes/Parts.yml

index c48afd819bed4a96c9ed4126f252ae8288cfe114..ae094052205d4644a83e7926f5311b05d088330e 100644 (file)
@@ -44,6 +44,7 @@ public sealed class MaterialArbitrageTest
         var pricing = entManager.System<PricingSystem>();
         var stackSys = entManager.System<StackSystem>();
         var mapSystem = server.System<SharedMapSystem>();
+        var latheSys = server.System<SharedLatheSystem>();
         var compFact = server.ResolveDependency<IComponentFactory>();
 
         Assert.That(mapSystem.IsInitialized(testMap.MapId));
@@ -53,12 +54,8 @@ public sealed class MaterialArbitrageTest
         var materialName = compFact.GetComponentName(typeof(MaterialComponent));
         var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
 
-        // construct inverted lathe recipe dictionary
-        Dictionary<string, List<LatheRecipePrototype>> latheRecipes = new();
-        foreach (var proto in protoManager.EnumeratePrototypes<LatheRecipePrototype>())
-        {
-            latheRecipes.GetOrNew(proto.Result).Add(proto);
-        }
+        // get the inverted lathe recipe dictionary
+        var latheRecipes = latheSys.InverseRecipes;
 
         // Lets assume the possible lathe for resource multipliers:
         // TODO: each recipe can technically have its own cost multiplier associated with it, so this test needs redone to factor that in.
index e240571f3153db410b1bdb9cad2a7d772ec95332..dd251ed18b3f5114a04f094d3ad090ad151859d8 100644 (file)
@@ -19,7 +19,7 @@ public abstract class SharedLatheSystem : EntitySystem
     [Dependency] private readonly IPrototypeManager _proto = default!;
     [Dependency] private readonly SharedMaterialStorageSystem _materialStorage = default!;
 
-    private readonly Dictionary<string, List<LatheRecipePrototype>> _inverseRecipeDictionary = new();
+    public readonly Dictionary<string, List<LatheRecipePrototype>> InverseRecipes = new();
 
     public override void Initialize()
     {
@@ -83,20 +83,20 @@ public abstract class SharedLatheSystem : EntitySystem
 
     private void BuildInverseRecipeDictionary()
     {
-        _inverseRecipeDictionary.Clear();
+        InverseRecipes.Clear();
         foreach (var latheRecipe in _proto.EnumeratePrototypes<LatheRecipePrototype>())
         {
-            if (latheRecipe.Result == null)
+            if (latheRecipe.Result is not {} result)
                 continue;
 
-            _inverseRecipeDictionary.GetOrNew(latheRecipe.Result).Add(latheRecipe);
+            InverseRecipes.GetOrNew(result).Add(latheRecipe);
         }
     }
 
     public bool TryGetRecipesFromEntity(string prototype, [NotNullWhen(true)] out List<LatheRecipePrototype>? recipes)
     {
         recipes = new();
-        if (_inverseRecipeDictionary.TryGetValue(prototype, out var r))
+        if (InverseRecipes.TryGetValue(prototype, out var r))
             recipes.AddRange(r);
         return recipes.Count != 0;
     }
@@ -111,7 +111,7 @@ public abstract class SharedLatheSystem : EntitySystem
         if (!string.IsNullOrWhiteSpace(proto.Name))
             return Loc.GetString(proto.Name);
 
-        if (proto.Result is { } result)
+        if (proto.Result is {} result)
         {
             return _proto.Index(result).Name;
         }
@@ -137,7 +137,7 @@ public abstract class SharedLatheSystem : EntitySystem
         if (!string.IsNullOrWhiteSpace(proto.Description))
             return Loc.GetString(proto.Description);
 
-        if (proto.Result is { } result)
+        if (proto.Result is {} result)
         {
             return _proto.Index(result).Description;
         }
index 40c20df343738cea8e3fb89d5998a742b6fe8f2b..0fabbd67166967e99191d2f8c764c241ad309a8e 100644 (file)
@@ -4,17 +4,27 @@ using Content.Shared.Lathe.Prototypes;
 using Content.Shared.Materials;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Serialization;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
 using Robust.Shared.Utility;
 
 namespace Content.Shared.Research.Prototypes
 {
     [NetSerializable, Serializable, Prototype]
-    public sealed partial class LatheRecipePrototype : IPrototype
+    public sealed partial class LatheRecipePrototype : IPrototype, IInheritingPrototype
     {
         [ViewVariables]
         [IdDataField]
         public string ID { get; private set; } = default!;
 
+        /// <inheritdoc/>
+        [ParentDataField(typeof(AbstractPrototypeIdArraySerializer<LatheRecipePrototype>))]
+        public string[]? Parents { get; }
+
+        /// <inheritdoc />
+        [NeverPushInheritance]
+        [AbstractDataField]
+        public bool Abstract { get; }
+
         /// <summary>
         ///     Name displayed in the lathe GUI.
         /// </summary>
index ba20a7b0cdde68b28c46250ec2676b57abdea511..c606e26f8f5a8d004d9909bc2724ef1b5e16e4bf 100644 (file)
       - PortableGeneratorPacmanMachineCircuitboard
       - PortableGeneratorSuperPacmanMachineCircuitboard
       - PortableGeneratorJrPacmanMachineCircuitboard
-      - WallmountGeneratorElectronics
-      - WallmountGeneratorAPUElectronics
       - WallmountSubstationElectronics
       - PowerCageRechargerCircuitboard
       - EmitterCircuitboard
index 90cff2174d6d73518f243d572c24d32c331478cc..0202919cb9a794161a2602569b5023f7b726ac09 100644 (file)
@@ -1,26 +1,34 @@
+# Non-stackable part that can have a use outside of machines
 - type: latheRecipe
-  id: CapacitorStockPart
-  result: CapacitorStockPart
+  abstract: true
+  id: BasePartRecipe
   category: Parts
+  completetime: 2
+  materials:
+    Steel: 300
+    Plastic: 200
+
+# Stackable part with no function
+- type: latheRecipe
+  abstract: true
+  parent: BasePartRecipe
+  id: BaseStockPartRecipe
   completetime: 1
   materials:
     Steel: 50
     Plastic: 50
 
 - type: latheRecipe
+  parent: BaseStockPartRecipe
+  id: CapacitorStockPart
+  result: CapacitorStockPart
+
+- type: latheRecipe
+  parent: BaseStockPartRecipe
   id: MatterBinStockPart
   result: MatterBinStockPart
-  category: Parts
-  completetime: 1
-  materials:
-    Steel: 50
-    Plastic: 50
 
 - type: latheRecipe
+  parent: BaseStockPartRecipe
   id: MicroManipulatorStockPart
   result: MicroManipulatorStockPart
-  category: Parts
-  completetime: 1
-  materials:
-    Steel: 50
-    Plastic: 50