Sort reagent dispenser entries (#3272)

* Sort reagent dispenser entries

Saves manually doing it.

* zumzum's suggestion

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-02-18 20:58:43 +11:00
committed by GitHub
parent a328de07d7
commit fb5c9d689e

View File

@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.GUI;
@@ -37,6 +38,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
[ComponentReference(typeof(IInteractUsing))]
public class ReagentDispenserComponent : SharedReagentDispenserComponent, IActivate, IInteractUsing, ISolutionChange
{
private static ReagentInventoryComparer _comparer = new();
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables] private ContainerSlot _beakerContainer = default!;
@@ -109,6 +112,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
{
Inventory.Add(new ReagentDispenserInventoryEntry(entry));
}
Inventory.Sort(_comparer);
}
private void OnPowerChanged(PowerChangedMessage e)
@@ -375,5 +380,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
component.TryEject(user);
}
}
private class ReagentInventoryComparer : Comparer<ReagentDispenserInventoryEntry>
{
public override int Compare(ReagentDispenserInventoryEntry x, ReagentDispenserInventoryEntry y)
{
return string.Compare(x.ID, y.ID, StringComparison.InvariantCultureIgnoreCase);
}
}
}
}