Refactor ReagentGrinder (#11751)

* Refactor ReagentGrinder

- It can now process partial stacks. (Before it would do nothing if the entire stack's solution didn't fit in the output container)
- Get rid of `SharedReagentGrinderComponent`, move shared stuff to `SharedReagentGrinder.cs`.
- Subscribe to events instead of massive switch/case.
- Get rid of update queue thing.
- Change `DoWork` so it's less duplicate code for grinding/juicing.
- Get rid of `ExtractableScalingEvent` and just scale directly based on item stack count.
- Add message for when you try to put something into the reagent grinder that doesn't fit.
- Fix obsolescence warnings.

* Use a timer on component instead of SpawnTimer

* s/StorageCap/StorageMaxEntities
This commit is contained in:
0x6273
2022-10-26 08:34:56 +02:00
committed by GitHub
parent 0dd60bb6a7
commit dfdad0ffe5
10 changed files with 378 additions and 428 deletions

View File

@@ -1,8 +1,6 @@
using Content.Shared.Chemistry.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Kitchen.Components;
using Content.Shared.Kitchen;
using Content.Server.Kitchen.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
namespace Content.Server.Kitchen.Components
{
@@ -12,32 +10,36 @@ namespace Content.Server.Kitchen.Components
/// converting something into its single juice form. E.g, grind an apple and get the nutriment and sugar
/// it contained, juice an apple and get "apple juice".
/// </summary>
[RegisterComponent]
public sealed class ReagentGrinderComponent : SharedReagentGrinderComponent
[Access(typeof(ReagentGrinderSystem)), RegisterComponent]
public sealed class ReagentGrinderComponent : Component
{
//YAML serialization vars
[DataField("storageMaxEntities"), ViewVariables(VVAccess.ReadWrite)]
public int StorageMaxEntities = 16;
[DataField("workTime"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan WorkTime = TimeSpan.FromSeconds(3.5); // Roughly matches the grind/juice sounds.
[DataField("clickSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
[DataField("grindSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier GrindSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/blender.ogg");
[DataField("juiceSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier JuiceSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/juicer.ogg");
}
[Access(typeof(ReagentGrinderSystem)), RegisterComponent]
public sealed class ActiveReagentGrinderComponent : Component
{
/// <summary>
/// Can be null since we won't always have a beaker in the grinder.
/// Remaining time until the grinder finishes grinding/juicing.
/// </summary>
[ViewVariables] public Solution? BeakerSolution;
[ViewVariables]
public float WorkTimer;
/// <summary>
/// Contains the things that are going to be ground or juiced.
/// </summary>
[ViewVariables] public Container Chamber = default!;
/// <summary>
/// Is the machine actively doing something and can't be used right now?
/// </summary>
public bool Busy;
//YAML serialization vars
[ViewVariables(VVAccess.ReadWrite)] [DataField("chamberCapacity")] public int StorageCap = 16;
[ViewVariables(VVAccess.ReadWrite)] [DataField("workTime")] public int WorkTime = 3500; //3.5 seconds, completely arbitrary for now.
[DataField("clickSound")] public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
[DataField("grindSound")] public SoundSpecifier GrindSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/blender.ogg");
[DataField("juiceSound")] public SoundSpecifier JuiceSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/juicer.ogg");
[DataField("beakerSlot")]
public ItemSlot BeakerSlot = new();
[ViewVariables]
public GrinderProgram Program;
}
}