Skip to content

Commit

Permalink
properly implements .yaml handling in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRitter committed Feb 6, 2023
1 parent 0eba350 commit d8d2993
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ indent_size = 4
trim_trailing_whitespace = true
charset = utf-8

[*.{csproj,xml,yml,dll.config,targets,props}]
[*.{csproj,xml,yml,yaml,dll.config,targets,props}]
indent_size = 2

[*.gdsl]
Expand Down
23 changes: 17 additions & 6 deletions Robust.Client/Prototypes/ClientPrototypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Robust.Client.Timing;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;
Expand Down Expand Up @@ -87,13 +86,20 @@ private void WatchResources()
foreach (var path in Resources.GetContentRoots().Select(r => r.ToString())
.Where(r => Directory.Exists(r + "/Prototypes")).Select(p => p + "/Prototypes"))
{
var watcher = new FileSystemWatcher(path, "*.yml")
var watcherYml = new FileSystemWatcher(path, "*.yml")
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastWrite
};

watcher.Changed += (_, args) =>
//filesystemwatcher doesnt support multiple filters, so we gotta do this. its a debug feature, so i dont think its that critical
var watcherYaml = new FileSystemWatcher(path, "*.yaml")
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastWrite
};

void OnWatcherOnChanged(object _, FileSystemEventArgs args)
{
switch (args.ChangeType)
{
Expand Down Expand Up @@ -123,12 +129,17 @@ private void WatchResources()
_reloadQueue.Add(relative);
}
});
};
}

watcherYml.Changed += OnWatcherOnChanged;
watcherYaml.Changed += OnWatcherOnChanged;

try
{
watcher.EnableRaisingEvents = true;
_watchers.Add(watcher);
watcherYml.EnableRaisingEvents = true;
watcherYaml.EnableRaisingEvents = true;
_watchers.Add(watcherYml);
_watchers.Add(watcherYaml);
}
catch (IOException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class AssetPassNormalizeText : AssetPass
"txt",
"json",
"yml",
"yaml",
"html",
"css",
"js",
Expand Down
4 changes: 2 additions & 2 deletions Robust.Shared/Prototypes/PrototypeManager.YamlLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void LoadDirectory(ResourcePath path, bool overwrite = false,
{
_hasEverBeenReloaded = true;
var streams = Resources.ContentFindFiles(path)
.Where(filePath => filePath.Extension is "yml" or "yaml" && !filePath.Filename.StartsWith("."))
.Where(ResourcePath.IsYamlResourceFile)
.ToArray();

// Shuffle to avoid input data patterns causing uneven thread workloads.
Expand Down Expand Up @@ -84,7 +84,7 @@ public void LoadDirectory(ResourcePath path, bool overwrite = false,
public Dictionary<string, HashSet<ErrorNode>> ValidateDirectory(ResourcePath path)
{
var streams = Resources.ContentFindFiles(path).ToList().AsParallel()
.Where(filePath => filePath.Extension is "yml" or "yaml" && !filePath.Filename.StartsWith("."));
.Where(ResourcePath.IsYamlResourceFile);

var dict = new Dictionary<string, HashSet<ErrorNode>>();
foreach (var resourcePath in streams)
Expand Down
6 changes: 6 additions & 0 deletions Robust.Shared/Utility/ResourcePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,5 +717,11 @@ private static void ValidateSeparate(string separator)
throw new ArgumentException("Separator may not be . or ..");
}
}

public static bool IsYamlResourceFile(ResourcePath filePath)
{
return filePath.Extension is "yml" or "yaml" &&
!filePath.Filename.StartsWith(".", StringComparison.Ordinal);
}
}
}

0 comments on commit d8d2993

Please sign in to comment.