Skip to content

Commit

Permalink
Merge pull request #2 from Carnagion/development
Browse files Browse the repository at this point in the history
Merge v1.0.1 into stable
  • Loading branch information
Carnagion authored Jun 29, 2022
2 parents 916eee5 + 0b62249 commit 6eb6cdf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
11 changes: 7 additions & 4 deletions Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ public static Metadata Load(string directoryPath)
directoryNode.InnerText = directoryPath;
document.DocumentElement.AppendChild(directoryNode);

Metadata metadata = new Serializer().Deserialize<Metadata>(document.DocumentElement)!;
return metadata.IsValid() ? metadata : throw new ModLoadException(directoryPath, "Invalid metadata");
return new Serializer().Deserialize<Metadata>(document.DocumentElement)!;
}
catch (Exception exception) when (exception is not ModLoadException)
{
throw new ModLoadException(directoryPath, exception);
}
}

private bool IsValid()
[AfterDeserialization]
private void IsValid()
{
// Check that the incompatible, load before, and load after lists don't have anything in common or contain the mod's own ID
bool invalidLoadOrder = this.Id.Yield()
Expand All @@ -260,7 +260,10 @@ private bool IsValid()
bool invalidDependencies = this.Dependencies
.Intersect(this.Incompatible)
.Any();
return !(invalidLoadOrder || invalidDependencies);
if (invalidLoadOrder || invalidDependencies)
{
throw new ModLoadException(this.Directory, "Invalid metadata");
}
}
}
}
Expand Down
24 changes: 10 additions & 14 deletions ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Mod LoadMod(string modDirectoryPath, bool executeAssemblies = true
ModLoader.loadedMods.Add(mod.Meta.Id, mod);
if (executeAssemblies)
{
ModLoader.StartupMods(mod.Yield());
ModLoader.StartupMod(mod);
}
return mod;
}
Expand All @@ -59,24 +59,20 @@ public static IEnumerable<Mod> LoadMods(IEnumerable<string> modDirectoryPaths, b
mods.ForEach(mod => ModLoader.loadedMods.Add(mod.Meta.Id, mod));
if (executeAssemblies)
{
ModLoader.StartupMods(mods);
mods.ForEach(ModLoader.StartupMod);
}
return mods;
}
private static void StartupMods(IEnumerable<Mod> mods)

private static void StartupMod(Mod mod)
{
// Invoke all static methods annotated with [Startup] along with the supplied parameters (if any)
foreach ((MethodInfo method, ModStartupAttribute attribute) in from mod in mods
from assembly in mod.Assemblies
from type in assembly.GetTypes()
from method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public)
let attribute = method.GetCustomAttribute<ModStartupAttribute>()
where attribute is not null
select (method, attribute))
{
method.Invoke(null, attribute.Parameters);
}
(from assembly in mod.Assemblies
from type in assembly.GetTypes()
from method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public)
let attribute = method.GetCustomAttribute<ModStartupAttribute>()
where attribute is not null
select (method, attribute)).ForEach(pair => pair.method.Invoke(null, pair.attribute.Parameters));
}

[MustUseReturnValue]
Expand Down
26 changes: 8 additions & 18 deletions Modot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,26 @@
<Nullable>enable</Nullable>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Godot.Modding</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Workaround as Godot does not know how to properly load NuGet packages -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.0.0</PackageVersion>
<PackageVersion>1.0.1</PackageVersion>
<Title>Modot</Title>
<Authors>Carnagion</Authors>
<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>
<RepositoryUrl>https://github.com/Carnagion/Modot</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\Debug\Modot.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ExportDebug' ">
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\ExportDebug\Modot.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ExportRelease' ">
<DocumentationFile>C:\Users\Indraneel\Projects\Modot\.mono\temp\bin\ExportRelease\Modot.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="GDSerializer" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GDLogger" Version="1.0.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageReference Include="GDLogger" Version="1.0.1"/>
<PackageReference Include="GDSerializer" Version="1.1.0"/>
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0"/>
</ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
<Content Include="LICENSE" />
<Content Include="README.md" />
<Content Include=".gitignore"/>
<Content Include="LICENSE"/>
<Content Include="README.md"/>
</ItemGroup>
<ItemGroup>
<None Include="LICENSE" Pack="true" PackagePath=""/>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A more detailed explanation of all features along with instructions on usage is
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):
```xml
<ItemGroup>
<PackageReference Include="Modot" Version="1.0.0"/>
<PackageReference Include="Modot" Version="1.0.1"/>
</ItemGroup>
```

Expand Down

0 comments on commit 6eb6cdf

Please sign in to comment.