Files
tbd-station-14/Content.Shared/GameObjects/Components/Chemistry/SharedReagentDispenserComponent.cs
moneyl 963bb28f0f Reagent dispensers (#360)
* Expose more private values of Solution and SolutionComponent

Expose SolutionComponent.ContainedSolution and Solution.Contents. Both needed by ReagentDispenserComponent.

* Implement IExamine for SolutionComponent

Allows players to see the contents of a solution by examining the entity which contains it.

* Implement ReagentDispenserComponent

Adds ReagentDispenserComponent. A component which can add or remove reagents from a solution container. It's written in a general way so that it can be used for things such as the Chemical dispensers in chemistry, but also the booze and soda dispensers in the bar. 

The chemicals it may dispense are defined in yaml, similar to the way that vending machines define which entities they can dispense, by defining a reagent pack.

* Add chemical dispenser and equipment

Adds the chemical dispenser, beaker, large beaker, dropper, and a few more chemicals.

* Add booze and soda dispensers.

Adds the booze and soda dispensers, and a few chemicals for them to dispense. There's no drink mixing or drunkenness yet.

* Update engine submodule.

* Remove unneeded and commented out code

Had a few WIP notes and debug code bits I forgot to remove beforehand.

* Make SolutionComponent._containedSolution and it's values private again

- Remove `SolutionComponent.ContainedSolution` property, replace with specific access functions to maintain safety.
- Make Solution.Contents return a `ReadOnlyCollection` instead of `_contents` to prevent uncontrolled access to the Solution values.
- Add `SolutionComponent.RemoveAllSolution()`

* Update Content.Shared/Chemistry/Solution.cs

Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.

Co-Authored-By: Remie Richards <remierichards@gmail.com>

* Update Content.Shared/GameObjects/Components/Chemistry/SolutionComponent.cs

Commits a suggestion from RemieRichards to match the coding style of the rest of the codebase. Using `IReadOnlyList` instead of `IReadOnlyCollection`.

Co-Authored-By: Remie Richards <remierichards@gmail.com>

* Add import for IReadOnlyList to Shared/SolutionComponent.cs

* Add documentation

* Improve localization

Improve use of ILocalizationManager.

* Resolve ReagentDispenserWindow._localizationManager before using it

Forgot to do this in the last commit, resulting in a crash. Oops.

* Add SolutionCaps.FitsInDispenser. Use in ReagentDispenserComponent.

Used to limit large containers like buckets or mop buckets from being placed in a dispenser. Both have large capacities (500) and weren't designed to hold certain chemicals like a beaker is, so for now they can be blocked from being put in a dispenser by giving them that flag.

* Add colors to new reagents

* Update engine submodule
2019-10-05 15:10:05 +02:00

111 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using Content.Shared.Chemistry;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Chemistry
{
/// <summary>
/// Shared class for <c>ReagentDispenserComponent</c>. Provides a way for entities to dispense and remove reagents from other entities with SolutionComponents via a user interface.
/// <para>This is useful for machines such as the chemical dispensers, booze dispensers, or soda dispensers.</para>
/// <para>The chemicals which may be dispensed are defined by specifying a reagent pack. See <see cref="ReagentDispenserInventoryPrototype"/> for more information on that.</para>
/// </summary>
public class SharedReagentDispenserComponent : Component
{
public override string Name => "ReagentDispenser";
/// <summary>
/// A list of reagents which this may dispense. Defined in yaml prototype, see <see cref="ReagentDispenserInventoryPrototype"/>.
/// </summary>
public List<ReagentDispenserInventoryEntry> Inventory = new List<ReagentDispenserInventoryEntry>();
[Serializable, NetSerializable]
public class ReagentDispenserBoundUserInterfaceState : BoundUserInterfaceState
{
public readonly bool HasBeaker;
public readonly int BeakerCurrentVolume;
public readonly int BeakerMaxVolume;
public readonly string ContainerName;
/// <summary>
/// A list of the reagents which this dispenser can dispense.
/// </summary>
public readonly List<ReagentDispenserInventoryEntry> Inventory;
/// <summary>
/// A list of the reagents and their amounts within the beaker/reagent container, if applicable.
/// </summary>
public readonly List<Solution.ReagentQuantity> ContainerReagents;
public readonly string DispenserName;
public ReagentDispenserBoundUserInterfaceState(bool hasBeaker, int beakerCurrentVolume, int beakerMaxVolume, string containerName,
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Solution.ReagentQuantity> containerReagents)
{
HasBeaker = hasBeaker;
BeakerCurrentVolume = beakerCurrentVolume;
BeakerMaxVolume = beakerMaxVolume;
ContainerName = containerName;
Inventory = inventory;
DispenserName = dispenserName;
ContainerReagents = containerReagents;
}
}
/// <summary>
/// Message data sent from client to server when a dispenser ui button is pressed.
/// </summary>
[Serializable, NetSerializable]
public class UiButtonPressedMessage : BoundUserInterfaceMessage
{
public readonly UiButton Button;
public readonly int DispenseIndex; //Index of dispense button / reagent being pressed. Only used when a dispense button is pressed.
public UiButtonPressedMessage(UiButton button, int dispenseIndex)
{
Button = button;
DispenseIndex = dispenseIndex;
}
}
[Serializable, NetSerializable]
public enum ReagentDispenserUiKey
{
Key
}
/// <summary>
/// Used in <see cref="UiButtonPressedMessage"/> to specify which button was pressed.
/// </summary>
public enum UiButton
{
Eject,
Clear,
SetDispenseAmount1,
SetDispenseAmount5,
SetDispenseAmount10,
SetDispenseAmount25,
SetDispenseAmount50,
SetDispenseAmount100,
/// <summary>
/// Used when any dispense button is pressed. Such as "Carbon", or "Oxygen" buttons on the chem dispenser.
/// The index of the reagent attached to that dispense button is sent as <see cref="UiButtonPressedMessage.DispenseIndex"/>.
/// </summary>
Dispense
}
/// <summary>
/// Information about a reagent which the dispenser can dispense.
/// </summary>
[Serializable, NetSerializable]
public class ReagentDispenserInventoryEntry
{
public string ID;
public ReagentDispenserInventoryEntry(string id)
{
ID = id;
}
}
}
}