Skip to content

Commit

Permalink
- Begun implementation of package loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
MapleWheels committed Sep 29, 2024
1 parent e4eb463 commit 9bcdb25
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Immutable;

namespace Barotrauma.LuaCs.Data;

public partial interface IModConfigInfo
{
/// <summary>
/// Collection of loadable styles data.
/// </summary>
ImmutableArray<IStylesResourceInfo> StylesResourceInfos { get; }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Barotrauma.LuaCs.Data;

public interface IStylesResourceInfo : IResourceInfo, IResourceCultureInfo { }
public interface IStylesResourceInfo : IResourceInfo, IResourceCultureInfo, ILazyLoadableResourceInfo, IPackageDependenciesInfo { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Immutable;

namespace Barotrauma.LuaCs.Data;

public readonly partial struct ModConfigInfo : IModConfigInfo
{
public ImmutableArray<IStylesResourceInfo> StylesResourceInfos { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Barotrauma.LuaCs.Services.Processing;

namespace Barotrauma.LuaCs.Services;

public partial class PackageService
{
private readonly Lazy<IXmlStylesToResConverterService> _stylesConverterService;

public PackageService(
Lazy<IXmlModConfigConverterService> converterService,
Lazy<IXmlLegacyModConfigConverterService> legacyConfigConverterService,
Lazy<IXmlLocalizationResConverterService> localizationConverterService,
Lazy<IXmlStylesToResConverterService> stylesConverterService,
IStorageService storageService,
ILoggerService loggerService)
{
_modConfigConverterService = converterService;
_legacyConfigConverterService = legacyConfigConverterService;
_localizationConverterService = localizationConverterService;
_stylesConverterService = stylesConverterService;
_storageService = storageService;
_loggerService = loggerService;
}
partial void TryParsePackageClient(ContentPackage package)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Barotrauma.LuaCs.Services.Processing;

namespace Barotrauma.LuaCs.Services;

public partial class PackageService
{
public PackageService(
Lazy<IXmlModConfigConverterService> converterService,
Lazy<IXmlLegacyModConfigConverterService> legacyConfigConverterService,
Lazy<IXmlLocalizationResConverterService> localizationConverterService,
IStorageService storageService,
ILoggerService loggerService)
{
_modConfigConverterService = converterService;
_legacyConfigConverterService = legacyConfigConverterService;
_localizationConverterService = localizationConverterService;
_storageService = storageService;
_loggerService = loggerService;
}
// No implementation
partial void TryParsePackageClient(ContentPackage package) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@ public interface IResourceCultureInfo
/// </summary>
ImmutableArray<CultureInfo> SupportedCultures { get; init; }
}


public interface ILazyLoadableResourceInfo
{
/// <summary>
/// The name that will be used when trying to reference this resource for execution or loading.
/// </summary>
public string InternalName { get; }

/// <summary>
/// Should this be compiled/loaded immediately or stored until demanded.
/// </summary>
public bool LazyLoad { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Barotrauma.LuaCs.Data;

public interface IModConfigInfo : IPackageDependenciesInfo, IResourceCultureInfo
public partial interface IModConfigInfo : IPackageDependenciesInfo, IResourceCultureInfo
{
// package info
ContentPackage Package { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ namespace Barotrauma.LuaCs.Data;
public interface IConfigResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo { }
public interface IConfigProfileResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo { }
public interface ILocalizationResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo { }

public interface IAssemblyResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo
/// <summary>
/// Represents loadable Lua files.
/// </summary>
public interface ILuaResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, ILazyLoadableResourceInfo { }
public interface IAssemblyResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, ILazyLoadableResourceInfo
{
/// <summary>
/// The friendly name of the assembly. Script files belonging to the same assembly should all have the same name.
Expand All @@ -18,8 +21,4 @@ public interface IAssemblyResourceInfo : IResourceInfo, IResourceCultureInfo, IP
/// Is this entry referring to a script file collection.
/// </summary>
public bool IsScript { get; }
/// <summary>
/// Should this be compiled/loaded immediately or stored until demanded.
/// </summary>
public bool LazyLoad { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.Runtime.InteropServices;

namespace Barotrauma.LuaCs.Data;

#region ModConfigurationInfo

public readonly struct ModConfigInfo : IModConfigInfo
[StructLayout(LayoutKind.Auto)] // because we have a partial readonly struct
public readonly partial struct ModConfigInfo : IModConfigInfo
{
public ContentPackage Package { get; init; }
public string PackageName { get; init; }
Expand All @@ -28,6 +30,7 @@ namespace Barotrauma.LuaCs.Data;
{
public string FriendlyName { get; init; }
public bool IsScript { get; init; }
public string InternalName { get; init; }
public bool LazyLoad { get; init; }
public Platform SupportedPlatforms { get; init; }
public Target SupportedTargets { get; init; }
Expand Down Expand Up @@ -55,4 +58,15 @@ namespace Barotrauma.LuaCs.Data;
public ImmutableArray<IPackageDependencyInfo> Dependencies { get; init; }
}

public readonly struct LuaScriptResourceInfo : ILuaResourceInfo
{
public Platform SupportedPlatforms { get; init; }
public Target SupportedTargets { get; init; }
public ImmutableArray<string> FilePaths { get; init; }
public ImmutableArray<CultureInfo> SupportedCultures { get; init; }
public ImmutableArray<IPackageDependencyInfo> Dependencies { get; init; }
public string InternalName { get; init; }
public bool LazyLoad { get; init; }
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,23 @@ public bool LuaTryRegisterPackageTypes(string name, bool caseSensitive = false)
#endregion

/// <summary>
/// Whether or not assemblies have been loaded.
/// Whether assemblies have been loaded.
/// </summary>
public bool AssembliesLoaded { get; private set; }


/// <summary>
/// Whether or not loaded plugins had their preloader run.
/// Whether loaded plugins had their preloader run.
/// </summary>
public bool PluginsPreInit { get; private set; }

/// <summary>
/// Whether or not plugins' types have been instantiated.
/// Whether plugins' types have been instantiated.
/// </summary>
public bool PluginsInitialized { get; private set; }

/// <summary>
/// Whether or not plugins are fully loaded.
/// Whether plugins are fully loaded.
/// </summary>
public bool PluginsLoaded { get; private set; }

Expand Down Expand Up @@ -967,7 +967,7 @@ private static bool TryBuildDependenciesMap(ImmutableList<ContentPackage> packag
/// <param name="cannotLoadPackages">Packages with errors or cyclic dependencies. Element is error message. Null if empty.</param>
/// <param name="packageChecksPredicate">Optional: Allows for a custom checks to be performed on each package.
/// Returns a bool indicating if the package is ready to load.</param>
/// <returns>Whether or not the process produces a usable list.</returns>
/// <returns>Whether the process produces a usable list.</returns>
private static bool OrderAndFilterPackagesByDependencies(
Dictionary<ContentPackage, ImmutableList<ContentPackage>> packages,
out IEnumerable<ContentPackage> readyToLoad,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Barotrauma.LuaCs.Data;
using System.Collections.Generic;
using System.Collections.Immutable;
using Barotrauma.LuaCs.Data;

namespace Barotrauma.LuaCs.Services;

public interface IContentPackageService : IService
{
bool TryLoadPackageData(ContentPackage package);
ModConfigInfo GetModConfigData();
ContentPackage TryFindPackage(string packageName, bool prioritizeLocal = true);
ContentPackage TryFindPackage(int steamId);
ContentPath GetContentPath();
bool TryParsePackage(ContentPackage package);
ContentPackage Package { get; }
IModConfigInfo ModConfigInfo { get; }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Barotrauma.LuaCs.Services;

public interface IPackageManagementService : IService
{

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
using System.Xml.Linq;
using System.Collections.Immutable;
using System.Xml.Linq;

namespace Barotrauma.LuaCs.Services;

public interface IStorageService : IService
{
#region LocalGameData

bool TryLoadLocalXml(ContentPackage package, string localFilePath, out XDocument document);
bool TryLoadLocalBinary(ContentPackage package, string localFilePath, out byte[] bytes);
bool TryLoadLocalText(ContentPackage package, string localFilePath, out string text);

#endregion

#region ContentPackageData
bool TryLoadPackageXml(ContentPackage package, string localFilePath, out XDocument document);
bool TryLoadPackageBinary(ContentPackage package, string localFilePath, out byte[] bytes);
bool TryLoadPackageText(ContentPackage package, string localFilePath, out string text);

ImmutableArray<bool> TryLoadPackageXmlFiles(ContentPackage package, ImmutableArray<string> localFilePath, out ImmutableArray<XDocument> document);
ImmutableArray<bool> TryLoadPackageBinaryFiles(ContentPackage package, ImmutableArray<string> localFilePath, out ImmutableArray<byte[]> bytes);
ImmutableArray<bool> TryLoadPackageTextFiles(ContentPackage package, ImmutableArray<string> localFilePath, out ImmutableArray<string> text);

bool FindFilesInPackage(ContentPackage package, string localSubfolder, string regexFilter, bool searchRecursively, out ImmutableArray<string> localFilePaths);

#endregion

#region AbsolutePaths

bool TryLoadXml(string filePath, out XDocument document);
bool TrySaveXml(string filePath, in XDocument document);
bool TryLoadBinary(string filePath, out byte[] bytes);
bool TrySaveBinary(string filePath, in byte[] bytes);
bool TryLoadText(string filePath, out string text);
bool TrySaveText(string filePath, string text);
bool FileExists(string filePath);

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Barotrauma.LuaCs.Services;

public class PackageManagementService : IPackageManagementService
{
private Func<IContentPackageService> GetPackageServiceInstance { get; init; }

public PackageManagementService(Func<IContentPackageService> getPackageService)
{
this.GetPackageServiceInstance = getPackageService;
}

public void Dispose()
{
throw new System.NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Barotrauma.LuaCs.Data;
using Barotrauma.LuaCs.Services.Processing;

namespace Barotrauma.LuaCs.Services;

public partial class PackageService : IContentPackageService
{
private readonly Lazy<IXmlModConfigConverterService> _modConfigConverterService;
private readonly Lazy<IXmlLegacyModConfigConverterService> _legacyConfigConverterService;
private readonly Lazy<IXmlLocalizationResConverterService> _localizationConverterService;
private readonly IStorageService _storageService;
private readonly ILoggerService _loggerService;

// cctor in server source and client source

public ContentPackage Package { get; private set; }

public IModConfigInfo ModConfigInfo { get; private set; }

public bool TryParsePackage(ContentPackage package)
{
// scan for files: modconfig.xml

// on fail, scan and try for legacy loading

// load resources info for: config, assemblies, lua files, localization

// load styles data on clients
TryParsePackageClient(package);

throw new NotImplementedException();
}

partial void TryParsePackageClient(ContentPackage package);

public void Dispose()
{
// TODO release managed resources here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public interface IXmlLocalizationResConverterService : IXmlResourceConverterServ
#region XmlToInfoParsers
public interface IXmlDependencyConverterService : IXmlResourceConverterService<IPackageDependencyInfo> { }
public interface IXmlModConfigConverterService : IXmlResourceConverterService<IModConfigInfo> { }
/// <summary>
/// Parses legacy packages that make use of the RunConfig.xml structure to produce a ModConfig.
/// </summary>
public interface IXmlLegacyModConfigConverterService : IXmlResourceConverterService<IModConfigInfo> { }

#endregion

Expand Down

0 comments on commit 9bcdb25

Please sign in to comment.