From 1ce8cb8cacdbd62d63d933495bea337319975bda Mon Sep 17 00:00:00 2001 From: Oiltanker Date: Sun, 15 May 2022 16:06:31 +0300 Subject: [PATCH] cs RunConfig fix --- .../SharedSource/LuaCs/Cs/CsScriptLoader.cs | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs index 7c439129d..f078db7c4 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptLoader.cs @@ -36,9 +36,9 @@ namespace Barotrauma } private enum RunType { Standard, Forced, None }; - private RunType GetRunType(ContentPackage cp, string path) + private bool ShouldRun(ContentPackage cp, string path) { - if (!Directory.Exists(path + "CSharp")) return RunType.None; + if (!Directory.Exists(path + "CSharp")) return false; var isEnabled = ContentPackageManager.EnabledPackages.All.Contains(cp); if (File.Exists(path + "CSharp/RunConfig.xml")) @@ -47,30 +47,45 @@ namespace Barotrauma var elems = doc.Root.Elements().ToArray(); var elem = elems.FirstOrDefault(e => e.Name.LocalName.Equals(LuaCsSetup.IsServer ? "Server" : (LuaCsSetup.IsClient ? "Client" : "None"), StringComparison.OrdinalIgnoreCase)); - if (elem != null && Enum.TryParse(typeof(RunType), elem.Value, out object enumValue) && enumValue is RunType rtValue) + if (elem != null && Enum.TryParse(elem.Value, true, out RunType rtValue)) { - if (rtValue == RunType.Standard && isEnabled) LuaCsSetup.PrintCsMessage($"Standard run C# of {cp.Name}"); - else if (rtValue == RunType.Forced) LuaCsSetup.PrintCsMessage($"Forced run C# of {cp.Name}"); - return rtValue; + if (rtValue == RunType.Standard && isEnabled) + { + LuaCsSetup.PrintCsMessage($"Standard run C# of {cp.Name}"); + return true; + } + else if (rtValue == RunType.Forced) + { + LuaCsSetup.PrintCsMessage($"Forced run C# of {cp.Name}"); + return true; + } + else if (rtValue == RunType.None) return false; } } if (isEnabled) { LuaCsSetup.PrintCsMessage($"Assumed run C# of {cp.Name}"); - return RunType.Standard; + return true; } - else return RunType.None; + else return false; } public void SearchFolders() { - var paths = new List(); + var paths = new Dictionary(); foreach (var cp in ContentPackageManager.AllPackages) { var path = $"{Path.GetFullPath(Path.GetDirectoryName(cp.Path)).Replace('\\','/')}/"; - if (GetRunType(cp, path) != RunType.None) paths.Add(path); + if (ShouldRun(cp, path)) + { + if (paths.ContainsKey(cp.Name)) + { + if (ContentPackageManager.EnabledPackages.All.Contains(cp)) paths[cp.Name] = path; + } + else paths.Add(cp.Name, path); + } } - paths.ForEach(p => RunFolder(p)); + foreach ((var _, var path) in paths) RunFolder(path); } public bool HasSources { get => sources.Count > 0; }