Use YamlDotNet to load patrons JSON file.
So that i don't have to add Newtonsoft.Json stuff to the sandbox whitelist. YAML is a JSON superset after all...
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Newtonsoft.Json;
|
||||
using Robust.Client.Credits;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -13,6 +12,7 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
@@ -82,7 +82,7 @@ namespace Content.Client.UserInterface
|
||||
var margin = new MarginContainer {MarginLeftOverride = 2, MarginTopOverride = 2};
|
||||
var vBox = new VBoxContainer();
|
||||
margin.AddChild(vBox);
|
||||
var patrons = ReadJson<PatronEntry[]>("/Credits/Patrons.json");
|
||||
var patrons = LoadPatrons();
|
||||
|
||||
Button patronButton;
|
||||
vBox.AddChild(patronButton = new Button
|
||||
@@ -117,6 +117,16 @@ namespace Content.Client.UserInterface
|
||||
patronsList.AddChild(margin);
|
||||
}
|
||||
|
||||
private IEnumerable<PatronEntry> LoadPatrons()
|
||||
{
|
||||
var yamlStream = _resourceManager.ContentFileReadYaml(new ResourcePath("/Credits/Patrons.json"));
|
||||
var sequence = (YamlSequenceNode) yamlStream.Documents[0].RootNode;
|
||||
|
||||
return sequence
|
||||
.Cast<YamlMappingNode>()
|
||||
.Select(m => new PatronEntry(m["Name"].AsString(), m["Tier"].AsString()));
|
||||
}
|
||||
|
||||
private void PopulateCredits(Control contributorsList)
|
||||
{
|
||||
Button contributeButton;
|
||||
@@ -141,6 +151,7 @@ namespace Content.Client.UserInterface
|
||||
});
|
||||
|
||||
var first = true;
|
||||
|
||||
void AddSection(string title, string path, bool markup = false)
|
||||
{
|
||||
if (!first)
|
||||
@@ -190,29 +201,16 @@ namespace Content.Client.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
private T ReadJson<T>(string path)
|
||||
{
|
||||
var serializer = new JsonSerializer();
|
||||
|
||||
using var stream = _resourceManager.ContentFileRead(path);
|
||||
using var streamReader = new StreamReader(stream);
|
||||
using var jsonTextReader = new JsonTextReader(streamReader);
|
||||
|
||||
return serializer.Deserialize<T>(jsonTextReader)!;
|
||||
}
|
||||
|
||||
[JsonObject(ItemRequired = Required.Always)]
|
||||
private sealed class PatronEntry
|
||||
{
|
||||
public string Name { get; set; } = default!;
|
||||
public string Tier { get; set; } = default!;
|
||||
}
|
||||
public string Name { get; }
|
||||
public string Tier { get; }
|
||||
|
||||
[JsonObject(ItemRequired = Required.Always)]
|
||||
private sealed class OpenSourceLicense
|
||||
public PatronEntry(string name, string tier)
|
||||
{
|
||||
public string Name { get; set; } = default!;
|
||||
public string License { get; set; } = default!;
|
||||
Name = name;
|
||||
Tier = tier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user