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 pricing = entManager.System<PricingSystem>();
|
||||||
var stackSys = entManager.System<StackSystem>();
|
var stackSys = entManager.System<StackSystem>();
|
||||||
var mapSystem = server.System<SharedMapSystem>();
|
var mapSystem = server.System<SharedMapSystem>();
|
||||||
|
var latheSys = server.System<SharedLatheSystem>();
|
||||||
var compFact = server.ResolveDependency<IComponentFactory>();
|
var compFact = server.ResolveDependency<IComponentFactory>();
|
||||||
|
|
||||||
Assert.That(mapSystem.IsInitialized(testMap.MapId));
|
Assert.That(mapSystem.IsInitialized(testMap.MapId));
|
||||||
@@ -53,12 +54,8 @@ public sealed class MaterialArbitrageTest
|
|||||||
var materialName = compFact.GetComponentName(typeof(MaterialComponent));
|
var materialName = compFact.GetComponentName(typeof(MaterialComponent));
|
||||||
var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
|
var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
|
||||||
|
|
||||||
// construct inverted lathe recipe dictionary
|
// get the inverted lathe recipe dictionary
|
||||||
Dictionary<string, List<LatheRecipePrototype>> latheRecipes = new();
|
var latheRecipes = latheSys.InverseRecipes;
|
||||||
foreach (var proto in protoManager.EnumeratePrototypes<LatheRecipePrototype>())
|
|
||||||
{
|
|
||||||
latheRecipes.GetOrNew(proto.Result).Add(proto);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lets assume the possible lathe for resource multipliers:
|
// 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.
|
// 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 IPrototypeManager _proto = default!;
|
||||||
[Dependency] private readonly SharedMaterialStorageSystem _materialStorage = 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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -83,20 +83,20 @@ public abstract class SharedLatheSystem : EntitySystem
|
|||||||
|
|
||||||
private void BuildInverseRecipeDictionary()
|
private void BuildInverseRecipeDictionary()
|
||||||
{
|
{
|
||||||
_inverseRecipeDictionary.Clear();
|
InverseRecipes.Clear();
|
||||||
foreach (var latheRecipe in _proto.EnumeratePrototypes<LatheRecipePrototype>())
|
foreach (var latheRecipe in _proto.EnumeratePrototypes<LatheRecipePrototype>())
|
||||||
{
|
{
|
||||||
if (latheRecipe.Result == null)
|
if (latheRecipe.Result is not {} result)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_inverseRecipeDictionary.GetOrNew(latheRecipe.Result).Add(latheRecipe);
|
InverseRecipes.GetOrNew(result).Add(latheRecipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetRecipesFromEntity(string prototype, [NotNullWhen(true)] out List<LatheRecipePrototype>? recipes)
|
public bool TryGetRecipesFromEntity(string prototype, [NotNullWhen(true)] out List<LatheRecipePrototype>? recipes)
|
||||||
{
|
{
|
||||||
recipes = new();
|
recipes = new();
|
||||||
if (_inverseRecipeDictionary.TryGetValue(prototype, out var r))
|
if (InverseRecipes.TryGetValue(prototype, out var r))
|
||||||
recipes.AddRange(r);
|
recipes.AddRange(r);
|
||||||
return recipes.Count != 0;
|
return recipes.Count != 0;
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ public abstract class SharedLatheSystem : EntitySystem
|
|||||||
if (!string.IsNullOrWhiteSpace(proto.Name))
|
if (!string.IsNullOrWhiteSpace(proto.Name))
|
||||||
return Loc.GetString(proto.Name);
|
return Loc.GetString(proto.Name);
|
||||||
|
|
||||||
if (proto.Result is { } result)
|
if (proto.Result is {} result)
|
||||||
{
|
{
|
||||||
return _proto.Index(result).Name;
|
return _proto.Index(result).Name;
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ public abstract class SharedLatheSystem : EntitySystem
|
|||||||
if (!string.IsNullOrWhiteSpace(proto.Description))
|
if (!string.IsNullOrWhiteSpace(proto.Description))
|
||||||
return Loc.GetString(proto.Description);
|
return Loc.GetString(proto.Description);
|
||||||
|
|
||||||
if (proto.Result is { } result)
|
if (proto.Result is {} result)
|
||||||
{
|
{
|
||||||
return _proto.Index(result).Description;
|
return _proto.Index(result).Description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,27 @@ using Content.Shared.Lathe.Prototypes;
|
|||||||
using Content.Shared.Materials;
|
using Content.Shared.Materials;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Research.Prototypes
|
namespace Content.Shared.Research.Prototypes
|
||||||
{
|
{
|
||||||
[NetSerializable, Serializable, Prototype]
|
[NetSerializable, Serializable, Prototype]
|
||||||
public sealed partial class LatheRecipePrototype : IPrototype
|
public sealed partial class LatheRecipePrototype : IPrototype, IInheritingPrototype
|
||||||
{
|
{
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
[IdDataField]
|
[IdDataField]
|
||||||
public string ID { get; private set; } = default!;
|
public string ID { get; private set; } = default!;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
[ParentDataField(typeof(AbstractPrototypeIdArraySerializer<LatheRecipePrototype>))]
|
||||||
|
public string[]? Parents { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
[NeverPushInheritance]
|
||||||
|
[AbstractDataField]
|
||||||
|
public bool Abstract { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name displayed in the lathe GUI.
|
/// Name displayed in the lathe GUI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -495,8 +495,6 @@
|
|||||||
- PortableGeneratorPacmanMachineCircuitboard
|
- PortableGeneratorPacmanMachineCircuitboard
|
||||||
- PortableGeneratorSuperPacmanMachineCircuitboard
|
- PortableGeneratorSuperPacmanMachineCircuitboard
|
||||||
- PortableGeneratorJrPacmanMachineCircuitboard
|
- PortableGeneratorJrPacmanMachineCircuitboard
|
||||||
- WallmountGeneratorElectronics
|
|
||||||
- WallmountGeneratorAPUElectronics
|
|
||||||
- WallmountSubstationElectronics
|
- WallmountSubstationElectronics
|
||||||
- PowerCageRechargerCircuitboard
|
- PowerCageRechargerCircuitboard
|
||||||
- EmitterCircuitboard
|
- EmitterCircuitboard
|
||||||
|
|||||||
@@ -1,26 +1,34 @@
|
|||||||
|
# Non-stackable part that can have a use outside of machines
|
||||||
- type: latheRecipe
|
- 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
|
id: CapacitorStockPart
|
||||||
result: CapacitorStockPart
|
result: CapacitorStockPart
|
||||||
category: Parts
|
|
||||||
completetime: 1
|
|
||||||
materials:
|
|
||||||
Steel: 50
|
|
||||||
Plastic: 50
|
|
||||||
|
|
||||||
- type: latheRecipe
|
- type: latheRecipe
|
||||||
|
parent: BaseStockPartRecipe
|
||||||
id: MatterBinStockPart
|
id: MatterBinStockPart
|
||||||
result: MatterBinStockPart
|
result: MatterBinStockPart
|
||||||
category: Parts
|
|
||||||
completetime: 1
|
|
||||||
materials:
|
|
||||||
Steel: 50
|
|
||||||
Plastic: 50
|
|
||||||
|
|
||||||
- type: latheRecipe
|
- type: latheRecipe
|
||||||
|
parent: BaseStockPartRecipe
|
||||||
id: MicroManipulatorStockPart
|
id: MicroManipulatorStockPart
|
||||||
result: MicroManipulatorStockPart
|
result: MicroManipulatorStockPart
|
||||||
category: Parts
|
|
||||||
completetime: 1
|
|
||||||
materials:
|
|
||||||
Steel: 50
|
|
||||||
Plastic: 50
|
|
||||||
|
|||||||
Reference in New Issue
Block a user