Recognizable chemicals (#16761)

This commit is contained in:
Kara
2023-05-24 16:08:05 -07:00
committed by GitHub
parent e93b1ad055
commit 04c975534b
16 changed files with 115 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components;
@@ -65,7 +66,9 @@ public sealed partial class SolutionContainerSystem : EntitySystem
SolutionContainerManagerComponent? solutionsManager = null;
if (!Resolve(args.Examined, ref solutionsManager)
|| !solutionsManager.Solutions.TryGetValue(examinableComponent.Solution, out var solutionHolder))
{
return;
}
var primaryReagent = solutionHolder.GetPrimaryReagentId();
@@ -75,7 +78,7 @@ public sealed partial class SolutionContainerSystem : EntitySystem
return;
}
if (!_prototypeManager.TryIndex(primaryReagent, out ReagentPrototype? proto))
if (!_prototypeManager.TryIndex(primaryReagent, out ReagentPrototype? primary))
{
Logger.Error(
$"{nameof(Solution)} could not find the prototype associated with {primaryReagent}.");
@@ -91,7 +94,53 @@ public sealed partial class SolutionContainerSystem : EntitySystem
("wordedAmount", Loc.GetString(solutionHolder.Contents.Count == 1
? "shared-solution-container-component-on-examine-worded-amount-one-reagent"
: "shared-solution-container-component-on-examine-worded-amount-multiple-reagents")),
("desc", proto.LocalizedPhysicalDescription)));
("desc", primary.LocalizedPhysicalDescription)));
// Add descriptions of immediately recognizable reagents, like water or beer
var recognized = new List<ReagentPrototype>();
foreach (var (id, _) in solutionHolder)
{
if (!_prototypeManager.TryIndex<ReagentPrototype>(id, out var proto))
{
continue;
}
if (!proto.Recognizable)
{
continue;
}
recognized.Add(proto);
}
// Skip if there's nothing recognizable
if (recognized.Count == 0)
return;
var msg = new StringBuilder();
foreach (var reagent in recognized)
{
string part;
if (reagent == recognized[0])
{
part = "examinable-solution-recognized-first";
}
else if (reagent == recognized[^1])
{
// this loc specifically requires space to be appended, fluent doesnt support whitespace
msg.Append(' ');
part = "examinable-solution-recognized-last";
}
else
{
part = "examinable-solution-recognized-next";
}
msg.Append(Loc.GetString(part, ("color", reagent.SubstanceColor.ToHexNoAlpha()),
("chemical", reagent.LocalizedName)));
}
args.PushMarkup(Loc.GetString("examinable-solution-has-recognizable-chemicals", ("recognizedString", msg.ToString())));
}
public void UpdateAppearance(EntityUid uid, Solution solution,