Files
tbd-station-14/Content.Shared/Lathe/SharedLatheComponent.cs
Rane 93cdca4f82 Partial lathe ECS, fix cursed lathe visualizer, a bit more audiovisual feedback for lathes (#7238)
* Prototype that's mostly borked rather than completely borked

* ECS inserting mats

* Partial ECS mostly done, needs cleanup and visualizer

* Replace timers

* Power visualizes at least

* First ""working"" version

* Clean up all lathes

* Colors

* Fix animation timing

* Fixes greyscale, adds a bunch of colors

* Give every (used) material a color

* Made most lathes take long enough you can at least see there's some sort of animation

* Insertion feedback popup

* Sound for circuit printer and uniform printer

* Fix queueing, optimize update

* Remove mono crash

* cleanup

* Fix test failure

* Techfab inserting sprite

* Cleanup and commenting

* Fix bug in CanProduce check

* Fix UI resolves

* Mirror review stuff
2022-04-17 17:34:14 +10:00

34 lines
1.1 KiB
C#

using Content.Shared.Research.Prototypes;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared.Lathe
{
[NetworkedComponent()]
[Virtual]
public class SharedLatheComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
public bool CanProduce(LatheRecipePrototype recipe, int quantity = 1)
{
if (!_entMan.TryGetComponent(Owner, out SharedMaterialStorageComponent? storage)
|| !_entMan.TryGetComponent(Owner, out SharedLatheDatabaseComponent? database)) return false;
if (!database.Contains(recipe)) return false;
foreach (var (material, amount) in recipe.RequiredMaterials)
{
if (storage[material] < (amount * quantity)) return false;
}
return true;
}
public bool CanProduce(string id, int quantity = 1)
{
return PrototypeManager.TryIndex(id, out LatheRecipePrototype? recipe) && CanProduce(recipe, quantity);
}
}
}