Skip to content

Commit

Permalink
Show mod reports in mod list
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniMacaroni committed Nov 11, 2023
1 parent 73894ac commit 06b195f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
17 changes: 17 additions & 0 deletions SonsGameManager/ModManagerUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ internal static void Create()
scroll.Add(ModCard(data));
}

foreach (var report in SonsSdk.ModReport.ModReports)
{
scroll.Add(ModReportCard(report));
}

AddModsButton();

panel.Active(false);
Expand Down Expand Up @@ -149,6 +154,18 @@ private static SContainerOptions ModCard(ModCardData data)

return container;
}

private static SContainerOptions ModReportCard(ModReport.ModReportInfo data)
{
var container = SContainer.Background(Color.black.WithAlpha(0.5f), EBackground.None).PHeight(100)
- SLabel.RichText($"<color=#BBB>{data.ModId}</color>").FontSize(22)
.Font(EFont.RobotoRegular)
.Dock(EDockType.Fill).Alignment(TextAlignmentOptions.MidlineLeft).Margin(50, 0, 0, 0)
- SLabel.Text(data.Message).Alignment(TextAlignmentOptions.MidlineRight).Pivot(1).Anchor(AnchorType.MiddleRight)
.FontSize(15).Position(-250).FontColor("#dcdcaa");

return container;
}

private static SContainerOptions ModLoaderCard()
{
Expand Down
8 changes: 6 additions & 2 deletions SonsLoaderPlugin/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ private ResolvedMelons Resolver(MelonAssembly melonAssembly)
if (manifest.Platform == "Client" && LoaderEnvironment.IsDedicatedServer)
{
RLog.Error($"Mod {assembly.FullName} is a client mod and cannot be loaded on a dedicated server.");
ModReport.ReportMod(manifest.Id, "Client mod cannot be loaded on a dedicated server.");
}
else if (manifest.Platform == "Server" && !LoaderEnvironment.IsDedicatedServer)
{
RLog.Error($"Mod {assembly.FullName} is a server mod and cannot be loaded on a client.");
ModReport.ReportMod(manifest.Id, "Server mod cannot be loaded on a client.");
}
else if (!string.IsNullOrEmpty(manifest.LoaderVersion) && LoaderUtils.IsCompatible(manifest.LoaderVersion))
else if (!string.IsNullOrEmpty(manifest.LoaderVersion) && !LoaderUtils.IsCompatible(manifest.LoaderVersion))
{
RLog.Error($"Mod {assembly.FullName} requires a different version of RedLoader.");
LoaderUtils.ShowMessageBox($"Mod {manifest.Id} requires a newer version of RedLoader.");
//LoaderUtils.ShowMessageBox($"Mod {manifest.Id} requires a newer version of RedLoader.");
ModReport.ReportMod(manifest.Id, $"Requires RedLoader >={manifest.LoaderVersion}");
}
else if (InitMod(melonAssembly, manifest, out var mod))
{
Expand All @@ -58,6 +61,7 @@ private ResolvedMelons Resolver(MelonAssembly melonAssembly)
else
{
RLog.Error($"{assembly.FullName} does not have a manifest.json file.");
ModReport.ReportMod(assembly.GetName().Name, "Missing manifest.json");
}

return new ResolvedMelons(melons.ToArray(), rottenMelons.ToArray());
Expand Down
21 changes: 21 additions & 0 deletions SonsSdk/ModReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace SonsSdk;

public static class ModReport
{
internal static List<ModReportInfo> ModReports = new();

public static void ReportMod(string modId, string message)
{
ModReports.Add(new ModReportInfo()
{
ModId = modId,
Message = message
});
}

public class ModReportInfo
{
public string ModId;
public string Message;
}
}

0 comments on commit 06b195f

Please sign in to comment.