forked from michaelchessall/SS14-Persistence
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuideReagentGroupEmbed.xaml.cs
More file actions
109 lines (101 loc) · 3.95 KB
/
GuideReagentGroupEmbed.xaml.cs
File metadata and controls
109 lines (101 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Content.Client.Guidebook.Richtext;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Content.Shared.Chemistry.Reaction;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace Content.Client.Guidebook.Controls;
/// <summary>
/// Control for embedding a reagent into a guidebook.
/// </summary>
[UsedImplicitly, GenerateTypedNameReferences]
public sealed partial class GuideReagentGroupEmbed : BoxContainer, IDocumentTag
{
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
private readonly ISawmill _sawmill;
public GuideReagentGroupEmbed()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sawmill = _logManager.GetSawmill("guidebook.reagent_group");
MouseFilter = MouseFilterMode.Stop;
}
public GuideReagentGroupEmbed(string group) : this()
{
if (group == "Precipitate")
{
var prototypes = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => !p.Source && p.Effects.Length >= 1)
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}
else
{
var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}
}
public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
{
control = null;
if (!args.TryGetValue("Group", out var group))
{
_sawmill.Error("Reagent group embed tag is missing group argument");
return false;
}
if (group == "Precipitate")
{
Dictionary<string, GuideReagentEmbed> precipitateDict = new Dictionary<string, GuideReagentEmbed>();
var prototypes = _prototype.EnumeratePrototypes<ReactionPrototype>()
.Where(p => !p.Source && p.Effects.Length >= 1)
.OrderBy(p => p.Priority)
.ThenBy(p => p.Products.Count)
.ToList();
foreach (var reagent in prototypes)
{
if (reagent.Effects.Length < 1)
continue;
IEnumerable<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity> spawnEvents = reagent.Effects.OfType<Shared.EntityEffects.Effects.EntitySpawning.SpawnEntity>();
if (spawnEvents.Count() == 0)
continue;
var spawnId = _prototype.Index<EntityPrototype>(spawnEvents.First().Entity).Name;
if (precipitateDict.ContainsKey(spawnId))
continue;
precipitateDict.Add(spawnId, new GuideReagentEmbed(reagent));
}
foreach (var key in precipitateDict.Keys.OrderBy(k => k))
{
GroupContainer.AddChild(precipitateDict[key]);
}
}
else
{
var prototypes = _prototype.EnumeratePrototypes<ReagentPrototype>()
.Where(p => p.Group.Equals(group)).OrderBy(p => p.LocalizedName);
foreach (var reagent in prototypes)
{
var embed = new GuideReagentEmbed(reagent);
GroupContainer.AddChild(embed);
}
}
control = this;
return true;
}
}