IT BUILDS!!!
- Removed LocalizationServices and other sus things. - Rewrote AssemblyLoader [In Progress] SafeStorageService [In Progress] LuaScriptLoader
This commit is contained in:
+26
-59
@@ -3,77 +3,44 @@ using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.LuaCs.Configuration;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
using Barotrauma.LuaCs.Services;
|
||||
using Barotrauma.LuaCs.Services.Safe;
|
||||
using Barotrauma.Networking;
|
||||
using FluentResults;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public partial interface IConfigService : IReusableService, ILuaConfigService
|
||||
{
|
||||
/*
|
||||
* Resource Files.
|
||||
*/
|
||||
/// <summary>
|
||||
/// Registers a type initializer from instancing config types by indicated type from config.
|
||||
/// </summary>
|
||||
/// <param name="initializer"></param>
|
||||
/// <param name="replaceIfExists"></param>
|
||||
/// <typeparam name="TData">The <see cref="Type"/> as parsed from the configuration info.</typeparam>
|
||||
/// <typeparam name="TConfig">The resulting configuration instance.</typeparam>
|
||||
void RegisterTypeInitializer<TData, TConfig>(Func<IConfigInfo, FluentResults.Result<TConfig>> initializer, bool replaceIfExists = false)
|
||||
where TData : IEquatable<TData> where TConfig : IConfigBase;
|
||||
|
||||
// Config Files/Resources
|
||||
Task<FluentResults.Result> LoadConfigsAsync(ImmutableArray<IConfigResourceInfo> configResources);
|
||||
Task<FluentResults.Result> LoadConfigsProfilesAsync(ImmutableArray<IConfigProfileResourceInfo> configProfileResources);
|
||||
FluentResults.Result DisposeConfigs(ImmutableArray<IConfigResourceInfo> configResources);
|
||||
FluentResults.Result DisposeConfigsProfiles(ImmutableArray<IConfigProfileResourceInfo> configProfilesResources);
|
||||
FluentResults.Result DisposeConfigs(ContentPackage package);
|
||||
FluentResults.Result DisposeConfigsProfiles(ContentPackage package);
|
||||
|
||||
// Immediate Mode
|
||||
FluentResults.Result<TConfig> AddConfig<TConfig>(IConfigInfo configInfo) where TConfig : IConfigBase;
|
||||
|
||||
/*
|
||||
* Immediate mode
|
||||
*/
|
||||
FluentResults.Result<IConfigEntry<T>> AddConfigEntry<T>(ContentPackage package, string name,
|
||||
T defaultValue,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<T, bool> valueChangePredicate = null,
|
||||
Action<IConfigEntry<T>> onValueChanged = null) where T : IConvertible, IEquatable<T>;
|
||||
|
||||
FluentResults.Result<IConfigList> AddConfigList(ContentPackage package, string name,
|
||||
int defaultIndex, IReadOnlyList<string> values,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<IConfigList, int, bool> valueChangePredicate = null,
|
||||
Action<IConfigList, int> onValueChanged = null);
|
||||
|
||||
FluentResults.Result<IConfigRangeEntry<T>> AddConfigRangeEntry<T>(ContentPackage package, string name,
|
||||
T defaultValue, T minValue, T maxValue,
|
||||
Func<IConfigRangeEntry<T>, int> getStepCount,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<T, bool> valueChangePredicate = null,
|
||||
Action<IConfigEntry<T>> onValueChanged = null) where T : IConvertible, IEquatable<T>;
|
||||
|
||||
FluentResults.Result<IConfigEntry<T>> AddConfigEntry<T>(string packageName, string name,
|
||||
T defaultValue,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<T, bool> valueChangePredicate = null,
|
||||
Action<IConfigEntry<T>> onValueChanged = null) where T : IConvertible, IEquatable<T>;
|
||||
|
||||
FluentResults.Result<IConfigList> AddConfigList(string packageName, string name,
|
||||
int defaultIndex, IReadOnlyList<string> values,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<IConfigList, int, bool> valueChangePredicate = null,
|
||||
Action<IConfigList, int> onValueChanged = null);
|
||||
|
||||
FluentResults.Result<IConfigRangeEntry<T>> AddConfigRangeEntry<T>(string packageName, string name,
|
||||
T defaultValue, T minValue, T maxValue,
|
||||
Func<IConfigRangeEntry<T>, int> getStepCount,
|
||||
NetSync syncMode = NetSync.None,
|
||||
ClientPermissions permissions = ClientPermissions.None,
|
||||
Func<T, bool> valueChangePredicate = null,
|
||||
Action<IConfigEntry<T>> onValueChanged = null) where T : IConvertible, IEquatable<T>;
|
||||
|
||||
FluentResults.Result<IReadOnlyDictionary<string, IConfigBase>> GetConfigsForPackage(ContentPackage package);
|
||||
FluentResults.Result<IReadOnlyDictionary<string, IConfigBase>> GetConfigsForPackage(string packageName);
|
||||
IReadOnlyDictionary<(ContentPackage, string), IConfigBase> GetAllConfigs();
|
||||
T GetConfig<T>(ContentPackage package, string name) where T : IConfigBase;
|
||||
T GetConfig<T>(string packageName, string name) where T : IConfigBase;
|
||||
// Utility
|
||||
FluentResults.Result ApplyProfileSettings(ContentPackage package, string profileName);
|
||||
FluentResults.Result DisposePackageData(ContentPackage package);
|
||||
FluentResults.Result<IReadOnlyDictionary<(ContentPackage Package, string ConfigName), IConfigBase>> GetConfigsForPackage(ContentPackage package);
|
||||
FluentResults.Result<IReadOnlyDictionary<(ContentPackage Package, string ConfigName), ImmutableArray<(string ConfigName, OneOf.OneOf<string, XElement> Value)>>>
|
||||
GetProfilesForPackage(ContentPackage package);
|
||||
IReadOnlyDictionary<(ContentPackage Package, string Name), IConfigBase> GetAllConfigs();
|
||||
bool TryGetConfig<T>(ContentPackage package, string name, out T config) where T : IConfigBase;
|
||||
Task<FluentResults.Result> SaveAllConfigs();
|
||||
Task<FluentResults.Result> SaveConfigsForPackage(ContentPackage package);
|
||||
Task<FluentResults.Result> SaveConfig((ContentPackage Package, string ConfigName) config);
|
||||
}
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public interface ILocalizationService : IReusableService
|
||||
{
|
||||
IReadOnlyCollection<CultureInfo> GetLoadedLocales();
|
||||
void Remove(ImmutableArray<ILocalizationResourceInfo> localizations);
|
||||
void DisposePackage(ContentPackage package);
|
||||
FluentResults.Result SetCurrentCulture(CultureInfo culture);
|
||||
FluentResults.Result SetCurrentCulture(string cultureName);
|
||||
Task<FluentResults.Result> LoadLocalizations(ImmutableArray<ILocalizationResourceInfo> localizationResources);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get a localized string without a fallback. Returns success/failure and associated data.
|
||||
/// </summary>
|
||||
/// <param name="key">Neutral localization key.</param>
|
||||
/// <returns></returns>
|
||||
FluentResults.Result<string> GetLocalizedString(string key);
|
||||
FluentResults.Result<string> GetLocalizedString(string key, CultureInfo targetCulture);
|
||||
string GetLocalizedString(string key, string fallback);
|
||||
string GetLocalizedString(string key, string fallback, CultureInfo targetCulture);
|
||||
FluentResults.Result<string> GetLocalizedStringForPackage(ContentPackage package, string key);
|
||||
FluentResults.Result<string> GetLocalizedStringForPackage(ContentPackage package, string key, CultureInfo targetCulture);
|
||||
string GetLocalizedStringForPackage(ContentPackage package, string key, string fallback);
|
||||
string GetLocalizedStringForPackage(ContentPackage package, string key, string fallback, CultureInfo targetCulture);
|
||||
FluentResults.Result RegisterLocalizationResolver(CultureInfo targetCulture, Func<string, CultureInfo, string> factoryResolver);
|
||||
bool IsCurrentCultureSupported(IResourceCultureInfo culturesInfo);
|
||||
}
|
||||
+49
-3
@@ -4,6 +4,7 @@ using System.Collections.Immutable;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
using FluentResults;
|
||||
using MoonSharp.Interpreter;
|
||||
using MoonSharp.Interpreter.Interop;
|
||||
|
||||
@@ -13,13 +14,58 @@ public interface ILuaScriptManagementService : IReusableService
|
||||
{
|
||||
#region Script_Ops
|
||||
|
||||
Result<object> GetGlobalTableValue(string tableName);
|
||||
|
||||
/// <summary>
|
||||
/// Parses and loads script sources (code) into a memory cache without executing it.
|
||||
/// </summary>
|
||||
/// <param name="resourcesInfo"></param>
|
||||
/// <returns></returns>
|
||||
// [Required]
|
||||
Task<FluentResults.Result> LoadScriptResourcesAsync(ImmutableArray<ILuaScriptResourceInfo> resourcesInfo);
|
||||
|
||||
FluentResults.Result ExecuteLoadedScripts(ContentPackage package, bool pauseExecutionOnError = false, bool verboseLogging = false);
|
||||
FluentResults.Result ExecuteLoadedScripts(ImmutableArray<ILuaScriptResourceInfo> scripts, bool pauseExecutionOnError = false, bool verboseLogging = false);
|
||||
FluentResults.Result ExecuteLoadedScripts(bool pauseExecutionOnError = false, bool verboseLogging = false);
|
||||
/// <summary>
|
||||
/// Executes cached scripts (code) for the given <see cref="ContentPackage"/>.
|
||||
/// </summary>
|
||||
/// <param name="package"></param>
|
||||
/// <returns></returns>
|
||||
// [Required]
|
||||
FluentResults.Result ExecuteLoadedScriptsForPackage(ContentPackage package);
|
||||
|
||||
/// <summary>
|
||||
/// Executes cached scripts (code) for the given collection <see cref="ContentPackage"/>.
|
||||
/// </summary>
|
||||
/// <param name="packages"></param>
|
||||
/// <returns></returns>
|
||||
// [Required]
|
||||
FluentResults.Result ExecuteLoadedScriptsForPackages(IEnumerable<ContentPackage> packages);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
// [Required]
|
||||
FluentResults.Result ExecuteLoadedScripts();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="package"></param>
|
||||
/// <returns></returns>
|
||||
// [Required]
|
||||
FluentResults.Result DisposePackageResources(ContentPackage package);
|
||||
|
||||
/// <summary>
|
||||
/// Calls dispose on, and clears active refs for, currently running scripts. Does not clear caches.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
FluentResults.Result UnloadActiveScripts();
|
||||
|
||||
/// <summary>
|
||||
/// Unloads all scripts and clears all caches/references.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>May be functionally equivalent to <see cref="IReusableService.Reset"/></remarks>
|
||||
FluentResults.Result DisposeAllPackageResources();
|
||||
|
||||
#endregion
|
||||
|
||||
+8
-3
@@ -8,7 +8,7 @@ namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
internal delegate void NetMessageReceived(IReadMessage netMessage);
|
||||
|
||||
internal partial interface INetworkingService : IReusableService, ILuaCsNetworking
|
||||
internal partial interface INetworkingService : IReusableService, ILuaCsNetworking, IEntityNetworkingService
|
||||
{
|
||||
bool IsActive { get; }
|
||||
bool IsSynchronized { get; }
|
||||
@@ -20,6 +20,11 @@ internal partial interface INetworkingService : IReusableService, ILuaCsNetworki
|
||||
#elif CLIENT
|
||||
public void Send(IWriteMessage netMessage, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable);
|
||||
#endif
|
||||
public void RegisterNetVar(INetVar netVar);
|
||||
public void SendNetVar(INetVar netVar);
|
||||
|
||||
}
|
||||
|
||||
public interface IEntityNetworkingService
|
||||
{
|
||||
public void RegisterNetVar(INetworkSyncEntity netVar);
|
||||
public void SendNetVar(INetworkSyncEntity netVar);
|
||||
}
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public interface IPackageInfoLookupService : IReusableService
|
||||
{
|
||||
bool IsPackageEnabled(ContentPackage package);
|
||||
Task<FluentResults.Result<IPackageInfo>> Lookup(string packageName);
|
||||
Task<FluentResults.Result<IPackageInfo>> Lookup(string packageName, ulong steamWorkshopId);
|
||||
Task<FluentResults.Result<IPackageInfo>> Lookup(ulong steamWorkshopId);
|
||||
|
||||
+17
-20
@@ -9,11 +9,7 @@ using Barotrauma.LuaCs.Data;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public interface IPackageManagementService : IReusableService, ILocalizationsResourcesInfo, IConfigsResourcesInfo, IConfigProfilesResourcesInfo, ILuaScriptsResourcesInfo, IAssembliesResourcesInfo
|
||||
#if CLIENT
|
||||
,IStylesResourcesInfo
|
||||
#endif
|
||||
|
||||
public interface IPackageManagementService : IReusableService, IConfigsResourcesInfo, IConfigProfilesResourcesInfo, ILuaScriptsResourcesInfo, IAssembliesResourcesInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads and parses the provided <see cref="ContentPackage"/> for <see cref="IResourceInfo"/> supported by the current runtime environment.
|
||||
@@ -30,6 +26,20 @@ public interface IPackageManagementService : IReusableService, ILocalizationsRes
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<(ContentPackage, FluentResults.Result)>> LoadPackagesInfosAsync(IReadOnlyList<ContentPackage> packages);
|
||||
IReadOnlyList<ContentPackage> GetAllLoadedPackages();
|
||||
bool IsPackageLoaded(ContentPackage package);
|
||||
|
||||
/// <summary>
|
||||
/// Filters out resources not suitable for the current environment using the following criteria: <br/>
|
||||
/// - Platform (Operating System)<br/>
|
||||
/// - Target (Client|Server)<br/>
|
||||
/// - Null/Invalid<br/>
|
||||
/// - Dependency Package Registered in PMS<br/>
|
||||
/// </summary>
|
||||
/// <param name="resources"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
ImmutableArray<T> FilterUnloadableResources<T>(IReadOnlyList<T> resources, bool enabledPackagesOnly = false)
|
||||
where T : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo;
|
||||
void DisposePackageInfos(ContentPackage package);
|
||||
void DisposePackagesInfos(IReadOnlyList<ContentPackage> packages);
|
||||
FluentResults.Result<IPackageDependency> GetPackageDependencyInfo(ContentPackage ownerPackage, string packageName, ulong steamWorkshopId);
|
||||
@@ -38,28 +48,15 @@ public interface IPackageManagementService : IReusableService, ILocalizationsRes
|
||||
FluentResults.Result<IAssembliesResourcesInfo> GetAssembliesInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigsResourcesInfo> GetConfigsInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigProfilesResourcesInfo> GetConfigProfilesInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILocalizationsResourcesInfo> GetLocalizationsInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
#if CLIENT
|
||||
FluentResults.Result<IStylesResourcesInfo> GetStylesInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
#endif
|
||||
// collection
|
||||
FluentResults.Result<IAssembliesResourcesInfo> GetAssembliesInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigsResourcesInfo> GetConfigsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigProfilesResourcesInfo> GetConfigProfilesInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILocalizationsResourcesInfo> GetLocalizationsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
#if CLIENT
|
||||
FluentResults.Result<IStylesResourcesInfo> GetStylesInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
#endif
|
||||
FluentResults.Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
|
||||
Task<FluentResults.Result<IAssembliesResourcesInfo>> GetAssembliesInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<IConfigsResourcesInfo>> GetConfigsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<IConfigProfilesResourcesInfo>> GetConfigProfilesInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<ILocalizationsResourcesInfo>> GetLocalizationsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<ILuaScriptsResourcesInfo>> GetLuaScriptsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
#if CLIENT
|
||||
Task<FluentResults.Result<IStylesResourcesInfo>> GetStylesInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
#endif
|
||||
|
||||
Task<FluentResults.Result<ILuaScriptsResourcesInfo>> GetLuaScriptsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Immutable;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
@@ -7,6 +8,26 @@ namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public interface IStorageService : IService
|
||||
{
|
||||
|
||||
bool UseCaching { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all cached file data.
|
||||
/// </summary>
|
||||
void PurgeCache();
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the data for the supplied file path from the data cache.
|
||||
/// </summary>
|
||||
/// <param name="absolutePath"></param>
|
||||
void PurgeFileFromCache(string absolutePath);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the data from the supplied file paths from the data cache.
|
||||
/// </summary>
|
||||
/// <param name="absolutePaths"></param>
|
||||
void PurgeFilesFromCache(params string[] absolutePaths);
|
||||
|
||||
// -- local game folder storage
|
||||
FluentResults.Result<XDocument> LoadLocalXml(ContentPackage package, string localFilePath);
|
||||
FluentResults.Result<byte[]> LoadLocalBinary(ContentPackage package, string localFilePath);
|
||||
|
||||
Reference in New Issue
Block a user