Skip to content

Commit 6eb6cdf

Browse files
authored
Merge pull request #2 from Carnagion/development
Merge v1.0.1 into stable
2 parents 916eee5 + 0b62249 commit 6eb6cdf

File tree

4 files changed

+26
-37
lines changed

4 files changed

+26
-37
lines changed

Mod.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,16 @@ public static Metadata Load(string directoryPath)
238238
directoryNode.InnerText = directoryPath;
239239
document.DocumentElement.AppendChild(directoryNode);
240240

241-
Metadata metadata = new Serializer().Deserialize<Metadata>(document.DocumentElement)!;
242-
return metadata.IsValid() ? metadata : throw new ModLoadException(directoryPath, "Invalid metadata");
241+
return new Serializer().Deserialize<Metadata>(document.DocumentElement)!;
243242
}
244243
catch (Exception exception) when (exception is not ModLoadException)
245244
{
246245
throw new ModLoadException(directoryPath, exception);
247246
}
248247
}
249248

250-
private bool IsValid()
249+
[AfterDeserialization]
250+
private void IsValid()
251251
{
252252
// Check that the incompatible, load before, and load after lists don't have anything in common or contain the mod's own ID
253253
bool invalidLoadOrder = this.Id.Yield()
@@ -260,7 +260,10 @@ private bool IsValid()
260260
bool invalidDependencies = this.Dependencies
261261
.Intersect(this.Incompatible)
262262
.Any();
263-
return !(invalidLoadOrder || invalidDependencies);
263+
if (invalidLoadOrder || invalidDependencies)
264+
{
265+
throw new ModLoadException(this.Directory, "Invalid metadata");
266+
}
264267
}
265268
}
266269
}

ModLoader.cs

+10-14
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Mod LoadMod(string modDirectoryPath, bool executeAssemblies = true
4040
ModLoader.loadedMods.Add(mod.Meta.Id, mod);
4141
if (executeAssemblies)
4242
{
43-
ModLoader.StartupMods(mod.Yield());
43+
ModLoader.StartupMod(mod);
4444
}
4545
return mod;
4646
}
@@ -59,24 +59,20 @@ public static IEnumerable<Mod> LoadMods(IEnumerable<string> modDirectoryPaths, b
5959
mods.ForEach(mod => ModLoader.loadedMods.Add(mod.Meta.Id, mod));
6060
if (executeAssemblies)
6161
{
62-
ModLoader.StartupMods(mods);
62+
mods.ForEach(ModLoader.StartupMod);
6363
}
6464
return mods;
6565
}
66-
67-
private static void StartupMods(IEnumerable<Mod> mods)
66+
67+
private static void StartupMod(Mod mod)
6868
{
6969
// Invoke all static methods annotated with [Startup] along with the supplied parameters (if any)
70-
foreach ((MethodInfo method, ModStartupAttribute attribute) in from mod in mods
71-
from assembly in mod.Assemblies
72-
from type in assembly.GetTypes()
73-
from method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public)
74-
let attribute = method.GetCustomAttribute<ModStartupAttribute>()
75-
where attribute is not null
76-
select (method, attribute))
77-
{
78-
method.Invoke(null, attribute.Parameters);
79-
}
70+
(from assembly in mod.Assemblies
71+
from type in assembly.GetTypes()
72+
from method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public)
73+
let attribute = method.GetCustomAttribute<ModStartupAttribute>()
74+
where attribute is not null
75+
select (method, attribute)).ForEach(pair => pair.method.Invoke(null, pair.attribute.Parameters));
8076
}
8177

8278
[MustUseReturnValue]

Modot.csproj

+8-18
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,26 @@
44
<Nullable>enable</Nullable>
55
<TargetFramework>netstandard2.1</TargetFramework>
66
<RootNamespace>Godot.Modding</RootNamespace>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
78
<!-- Workaround as Godot does not know how to properly load NuGet packages -->
89
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
910
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10-
<PackageVersion>1.0.0</PackageVersion>
11+
<PackageVersion>1.0.1</PackageVersion>
1112
<Title>Modot</Title>
1213
<Authors>Carnagion</Authors>
1314
<Description>A mod loader and API for applications made using Godot, with the ability to load C# assemblies, XML data, and resource packs at runtime.</Description>
1415
<RepositoryUrl>https://github.com/Carnagion/Modot</RepositoryUrl>
1516
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1617
</PropertyGroup>
17-
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
18-
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\Debug\Modot.xml</DocumentationFile>
19-
</PropertyGroup>
20-
<PropertyGroup Condition=" '$(Configuration)' == 'ExportDebug' ">
21-
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\ExportDebug\Modot.xml</DocumentationFile>
22-
</PropertyGroup>
23-
<PropertyGroup Condition=" '$(Configuration)' == 'ExportRelease' ">
24-
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\ExportRelease\Modot.xml</DocumentationFile>
25-
</PropertyGroup>
26-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
27-
<PackageReference Include="GDSerializer" Version="1.0.0" />
28-
</ItemGroup>
2918
<ItemGroup>
30-
<PackageReference Include="GDLogger" Version="1.0.0" />
31-
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
19+
<PackageReference Include="GDLogger" Version="1.0.1"/>
20+
<PackageReference Include="GDSerializer" Version="1.1.0"/>
21+
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0"/>
3222
</ItemGroup>
3323
<ItemGroup>
34-
<Content Include=".gitignore" />
35-
<Content Include="LICENSE" />
36-
<Content Include="README.md" />
24+
<Content Include=".gitignore"/>
25+
<Content Include="LICENSE"/>
26+
<Content Include="README.md"/>
3727
</ItemGroup>
3828
<ItemGroup>
3929
<None Include="LICENSE" Pack="true" PackagePath=""/>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A more detailed explanation of all features along with instructions on usage is
1919
Simply include the following lines in a Godot project's `.csproj` file (either by editing the file manually or letting an IDE install the package):
2020
```xml
2121
<ItemGroup>
22-
<PackageReference Include="Modot" Version="1.0.0"/>
22+
<PackageReference Include="Modot" Version="1.0.1"/>
2323
</ItemGroup>
2424
```
2525

0 commit comments

Comments
 (0)