- Made Package loading conditional on resources being available.
- Made States registration use named parameters. - Changed IPluginManagementService interface to better suit expected return results.
This commit is contained in:
@@ -19,55 +19,55 @@ namespace Barotrauma
|
|||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Enable CSharp Scripting")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Enable CSharp Scripting")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.IsCsEnabled?.Value ?? false,
|
Selected = GameMain.LuaCs.IsCsEnabled,
|
||||||
ToolTip = "This enables CSharp Scripting for mods to use, WARNING: CSharp is NOT sandboxed, be careful with what mods you download.",
|
ToolTip = "This enables CSharp Scripting for mods to use, WARNING: CSharp is NOT sandboxed, be careful with what mods you download.",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.IsCsEnabled?.TrySetValue(tick.Selected);
|
GameMain.LuaCs.IsCsEnabled = tick.Selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Treat Forced Mods As Normal")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Treat Forced Mods As Normal")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.TreatForcedModsAsNormal?.Value ?? false,
|
Selected = GameMain.LuaCs.TreatForcedModsAsNormal,
|
||||||
ToolTip = "This makes mods that were setup to run even when disabled to only run when enabled.",
|
ToolTip = "This makes mods that were setup to run even when disabled to only run when enabled.",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.TreatForcedModsAsNormal?.TrySetValue(tick.Selected);
|
GameMain.LuaCs.TreatForcedModsAsNormal = tick.Selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Prefer To Use Workshop Lua Setup")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Prefer To Use Workshop Lua Setup")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.PreferToUseWorkshopLuaSetup?.Value ?? false,
|
Selected = GameMain.LuaCs.PreferToUseWorkshopLuaSetup,
|
||||||
ToolTip = "This makes Lua look first for the Lua/LuaSetup.lua located in the Workshop package instead of the one located locally.",
|
ToolTip = "This makes Lua look first for the Lua/LuaSetup.lua located in the Workshop package instead of the one located locally.",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.PreferToUseWorkshopLuaSetup?.TrySetValue(tick.Selected);
|
GameMain.LuaCs.PreferToUseWorkshopLuaSetup = tick.Selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Disable Error GUI Overlay")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Disable Error GUI Overlay")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.DisableErrorGUIOverlay?.Value ?? false,
|
Selected = GameMain.LuaCs.DisableErrorGUIOverlay,
|
||||||
ToolTip = "",
|
ToolTip = "",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.DisableErrorGUIOverlay?.TrySetValue(tick.Selected);
|
GameMain.LuaCs.DisableErrorGUIOverlay = tick.Selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Hide usernames In Error Logs")
|
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Hide usernames In Error Logs")
|
||||||
{
|
{
|
||||||
Selected = GameMain.LuaCs.HideUserNamesInLogs?.Value ?? false,
|
Selected = GameMain.LuaCs.HideUserNamesInLogs,
|
||||||
ToolTip = "Hides the operating system username when displaying error logs (eg your username on windows).",
|
ToolTip = "Hides the operating system username when displaying error logs (eg your username on windows).",
|
||||||
OnSelected = (GUITickBox tick) =>
|
OnSelected = (GUITickBox tick) =>
|
||||||
{
|
{
|
||||||
GameMain.LuaCs.HideUserNamesInLogs?.TrySetValue(tick.Selected);
|
GameMain.LuaCs.HideUserNamesInLogs = tick.Selected;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
public void AddToGUIUpdateList()
|
public void AddToGUIUpdateList()
|
||||||
{
|
{
|
||||||
if (!DisableErrorGUIOverlay.Value)
|
if (!DisableErrorGUIOverlay)
|
||||||
{
|
{
|
||||||
LuaCsLogger.AddToGUIUpdateList();
|
LuaCsLogger.AddToGUIUpdateList();
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ namespace Barotrauma
|
|||||||
public bool CheckCsEnabled()
|
public bool CheckCsEnabled()
|
||||||
{
|
{
|
||||||
// fast exit if enabled or unavailable.
|
// fast exit if enabled or unavailable.
|
||||||
if (this.IsCsEnabled?.Value ?? true )
|
if (this.IsCsEnabled)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -60,14 +60,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
|
msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
|
||||||
{
|
{
|
||||||
this.IsCsEnabled.TrySetValue(true);
|
this.IsCsEnabled = true;
|
||||||
isCsValueChanged = true;
|
isCsValueChanged = true;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
|
msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
|
||||||
{
|
{
|
||||||
this.IsCsEnabled.TrySetValue(false);
|
this.IsCsEnabled = false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -815,7 +815,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
var tempBuffer = new ReadWriteMessage();
|
var tempBuffer = new ReadWriteMessage();
|
||||||
WriteStatus(tempBuffer, forceAfflictionData: true);
|
WriteStatus(tempBuffer, forceAfflictionData: true);
|
||||||
if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize && (GameMain.LuaCs.RestrictMessageSize?.Value ?? false))
|
if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize && (GameMain.LuaCs.RestrictMessageSize))
|
||||||
{
|
{
|
||||||
msg.WriteBoolean(false);
|
msg.WriteBoolean(false);
|
||||||
if (msgLengthBeforeStatus < 255)
|
if (msgLengthBeforeStatus < 255)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
foreach (var package in ContentPackageManager.AllPackages)
|
foreach (var package in ContentPackageManager.AllPackages)
|
||||||
{
|
{
|
||||||
if (package.UgcId.ValueEquals(new SteamWorkshopId(GameMain.LuaCs.LuaForBarotraumaSteamId?.Value ?? 0ul))
|
if (package.UgcId.ValueEquals(new SteamWorkshopId(GameMain.LuaCs.LuaForBarotraumaSteamId))
|
||||||
&& pathStartsWith(getFullPath(package.Path)))
|
&& pathStartsWith(getFullPath(package.Path)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Collections.Immutable;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Barotrauma.LuaCs;
|
using Barotrauma.LuaCs;
|
||||||
@@ -97,56 +98,98 @@ namespace Barotrauma
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether C# plugin code is enabled.
|
/// Whether C# plugin code is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> IsCsEnabled { get; private set; }
|
public bool IsCsEnabled
|
||||||
|
{
|
||||||
|
get => _isCsEnabled?.Value ?? false;
|
||||||
|
internal set => _isCsEnabled?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISettingEntry<bool> _isCsEnabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether mods marked as 'forced' or 'always load' should only be loaded if they're in the enabled mods list.
|
/// Whether mods marked as 'forced' or 'always load' should only be loaded if they're in the enabled mods list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> TreatForcedModsAsNormal { get; private set; }
|
public bool TreatForcedModsAsNormal
|
||||||
|
{
|
||||||
|
get => _treatForcedModsAsNormal?.Value ?? true;
|
||||||
|
internal set => _treatForcedModsAsNormal?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISettingEntry<bool> _treatForcedModsAsNormal;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the lua script runner from Workshop package should be used over the in-built version.
|
/// Whether the lua script runner from Workshop package should be used over the in-built version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> PreferToUseWorkshopLuaSetup { get; private set; }
|
public bool PreferToUseWorkshopLuaSetup
|
||||||
|
{
|
||||||
|
get => _preferToUseWorkshopLuaSetup?.Value ?? false;
|
||||||
|
internal set => _preferToUseWorkshopLuaSetup?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<bool> _preferToUseWorkshopLuaSetup;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the popup error GUI should be hidden/suppressed.
|
/// Whether the popup error GUI should be hidden/suppressed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> DisableErrorGUIOverlay { get; private set; }
|
public bool DisableErrorGUIOverlay
|
||||||
|
{
|
||||||
|
get => _disableErrorGUIOverlay?.Value ?? false;
|
||||||
|
internal set => _disableErrorGUIOverlay?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<bool> _disableErrorGUIOverlay;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether usernames are anonymized or show in logs.
|
/// Whether usernames are anonymized or show in logs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> HideUserNamesInLogs { get; private set; }
|
public bool HideUserNamesInLogs
|
||||||
|
{
|
||||||
|
get => _hideUserNamesInLogs?.Value ?? false;
|
||||||
|
internal set => _hideUserNamesInLogs?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<bool> _hideUserNamesInLogs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The SteamId of the Workshop LuaCs CPackage in use, if available.
|
/// The SteamId of the Workshop LuaCs CPackage in use, if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<ulong> LuaForBarotraumaSteamId { get; private set; }
|
public ulong LuaForBarotraumaSteamId
|
||||||
|
{
|
||||||
|
get => _luaForBarotraumaSteamId?.Value ?? 0;
|
||||||
|
internal set => _luaForBarotraumaSteamId?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<ulong> _luaForBarotraumaSteamId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TODO: @evilfactory@users.noreply.github.com
|
/// TODO: @evilfactory@users.noreply.github.com
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<bool> RestrictMessageSize { get; private set; }
|
public bool RestrictMessageSize
|
||||||
|
{
|
||||||
|
get => _restrictMessageSize?.Value ?? false;
|
||||||
|
internal set => _restrictMessageSize?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<bool> _restrictMessageSize;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The local save path for all local data storage for mods.
|
/// The local save path for all local data storage for mods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal ISettingEntry<string> LocalDataSavePath { get; private set; }
|
public string LocalDataSavePath
|
||||||
|
{
|
||||||
|
get => _localDataSavePath?.Value ?? Path.Combine(Directory.GetCurrentDirectory(), "/Data/Mods");
|
||||||
|
internal set => _localDataSavePath?.TrySetValue(value);
|
||||||
|
}
|
||||||
|
private ISettingEntry<string> _localDataSavePath;
|
||||||
|
|
||||||
void LoadLuaCsConfig()
|
void LoadLuaCsConfig()
|
||||||
{
|
{
|
||||||
IsCsEnabled = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "IsCsEnabled", out var val1) ? val1
|
_isCsEnabled = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "IsCsEnabled", out var val1) ? val1
|
||||||
: throw new NullReferenceException($"{nameof(IsCsEnabled)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(IsCsEnabled)} cannot be loaded.");
|
||||||
TreatForcedModsAsNormal = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "TreatForcedModsAsNormal", out var val2) ? val2
|
_treatForcedModsAsNormal = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "TreatForcedModsAsNormal", out var val2) ? val2
|
||||||
: throw new NullReferenceException($"{nameof(TreatForcedModsAsNormal)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(TreatForcedModsAsNormal)} cannot be loaded.");
|
||||||
DisableErrorGUIOverlay = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "DisableErrorGUIOverlay", out var val3) ? val3
|
_disableErrorGUIOverlay = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "DisableErrorGUIOverlay", out var val3) ? val3
|
||||||
: throw new NullReferenceException($"{nameof(DisableErrorGUIOverlay)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(DisableErrorGUIOverlay)} cannot be loaded.");
|
||||||
HideUserNamesInLogs = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "HideUserNamesInLogs", out var val4) ? val4
|
_hideUserNamesInLogs = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "HideUserNamesInLogs", out var val4) ? val4
|
||||||
: throw new NullReferenceException($"{nameof(HideUserNamesInLogs)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(HideUserNamesInLogs)} cannot be loaded.");
|
||||||
LuaForBarotraumaSteamId = ConfigService.TryGetConfig<ISettingEntry<ulong>>(ContentPackageManager.VanillaCorePackage, "LuaForBarotraumaSteamId", out var val5) ? val5
|
_luaForBarotraumaSteamId = ConfigService.TryGetConfig<ISettingEntry<ulong>>(ContentPackageManager.VanillaCorePackage, "LuaForBarotraumaSteamId", out var val5) ? val5
|
||||||
: throw new NullReferenceException($"{nameof(LuaForBarotraumaSteamId)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(LuaForBarotraumaSteamId)} cannot be loaded.");
|
||||||
RestrictMessageSize = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "RestrictMessageSize", out var val7) ? val7
|
_restrictMessageSize = ConfigService.TryGetConfig<ISettingEntry<bool>>(ContentPackageManager.VanillaCorePackage, "RestrictMessageSize", out var val7) ? val7
|
||||||
: throw new NullReferenceException($"{nameof(RestrictMessageSize)} cannot be loaded.");
|
: throw new NullReferenceException($"{nameof(RestrictMessageSize)} cannot be loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,9 +287,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private StateMachine<RunState> SetupStateMachine()
|
private StateMachine<RunState> SetupStateMachine()
|
||||||
{
|
{
|
||||||
return new StateMachine<RunState>(false, RunState.Unloaded, RunStateUnloaded_OnEnter, null)
|
return new StateMachine<RunState>(false, RunState.Unloaded, onEnter: RunStateUnloaded_OnEnter, null)
|
||||||
.AddState(RunState.LoadedNoExec, RunStateLoadedNoExec_OnEnter, null)
|
.AddState(RunState.LoadedNoExec, onEnter: RunStateLoadedNoExec_OnEnter, null)
|
||||||
.AddState(RunState.Running, RunStateRunning_OnEnter, RunStateRunning_OnExit);
|
.AddState(RunState.Running, onEnter: RunStateRunning_OnEnter, RunStateRunning_OnExit);
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
void RunStateUnloaded_OnEnter(State<RunState> currentState)
|
void RunStateUnloaded_OnEnter(State<RunState> currentState)
|
||||||
@@ -355,12 +398,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
void DisposeLuaCsConfig()
|
void DisposeLuaCsConfig()
|
||||||
{
|
{
|
||||||
IsCsEnabled = null;
|
_isCsEnabled = null;
|
||||||
TreatForcedModsAsNormal = null;
|
_treatForcedModsAsNormal = null;
|
||||||
DisableErrorGUIOverlay = null;
|
_disableErrorGUIOverlay = null;
|
||||||
HideUserNamesInLogs = null;
|
_hideUserNamesInLogs = null;
|
||||||
LuaForBarotraumaSteamId = null;
|
_luaForBarotraumaSteamId = null;
|
||||||
RestrictMessageSize = null;
|
_restrictMessageSize = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+29
-20
@@ -151,17 +151,28 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = new FluentResults.Result();
|
var res = new FluentResults.Result();
|
||||||
var configsTask = new Task<Task<FluentResults.Result>>(async Task<FluentResults.Result> () =>
|
var tasks = ImmutableArray.CreateBuilder<Task<Task<FluentResults.Result>>>();
|
||||||
new FluentResults.Result()
|
|
||||||
.WithReasons((await _configService.LoadConfigsAsync(config.Configs)).Reasons)
|
|
||||||
.WithReasons((await _configService.LoadConfigsProfilesAsync(config.Configs)).Reasons));
|
|
||||||
var luaScriptsTask = new Task<Task<FluentResults.Result>>(async () =>
|
|
||||||
await _luaScriptManagementService.LoadScriptResourcesAsync(config.LuaScripts));
|
|
||||||
|
|
||||||
configsTask.Start();
|
if (!config.Configs.IsDefaultOrEmpty)
|
||||||
luaScriptsTask.Start();
|
{
|
||||||
|
tasks.Add(Task.Factory.StartNew(async Task<FluentResults.Result> () =>
|
||||||
|
new FluentResults.Result()
|
||||||
|
.WithReasons((await _configService.LoadConfigsAsync(config.Configs)).Reasons)
|
||||||
|
.WithReasons((await _configService.LoadConfigsProfilesAsync(config.Configs)).Reasons)));
|
||||||
|
}
|
||||||
|
|
||||||
var r = Task.WhenAll(configsTask, luaScriptsTask).ConfigureAwait(false).GetAwaiter().GetResult();
|
if (!config.LuaScripts.IsDefaultOrEmpty)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Factory.StartNew(async () =>
|
||||||
|
await _luaScriptManagementService.LoadScriptResourcesAsync(config.LuaScripts)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tasks.Count == 0)
|
||||||
|
{
|
||||||
|
return FluentResults.Result.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
var r = Task.WhenAll(tasks.ToArray()).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
|
|
||||||
foreach (var task in r)
|
foreach (var task in r)
|
||||||
res.WithReasons(task.ConfigureAwait(false).GetAwaiter().GetResult().Reasons);
|
res.WithReasons(task.ConfigureAwait(false).GetAwaiter().GetResult().Reasons);
|
||||||
@@ -180,7 +191,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
IService.CheckDisposed(this);
|
IService.CheckDisposed(this);
|
||||||
|
|
||||||
if (executionOrder.IsDefaultOrEmpty)
|
if (executionOrder.IsDefaultOrEmpty)
|
||||||
|
{
|
||||||
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages in the execution order list.");
|
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages in the execution order list.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!_runningPackages.IsEmpty)
|
if (!_runningPackages.IsEmpty)
|
||||||
{
|
{
|
||||||
@@ -190,7 +203,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_loadedPackages.IsEmpty)
|
if (_loadedPackages.IsEmpty)
|
||||||
|
{
|
||||||
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages loaded. Nothing to run!)");
|
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages loaded. Nothing to run!)");
|
||||||
|
}
|
||||||
|
|
||||||
var result = new FluentResults.Result();
|
var result = new FluentResults.Result();
|
||||||
|
|
||||||
@@ -198,24 +213,16 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
var loadingOrderedPackages = _loadedPackages.OrderBy(pkg => executionOrder.IndexOf(pkg.Key))
|
var loadingOrderedPackages = _loadedPackages.OrderBy(pkg => executionOrder.IndexOf(pkg.Key))
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
|
|
||||||
//mod settings
|
// NOTE: Config/Settings are instanced in LoadPackages()
|
||||||
var settings = loadingOrderedPackages
|
|
||||||
.SelectMany(pkg => pkg.Value.Configs.OrderBy(scr => scr.LoadPriority))
|
|
||||||
.ToImmutableArray();
|
|
||||||
if (!settings.IsDefaultOrEmpty)
|
|
||||||
{
|
|
||||||
result.WithReasons(_configService.LoadConfigsAsync(settings).ConfigureAwait(false).GetAwaiter()
|
|
||||||
.GetResult().Reasons);
|
|
||||||
result.WithReasons(_configService.LoadConfigsProfilesAsync(settings).ConfigureAwait(false)
|
|
||||||
.GetAwaiter().GetResult().Reasons);
|
|
||||||
}
|
|
||||||
|
|
||||||
//lua scripts
|
//lua scripts
|
||||||
var luaScripts = loadingOrderedPackages
|
var luaScripts = loadingOrderedPackages
|
||||||
.SelectMany(pkg => pkg.Value.LuaScripts.OrderBy(scr => scr.LoadPriority))
|
.SelectMany(pkg => pkg.Value.LuaScripts.OrderBy(scr => scr.LoadPriority))
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
if (!luaScripts.IsDefaultOrEmpty)
|
if (!luaScripts.IsDefaultOrEmpty)
|
||||||
|
{
|
||||||
result.WithReasons(_luaScriptManagementService.ExecuteLoadedScripts(luaScripts).Reasons);
|
result.WithReasons(_luaScriptManagementService.ExecuteLoadedScripts(luaScripts).Reasons);
|
||||||
|
}
|
||||||
|
|
||||||
if (_runConfig.IsCsEnabled)
|
if (_runConfig.IsCsEnabled)
|
||||||
{
|
{
|
||||||
@@ -223,7 +230,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
loadingOrderedPackages.SelectMany(pkg => pkg.Value.Assemblies.OrderBy(scr => scr.LoadPriority))
|
loadingOrderedPackages.SelectMany(pkg => pkg.Value.Assemblies.OrderBy(scr => scr.LoadPriority))
|
||||||
.ToImmutableArray();
|
.ToImmutableArray();
|
||||||
if (!plugins.IsDefaultOrEmpty)
|
if (!plugins.IsDefaultOrEmpty)
|
||||||
|
{
|
||||||
result.WithReasons(_pluginManagementService.LoadAssemblyResources(plugins).Reasons);
|
result.WithReasons(_pluginManagementService.LoadAssemblyResources(plugins).Reasons);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using Barotrauma.LuaCs.Data;
|
|||||||
using Barotrauma.LuaCs.Events;
|
using Barotrauma.LuaCs.Events;
|
||||||
using FluentResults;
|
using FluentResults;
|
||||||
using FluentResults.LuaCs;
|
using FluentResults.LuaCs;
|
||||||
|
using ImpromptuInterface.Build;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using OneOf;
|
using OneOf;
|
||||||
|
|
||||||
@@ -21,14 +22,15 @@ namespace Barotrauma.LuaCs.Services;
|
|||||||
public class PluginManagementService : IPluginManagementService, IAssemblyManagementService
|
public class PluginManagementService : IPluginManagementService, IAssemblyManagementService
|
||||||
{
|
{
|
||||||
private readonly Func<IAssemblyLoaderService.LoaderInitData, IAssemblyLoaderService> _assemblyLoaderServiceFactory;
|
private readonly Func<IAssemblyLoaderService.LoaderInitData, IAssemblyLoaderService> _assemblyLoaderServiceFactory;
|
||||||
private readonly ConcurrentDictionary<ContentPackage, (List<IAssemblyResourceInfo> ResourceInfos, IAssemblyLoaderService Loader)> _packageAssemblyResources;
|
private readonly ConcurrentDictionary<ContentPackage, (List<IAssemblyResourceInfo> ResourceInfos, IAssemblyLoaderService Loader)> _packageAssemblyResources = new();
|
||||||
private readonly ConcurrentDictionary<ContentPackage, List<IDisposable>> _pluginInstances;
|
private readonly ConcurrentDictionary<ContentPackage, List<IDisposable>> _pluginInstances = new();
|
||||||
private readonly Lazy<IEventService> _eventService;
|
private readonly Lazy<IEventService> _eventService;
|
||||||
private readonly ConditionalWeakTable<IAssemblyLoaderService, ContentPackage> _unloadingAssemblyLoaders;
|
private readonly ConditionalWeakTable<IAssemblyLoaderService, ContentPackage> _unloadingAssemblyLoaders = new();
|
||||||
private readonly ConditionalWeakTable<Assembly, ConcurrentDictionary<string, Type>> _assemblyTypesCache;
|
private readonly ConditionalWeakTable<Assembly, ConcurrentDictionary<string, Type>> _assemblyTypesCache = new();
|
||||||
|
|
||||||
public PluginManagementService(
|
public PluginManagementService(
|
||||||
Func<IAssemblyLoaderService.LoaderInitData, IAssemblyLoaderService> assemblyLoaderServiceFactory,
|
Func<IAssemblyLoaderService.LoaderInitData,
|
||||||
|
IAssemblyLoaderService> assemblyLoaderServiceFactory,
|
||||||
Lazy<IEventService> eventService)
|
Lazy<IEventService> eventService)
|
||||||
{
|
{
|
||||||
_assemblyLoaderServiceFactory = assemblyLoaderServiceFactory;
|
_assemblyLoaderServiceFactory = assemblyLoaderServiceFactory;
|
||||||
@@ -123,14 +125,20 @@ public class PluginManagementService : IPluginManagementService, IAssemblyManage
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<ImmutableArray<IAssemblyResourceInfo>> LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource)
|
public FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return FluentResults.Result.Fail($"{nameof(LoadAssemblyResources)}: Plugin loading not currently implemented.");
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableArray<Result<(Type, T)>> ActivateTypeInstances<T>(ImmutableArray<Type> types, bool serviceInjection = true,
|
public ImmutableArray<Result<(Type, T)>> ActivateTypeInstances<T>(ImmutableArray<Type> types, bool serviceInjection = true,
|
||||||
bool hostInstanceReference = false) where T : IDisposable
|
bool hostInstanceReference = false) where T : IDisposable
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
return ImmutableArray<Result<(Type, T)>>.Empty;
|
||||||
|
#endif
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ public interface IPluginManagementService : IReusableService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="resource"></param>
|
/// <param name="resource"></param>
|
||||||
/// <returns>Success/Failure and list of failed resources, if any.</returns>
|
/// <returns>Success/Failure and list of failed resources, if any.</returns>
|
||||||
FluentResults.Result<ImmutableArray<IAssemblyResourceInfo>> LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource);
|
FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates instances of the given type and provides Property Injection and instance reference caching. Disposes of
|
/// Creates instances of the given type and provides Property Injection and instance reference caching. Disposes of
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class StateMachine<T> where T : Enum
|
|||||||
ThrowHelper.ThrowArgumentException($"State with id {stateId} already exists.");
|
ThrowHelper.ThrowArgumentException($"State with id {stateId} already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_states[stateId] = new State<T>(stateId, onEnter, onExit);
|
_states[stateId] = new State<T>(stateId, onEnterState: onEnter, onExitState: onExit);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user