Content PR for YAML hot reloading (#3319)
* Content PR for YAML hot reloading * Add CanAdminReloadPrototypes (host permission) * IndexedPrototype fixes
This commit is contained in:
@@ -12,23 +12,29 @@ namespace Content.Shared.Alert
|
||||
[Prototype("alertOrder")]
|
||||
public class AlertOrderPrototype : IPrototype, IComparer<AlertPrototype>
|
||||
{
|
||||
public string ID { get; private set; }
|
||||
|
||||
private readonly Dictionary<AlertType, int> _typeToIdx = new();
|
||||
private readonly Dictionary<AlertCategory, int> _categoryToIdx = new();
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
var serializer = YamlObjectSerializer.NewReader(mapping);
|
||||
|
||||
serializer.DataField(this, x => x.ID, "id", string.Empty);
|
||||
|
||||
if (!mapping.TryGetNode("order", out YamlSequenceNode orderMapping)) return;
|
||||
|
||||
int i = 0;
|
||||
var i = 0;
|
||||
foreach (var entryYaml in orderMapping)
|
||||
{
|
||||
var orderEntry = (YamlMappingNode) entryYaml;
|
||||
var serializer = YamlObjectSerializer.NewReader(orderEntry);
|
||||
if (serializer.TryReadDataField("category", out AlertCategory alertCategory))
|
||||
var orderSerializer = YamlObjectSerializer.NewReader(orderEntry);
|
||||
if (orderSerializer.TryReadDataField("category", out AlertCategory alertCategory))
|
||||
{
|
||||
_categoryToIdx[alertCategory] = i++;
|
||||
}
|
||||
else if (serializer.TryReadDataField("alertType", out AlertType alertType))
|
||||
else if (orderSerializer.TryReadDataField("alertType", out AlertType alertType))
|
||||
{
|
||||
_typeToIdx[alertType] = i++;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace Content.Shared.Alert
|
||||
[Prototype("alert")]
|
||||
public class AlertPrototype : IPrototype
|
||||
{
|
||||
public string ID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Type of alert, no 2 alert prototypes should have the same one.
|
||||
/// </summary>
|
||||
@@ -94,7 +96,11 @@ namespace Content.Shared.Alert
|
||||
serializer.DataField(ref _minSeverity, "minSeverity", (short) 1);
|
||||
|
||||
serializer.DataReadFunction("name", string.Empty,
|
||||
s => Name = FormattedMessage.FromMarkup(s));
|
||||
s =>
|
||||
{
|
||||
ID = s;
|
||||
Name = FormattedMessage.FromMarkup(s);
|
||||
});
|
||||
serializer.DataReadFunction("description", string.Empty,
|
||||
s => Description = FormattedMessage.FromMarkup(s));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user