Add a way for bulk abstracting prototypes (#24140)
* Ignored Prototypes * respath it * add multi-file support
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Content.Shared.Humanoid.Markings;
|
||||
using Content.Shared.IoC;
|
||||
using Content.Shared.Localizations;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Sequence;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Entry
|
||||
{
|
||||
@@ -18,6 +20,9 @@ namespace Content.Shared.Entry
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||
[Dependency] private readonly IResourceManager _resMan = default!;
|
||||
|
||||
private readonly ResPath _ignoreFileDirectory = new("/IgnoredPrototypes/");
|
||||
|
||||
public override void PreInit()
|
||||
{
|
||||
@@ -32,6 +37,7 @@ namespace Content.Shared.Entry
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
IgnorePrototypes();
|
||||
}
|
||||
|
||||
public override void PostInit()
|
||||
@@ -96,5 +102,48 @@ namespace Content.Shared.Entry
|
||||
def.AssignTileId(_tileDefinitionManager[def.ID].TileId);
|
||||
}
|
||||
}
|
||||
|
||||
private void IgnorePrototypes()
|
||||
{
|
||||
if (!TryReadFile(out var sequences))
|
||||
return;
|
||||
|
||||
foreach (var sequence in sequences)
|
||||
{
|
||||
foreach (var node in sequence.Sequence)
|
||||
{
|
||||
var path = new ResPath(((ValueDataNode) node).Value);
|
||||
|
||||
if (string.IsNullOrEmpty(path.Extension))
|
||||
{
|
||||
_prototypeManager.AbstractDirectory(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
_prototypeManager.AbstractFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryReadFile([NotNullWhen(true)] out List<SequenceDataNode>? sequence)
|
||||
{
|
||||
sequence = new();
|
||||
|
||||
foreach (var path in _resMan.ContentFindFiles(_ignoreFileDirectory))
|
||||
{
|
||||
if (!_resMan.TryContentFileRead(path, out var stream))
|
||||
continue;
|
||||
|
||||
using var reader = new StreamReader(stream, EncodingHelpers.UTF8);
|
||||
var documents = DataNodeParser.ParseYamlStream(reader).FirstOrDefault();
|
||||
|
||||
if (documents == null)
|
||||
continue;
|
||||
|
||||
sequence.Add((SequenceDataNode) documents.Root);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
Resources/IgnoredPrototypes/ignoredPrototypes.yml
Normal file
8
Resources/IgnoredPrototypes/ignoredPrototypes.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
# This is a basic list that specifies files for which the prototypes inside of them will be made abstract.
|
||||
# This supports all prototype kinds and is intended to allow servers to remove prototypes in a relatively clean way.
|
||||
# This method does not break inheritance, but you will still have to remove usages.
|
||||
|
||||
# e.g., you can specify both directories and specific files by adding lines like:
|
||||
#
|
||||
# - /Prototypes/Guidebook
|
||||
# - /Prototypes/Catalog/uplink_catalog.yml
|
||||
Reference in New Issue
Block a user