reduce lathe recipe copy pasta (#31515)
* 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>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -495,8 +495,6 @@
|
||||
- PortableGeneratorPacmanMachineCircuitboard
|
||||
- PortableGeneratorSuperPacmanMachineCircuitboard
|
||||
- PortableGeneratorJrPacmanMachineCircuitboard
|
||||
- WallmountGeneratorElectronics
|
||||
- WallmountGeneratorAPUElectronics
|
||||
- WallmountSubstationElectronics
|
||||
- PowerCageRechargerCircuitboard
|
||||
- EmitterCircuitboard
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
# Non-stackable part that can have a use outside of machines
|
||||
- type: latheRecipe
|
||||
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
|
||||
category: Parts
|
||||
completetime: 1
|
||||
materials:
|
||||
Steel: 50
|
||||
Plastic: 50
|
||||
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user