Flatpacks and the Flatpacker 1001 (#23338)
* Flatpacker and flatpacks * ok that's good enough * convert solars/AME to flatpacks * mats, mats, we are the mats * basic mechanics are DONE * thing * final UI * sloth * rped jumpscare * rename
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Lathe;
|
||||
|
||||
@@ -14,11 +16,15 @@ 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 override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmagLatheRecipesComponent, GotEmaggedEvent>(OnEmagged);
|
||||
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);
|
||||
BuildInverseRecipeDictionary();
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
@@ -53,4 +59,28 @@ public abstract class SharedLatheSystem : EntitySystem
|
||||
=> reduce ? (int) MathF.Ceiling(original * multiplier) : original;
|
||||
|
||||
protected abstract bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component);
|
||||
|
||||
private void OnPrototypesReloaded(PrototypesReloadedEventArgs obj)
|
||||
{
|
||||
if (!obj.WasModified<LatheRecipePrototype>())
|
||||
return;
|
||||
BuildInverseRecipeDictionary();
|
||||
}
|
||||
|
||||
private void BuildInverseRecipeDictionary()
|
||||
{
|
||||
_inverseRecipeDictionary.Clear();
|
||||
foreach (var latheRecipe in _proto.EnumeratePrototypes<LatheRecipePrototype>())
|
||||
{
|
||||
_inverseRecipeDictionary.GetOrNew(latheRecipe.Result).Add(latheRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetRecipesFromEntity(string prototype, [NotNullWhen(true)] out List<LatheRecipePrototype>? recipes)
|
||||
{
|
||||
recipes = new();
|
||||
if (_inverseRecipeDictionary.TryGetValue(prototype, out var r))
|
||||
recipes.AddRange(r);
|
||||
return recipes.Count != 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user