- Removed all MoveImmute situations.
- Added filtering and ordering functions for package resources.
This commit is contained in:
@@ -15,6 +15,7 @@ bld/
|
||||
[Rr]eleaseMac/
|
||||
[Dd]ebugLinux/
|
||||
[Rr]eleaseLinux/
|
||||
LocalMods/
|
||||
*.o
|
||||
*/Barotrauma*/doc/
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ public sealed partial class ConfigService : IConfigService
|
||||
}));
|
||||
}
|
||||
|
||||
var taskResults = await Task.WhenAll(taskBuilder.MoveToImmutable());
|
||||
var taskResults = await Task.WhenAll(taskBuilder.ToImmutable());
|
||||
|
||||
if (toProcessErrors.Count > 0)
|
||||
{
|
||||
|
||||
@@ -354,7 +354,7 @@ public class EventService : IEventService, IEventAssemblyContextUnloading
|
||||
|
||||
public FluentResults.Result Reset()
|
||||
{
|
||||
((IService)this).CheckDisposed();
|
||||
IService.CheckDisposed(this);
|
||||
_subscriptions.Clear();
|
||||
_luaSubscriptionFactories.Clear();
|
||||
_eventTypeNameAliases.Clear();
|
||||
|
||||
+35
-8
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
using FluentResults;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
@@ -212,13 +213,19 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
// get loading order. Note: packages not in the execution order list will load first.
|
||||
var loadingOrderedPackages = _loadedPackages.OrderBy(pkg => executionOrder.IndexOf(pkg.Key))
|
||||
.ToImmutableArray();
|
||||
var loadOrderByPackage = loadingOrderedPackages.Select(p => p.Key).ToImmutableArray();
|
||||
var toLoadPackagesIndents = loadingOrderedPackages
|
||||
.SelectMany(p => p.Key.AltNames.Union(new []{ p.Key.Name }).ToIdentifiers())
|
||||
.ToImmutableHashSet();
|
||||
|
||||
|
||||
// NOTE: Config/Settings are instanced in LoadPackages()
|
||||
|
||||
//lua scripts
|
||||
var luaScripts = loadingOrderedPackages
|
||||
.SelectMany(pkg => pkg.Value.LuaScripts.OrderBy(scr => scr.LoadPriority))
|
||||
.ToImmutableArray();
|
||||
var luaScripts = SelectCompatible(loadingOrderedPackages
|
||||
.SelectMany(pkg => pkg.Value.LuaScripts)
|
||||
.ToImmutableArray(), toLoadPackagesIndents, loadOrderByPackage);
|
||||
|
||||
if (!luaScripts.IsDefaultOrEmpty)
|
||||
{
|
||||
result.WithReasons(_luaScriptManagementService.ExecuteLoadedScripts(luaScripts).Reasons);
|
||||
@@ -226,9 +233,10 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
|
||||
if (_runConfig.IsCsEnabled)
|
||||
{
|
||||
var plugins =
|
||||
loadingOrderedPackages.SelectMany(pkg => pkg.Value.Assemblies.OrderBy(scr => scr.LoadPriority))
|
||||
.ToImmutableArray();
|
||||
var plugins = SelectCompatible(loadingOrderedPackages
|
||||
.SelectMany(pkg => pkg.Value.Assemblies)
|
||||
.ToImmutableArray(), toLoadPackagesIndents, loadOrderByPackage);
|
||||
|
||||
if (!plugins.IsDefaultOrEmpty)
|
||||
{
|
||||
result.WithReasons(_pluginManagementService.LoadAssemblyResources(plugins).Reasons);
|
||||
@@ -239,10 +247,29 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
{
|
||||
_runningPackages[package.Key] = package.Value;
|
||||
}
|
||||
|
||||
|
||||
if (result.IsFailed)
|
||||
{
|
||||
_logger.LogResults(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static ImmutableArray<T> SelectCompatible<T>(ImmutableArray<T> resources, ImmutableHashSet<Identifier> enabledPackagesIdents, ImmutableArray<ContentPackage> loadingOrder)
|
||||
where T : IBaseResourceInfo
|
||||
{
|
||||
return resources
|
||||
.Where(r => r.SupportedPlatforms.HasFlag(ModUtils.Environment.CurrentPlatform))
|
||||
.Where(r => r.SupportedTargets.HasFlag(ModUtils.Environment.CurrentTarget))
|
||||
.Where(r => !r.Optional || (
|
||||
(r.RequiredPackages.IsDefaultOrEmpty || enabledPackagesIdents.Intersect(r.RequiredPackages).Any())
|
||||
&& (r.IncompatiblePackages.IsDefaultOrEmpty || enabledPackagesIdents.Intersect(r.IncompatiblePackages).None()))
|
||||
).OrderBy(r => loadingOrder.IndexOf(r.OwnerPackage))
|
||||
.ThenBy(r => r.LoadPriority)
|
||||
.ToImmutableArray();
|
||||
}
|
||||
|
||||
|
||||
public FluentResults.Result SyncLoadedPackagesList(ImmutableArray<ContentPackage> packages)
|
||||
{
|
||||
if (packages.IsDefaultOrEmpty)
|
||||
|
||||
@@ -15,6 +15,7 @@ using FluentResults;
|
||||
using FluentResults.LuaCs;
|
||||
using ImpromptuInterface.Build;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using OneOf;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
@@ -118,8 +119,8 @@ public class PluginManagementService : IPluginManagementService, IAssemblyManage
|
||||
{
|
||||
if (includeDefaultContext)
|
||||
{
|
||||
var type = Type.GetType(typeName, false);
|
||||
if (type is not null)
|
||||
var type = Type.GetType(typeName, false, false);
|
||||
if (type is not null && (includeInterfaces || !type.IsInterface))
|
||||
{
|
||||
if (isByRefType)
|
||||
{
|
||||
@@ -132,7 +133,7 @@ public class PluginManagementService : IPluginManagementService, IAssemblyManage
|
||||
|
||||
foreach (var ass in AssemblyLoadContext.All.SelectMany(alc => alc.Assemblies))
|
||||
{
|
||||
if (ass.GetType(typeName, false) is not { } type)
|
||||
if (ass.GetType(typeName, false, false) is not {} type || (!includeInterfaces && type.IsInterface))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -143,11 +144,14 @@ public class PluginManagementService : IPluginManagementService, IAssemblyManage
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource)
|
||||
public FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resources)
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Fail($"{nameof(LoadAssemblyResources)}: Plugin loading not currently implemented.");
|
||||
#endif
|
||||
IService.CheckDisposed(this);
|
||||
if (resources.IsDefaultOrEmpty)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException($"{nameof(LoadAssemblyResources)}: The resources list is empty!");
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -114,7 +114,7 @@ public sealed class SettingsFileParserService :
|
||||
}
|
||||
}
|
||||
|
||||
return FluentResults.Result.Ok(parsedInfo.MoveToImmutable());
|
||||
return FluentResults.Result.Ok(parsedInfo.ToImmutable());
|
||||
|
||||
// Helpers
|
||||
|
||||
@@ -196,12 +196,12 @@ public sealed class SettingsFileParserService :
|
||||
{
|
||||
InternalName = profileName,
|
||||
OwnerPackage = res.path.ContentPackage,
|
||||
ProfileValues = profileValuesBuilder.MoveToImmutable()
|
||||
ProfileValues = profileValuesBuilder.ToImmutable()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return parsedInfo.MoveToImmutable();
|
||||
return parsedInfo.ToImmutable();
|
||||
|
||||
FluentResults.Result ReturnFail(string msg)
|
||||
{
|
||||
|
||||
@@ -251,7 +251,7 @@ public class StorageService : IStorageService
|
||||
{
|
||||
builder.Add((path, LoadPackageData(path, dataLoader)));
|
||||
}
|
||||
return builder.MoveToImmutable();
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
|
||||
public ImmutableArray<(ContentPath, Result<XDocument>)> LoadPackageXmlFiles(ImmutableArray<ContentPath> filePaths)
|
||||
@@ -317,7 +317,7 @@ public class StorageService : IStorageService
|
||||
{
|
||||
builder.Add((path, await LoadPackageDataAsync(path, dataLoader)));
|
||||
}
|
||||
return builder.MoveToImmutable();
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
|
||||
public async Task<ImmutableArray<(ContentPath, Result<XDocument>)>> LoadPackageXmlFilesAsync(ImmutableArray<ContentPath> filePaths)
|
||||
|
||||
+2
-2
@@ -35,9 +35,9 @@ public interface IPluginManagementService : IReusableService
|
||||
/// <summary>
|
||||
/// Loads the provided assembly resources in the order of their dependencies and intra-mod priority load order.
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="resources"></param>
|
||||
/// <returns>Success/Failure and list of failed resources, if any.</returns>
|
||||
FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource);
|
||||
FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resources);
|
||||
|
||||
/// <summary>
|
||||
/// Creates instances of the given type and provides Property Injection and instance reference caching. Disposes of
|
||||
|
||||
Reference in New Issue
Block a user