Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for ressources in the dirrectory of the environement #2157

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Content.Tests/DMProject/environment.dme
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// BEGIN_INTERNALS
// END_INTERNALS
// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR
ritorizo marked this conversation as resolved.
Show resolved Hide resolved
// BEGIN_PREFERENCES
// END_PREFERENCES
// BEGIN_INCLUDE
Expand Down
14 changes: 9 additions & 5 deletions DMCompiler/DMCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@
ForcedWarning("Unimplemented proc & var warnings are currently suppressed");
}

DMPreprocessor preprocessor = Preprocess(this, settings.Files, settings.MacroDefines);

Check warning on line 69 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible null reference argument for parameter 'files' in 'DMPreprocessor? DMCompiler.Preprocess(DMCompiler compiler, List<string> files, Dictionary<string, string>? macroDefines)'.

Check warning on line 69 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.
bool successfulCompile = preprocessor is not null && Compile(preprocessor);

if (successfulCompile) {
//Output file is the first file with the extension changed to .json
string outputFile = Path.ChangeExtension(settings.Files[0], "json");
List<DreamMapJson> maps = ConvertMaps(this, preprocessor.IncludedMaps);

Check warning on line 75 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.

if (ErrorCount > 0) {
successfulCompile = false;
} else {
var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile);

Check warning on line 80 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible null reference argument for parameter 'interfaceFile' in 'string DMCompiler.SaveJson(List<DreamMapJson> maps, string interfaceFile, string outputFile)'.
if (ErrorCount > 0) {
successfulCompile = false;
} else {
Expand Down Expand Up @@ -128,9 +128,13 @@
preproc.IncludeFile(includeDir, fileName, false);
}

// Adds the root of the DM project to FILE_DIR
compiler.AddResourceDirectory(Path.GetDirectoryName(files[0]));
Fixed Show fixed Hide fixed
ritorizo marked this conversation as resolved.
Show resolved Hide resolved

string compilerDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
string dmStandardDirectory = Path.Join(compilerDirectory, "DMStandard");


ritorizo marked this conversation as resolved.
Show resolved Hide resolved
// Push DMStandard to the top of the stack, prioritizing it.
if (!Settings.NoStandard) {
preproc.IncludeFile(dmStandardDirectory, "_Standard.dm", true);
Expand All @@ -139,15 +143,15 @@
// 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 {
pragmaDirectory = dmStandardDirectory;
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;
}
Expand Down Expand Up @@ -336,7 +340,7 @@

try {
JsonSerializer.Serialize(outputFileHandle, compiledDream,
new JsonSerializerOptions() {DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault});
new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault });

return $"Saved to {outputFile}";
} catch (Exception e) {
Expand All @@ -349,7 +353,7 @@

public void DefineFatalErrors() {
foreach (WarningCode code in Enum.GetValues<WarningCode>()) {
if((int)code < 1_000) {
if ((int)code < 1_000) {
Config.ErrorConfig[code] = ErrorLevel.Error;
}
}
Expand All @@ -359,7 +363,7 @@
/// This method also enforces the rule that all emissions with codes less than 1000 are mandatory errors.
/// </summary>
public void CheckAllPragmasWereSet() {
foreach(WarningCode code in Enum.GetValues<WarningCode>()) {
foreach (WarningCode code in Enum.GetValues<WarningCode>()) {
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);
Expand Down
3 changes: 0 additions & 3 deletions TestGame/environment.dme
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// BEGIN_INTERNALS
// END_INTERNALS
// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR
ritorizo marked this conversation as resolved.
Show resolved Hide resolved
// BEGIN_PREFERENCES
// END_PREFERENCES
// BEGIN_INCLUDE
Expand Down
Loading