From 475c5cc261604f419a8c81b1a088da8204801989 Mon Sep 17 00:00:00 2001 From: ritorizo Date: Mon, 6 Jan 2025 04:25:53 +0100 Subject: [PATCH 1/4] Treat the dir of the DME as a ressource dir --- Content.Tests/DMProject/environment.dme | 3 --- DMCompiler/DMCompiler.cs | 14 +++++++++----- TestGame/environment.dme | 3 --- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Content.Tests/DMProject/environment.dme b/Content.Tests/DMProject/environment.dme index 4aba6808f5..c10f4c982f 100644 --- a/Content.Tests/DMProject/environment.dme +++ b/Content.Tests/DMProject/environment.dme @@ -1,8 +1,5 @@ // BEGIN_INTERNALS // END_INTERNALS -// BEGIN_FILE_DIR -#define FILE_DIR . -// END_FILE_DIR // BEGIN_PREFERENCES // END_PREFERENCES // BEGIN_INCLUDE diff --git a/DMCompiler/DMCompiler.cs b/DMCompiler/DMCompiler.cs index d386a8e69f..824102b13c 100644 --- a/DMCompiler/DMCompiler.cs +++ b/DMCompiler/DMCompiler.cs @@ -128,9 +128,13 @@ public void AddResourceDirectory(string dir) { preproc.IncludeFile(includeDir, fileName, false); } + // Adds the root of the DM project to FILE_DIR + compiler.AddResourceDirectory(Path.GetDirectoryName(files[0])); + string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty; string dmStandardDirectory = Path.Join(compilerDirectory, "DMStandard"); + // Push DMStandard to the top of the stack, prioritizing it. if (!Settings.NoStandard) { preproc.IncludeFile(dmStandardDirectory, "_Standard.dm", true); @@ -139,7 +143,7 @@ public void AddResourceDirectory(string dir) { // Push the pragma config file to the tippy-top of the stack, super-duper prioritizing it, since it governs some compiler behaviour. string pragmaName; string pragmaDirectory; - if(Settings.PragmaFileOverride is not null) { + if (Settings.PragmaFileOverride is not null) { pragmaDirectory = Path.GetDirectoryName(Settings.PragmaFileOverride); pragmaName = Path.GetFileName(Settings.PragmaFileOverride); } else { @@ -147,7 +151,7 @@ public void AddResourceDirectory(string dir) { pragmaName = "DefaultPragmaConfig.dm"; } - if(!File.Exists(Path.Join(pragmaDirectory,pragmaName))) { + if (!File.Exists(Path.Join(pragmaDirectory, pragmaName))) { ForcedError($"Configuration file '{pragmaName}' not found."); return null; } @@ -336,7 +340,7 @@ private string SaveJson(List maps, string interfaceFile, string ou try { JsonSerializer.Serialize(outputFileHandle, compiledDream, - new JsonSerializerOptions() {DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault}); + new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault }); return $"Saved to {outputFile}"; } catch (Exception e) { @@ -349,7 +353,7 @@ private string SaveJson(List maps, string interfaceFile, string ou public void DefineFatalErrors() { foreach (WarningCode code in Enum.GetValues()) { - if((int)code < 1_000) { + if ((int)code < 1_000) { Config.ErrorConfig[code] = ErrorLevel.Error; } } @@ -359,7 +363,7 @@ public void DefineFatalErrors() { /// This method also enforces the rule that all emissions with codes less than 1000 are mandatory errors. /// public void CheckAllPragmasWereSet() { - foreach(WarningCode code in Enum.GetValues()) { + foreach (WarningCode code in Enum.GetValues()) { if (!Config.ErrorConfig.ContainsKey(code)) { ForcedWarning($"Warning #{(int)code:d4} '{code.ToString()}' was never declared as error, warning, notice, or disabled."); Config.ErrorConfig.Add(code, ErrorLevel.Disabled); diff --git a/TestGame/environment.dme b/TestGame/environment.dme index 8b6043085f..50d4f02a5b 100644 --- a/TestGame/environment.dme +++ b/TestGame/environment.dme @@ -1,8 +1,5 @@ // BEGIN_INTERNALS // END_INTERNALS -// BEGIN_FILE_DIR -#define FILE_DIR . -// END_FILE_DIR // BEGIN_PREFERENCES // END_PREFERENCES // BEGIN_INCLUDE From f5c46783ebb92509a537526af250dc123ddc6d09 Mon Sep 17 00:00:00 2001 From: ritorizo <41831966+ritorizo@users.noreply.github.com> Date: Wed, 8 Jan 2025 06:37:19 +0100 Subject: [PATCH 2/4] Update DMCompiler/DMCompiler.cs Co-authored-by: wixoa --- DMCompiler/DMCompiler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/DMCompiler/DMCompiler.cs b/DMCompiler/DMCompiler.cs index 824102b13c..bf613ab2bd 100644 --- a/DMCompiler/DMCompiler.cs +++ b/DMCompiler/DMCompiler.cs @@ -134,7 +134,6 @@ public void AddResourceDirectory(string dir) { string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty; string dmStandardDirectory = Path.Join(compilerDirectory, "DMStandard"); - // Push DMStandard to the top of the stack, prioritizing it. if (!Settings.NoStandard) { preproc.IncludeFile(dmStandardDirectory, "_Standard.dm", true); From 7eb072ebf5e40cb3c84d7f860cd6e80f706c7ea7 Mon Sep 17 00:00:00 2001 From: ritorizo <41831966+ritorizo@users.noreply.github.com> Date: Wed, 8 Jan 2025 06:38:42 +0100 Subject: [PATCH 3/4] Update DMCompiler/DMCompiler.cs Co-authored-by: wixoa --- DMCompiler/DMCompiler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DMCompiler/DMCompiler.cs b/DMCompiler/DMCompiler.cs index bf613ab2bd..25f6e9a5f3 100644 --- a/DMCompiler/DMCompiler.cs +++ b/DMCompiler/DMCompiler.cs @@ -129,7 +129,7 @@ public void AddResourceDirectory(string dir) { } // Adds the root of the DM project to FILE_DIR - compiler.AddResourceDirectory(Path.GetDirectoryName(files[0])); + compiler.AddResourceDirectory(Path.GetDirectoryName(files[0]) ?? "/"); string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty; string dmStandardDirectory = Path.Join(compilerDirectory, "DMStandard"); From 5376b205ba683b7028a3f7babe0c9b658ca88d9b Mon Sep 17 00:00:00 2001 From: ritorizo Date: Wed, 8 Jan 2025 06:44:00 +0100 Subject: [PATCH 4/4] return the #define FILE_DIR --- Content.Tests/DMProject/environment.dme | 3 +++ TestGame/environment.dme | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Content.Tests/DMProject/environment.dme b/Content.Tests/DMProject/environment.dme index c10f4c982f..4aba6808f5 100644 --- a/Content.Tests/DMProject/environment.dme +++ b/Content.Tests/DMProject/environment.dme @@ -1,5 +1,8 @@ // BEGIN_INTERNALS // END_INTERNALS +// BEGIN_FILE_DIR +#define FILE_DIR . +// END_FILE_DIR // BEGIN_PREFERENCES // END_PREFERENCES // BEGIN_INCLUDE diff --git a/TestGame/environment.dme b/TestGame/environment.dme index 50d4f02a5b..8b6043085f 100644 --- a/TestGame/environment.dme +++ b/TestGame/environment.dme @@ -1,5 +1,8 @@ // BEGIN_INTERNALS // END_INTERNALS +// BEGIN_FILE_DIR +#define FILE_DIR . +// END_FILE_DIR // BEGIN_PREFERENCES // END_PREFERENCES // BEGIN_INCLUDE