- Removed all package dependency lookup code.
- Changed from absolute file paths to the upstream `ContentPath` system.
This commit is contained in:
+16
-133
@@ -33,146 +33,29 @@ public record LuaScriptsResourcesInfo(ImmutableArray<ILuaScriptResourceInfo> Lua
|
||||
public record ConfigResourcesInfo(ImmutableArray<IConfigResourceInfo> Configs) : IConfigsResourcesInfo;
|
||||
public record ConfigProfilesResourcesInfo(ImmutableArray<IConfigProfileResourceInfo> ConfigProfiles) : IConfigProfilesResourcesInfo;
|
||||
|
||||
public record AssemblyResourceInfo : IAssemblyResourceInfo
|
||||
public record BaseResourceInfo : IBaseResourceInfo
|
||||
{
|
||||
public Platform SupportedPlatforms { get; init; }
|
||||
public Target SupportedTargets { get; init; }
|
||||
public int LoadPriority { get; init; }
|
||||
public ImmutableArray<ContentPath> FilePaths { get; init; }
|
||||
public bool Optional { get; init; }
|
||||
public string InternalName { get; init; }
|
||||
public ContentPackage OwnerPackage { get; init; }
|
||||
}
|
||||
|
||||
public record AssemblyResourceInfo : BaseResourceInfo, IAssemblyResourceInfo
|
||||
{
|
||||
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; }
|
||||
public int LoadPriority { get; init; }
|
||||
public ImmutableArray<string> FilePaths { get; init; }
|
||||
public ImmutableArray<CultureInfo> SupportedCultures { get; init; }
|
||||
public ImmutableArray<IPackageDependency> Dependencies { get; init; }
|
||||
public bool Optional { get; init; }
|
||||
}
|
||||
|
||||
public record PackageDependency : IPackageDependency
|
||||
public record ConfigResourceInfo : BaseResourceInfo, IConfigResourceInfo {}
|
||||
|
||||
public record ConfigProfileResourceInfo : BaseResourceInfo, IConfigProfileResourceInfo {}
|
||||
|
||||
public record LuaScriptsResourceInfo : BaseResourceInfo, ILuaScriptResourceInfo
|
||||
{
|
||||
public PackageDependency(ContentPackage package, IPackageInfo dependencyInfo, string internalName)
|
||||
{
|
||||
Dependency = dependencyInfo ?? throw new ArgumentNullException(nameof(dependencyInfo));
|
||||
OwnerPackage = package ?? throw new ArgumentNullException(nameof(package));
|
||||
InternalName = internalName ?? throw new ArgumentNullException(nameof(internalName));
|
||||
}
|
||||
public string InternalName { get; init; }
|
||||
public ContentPackage OwnerPackage { get; init; }
|
||||
public IPackageInfo Dependency { get; init; }
|
||||
public override int GetHashCode() => Dependency.GetHashCode();
|
||||
|
||||
}
|
||||
|
||||
public record PackageInfo : IPackageInfo
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public ulong SteamWorkshopId { get; private set; }
|
||||
public uint Id { get; private set; }
|
||||
|
||||
private readonly Func<IPackageInfo, ContentPackage> _getPackage;
|
||||
|
||||
public ContentPackage GetPackage() => _getPackage?.Invoke(this) ?? null;
|
||||
|
||||
public void UpdateInfo(string name, ulong steamId, uint packageId)
|
||||
{
|
||||
if (name.IsNullOrWhiteSpace() || steamId == 0 || packageId == 0)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"{nameof(PackageInfo)}: You cannot update a package with an invalid name or steam id with a valid id, or vice-versa.");
|
||||
}
|
||||
|
||||
Name = name;
|
||||
SteamWorkshopId = steamId;
|
||||
Id = packageId;
|
||||
}
|
||||
|
||||
public PackageInfo(ContentPackage package, uint id, Func<IPackageInfo, ContentPackage> getPackage)
|
||||
{
|
||||
if (package is null)
|
||||
throw new ArgumentNullException($"{nameof(PackageInfo)}: package is null");
|
||||
if (id == 0)
|
||||
throw new ArgumentNullException($"{nameof(PackageInfo)}: id is zero.");
|
||||
|
||||
this.Name = package.Name;
|
||||
this.SteamWorkshopId = package.TryExtractSteamWorkshopId(out var sId) ? sId.Value : 0;
|
||||
this.Id = id;
|
||||
this._getPackage = getPackage;
|
||||
}
|
||||
|
||||
public PackageInfo(string name, ulong steamWorkshopId, uint id, Func<IPackageInfo, ContentPackage> getPackage)
|
||||
{
|
||||
Name = !name.IsNullOrWhiteSpace() ? name : throw new ArgumentNullException($"{nameof(PackageInfo)}: name cannot be null or empty.");
|
||||
SteamWorkshopId = steamWorkshopId != 0 ? steamWorkshopId : throw new ArgumentNullException($"{nameof(PackageInfo)}: steam id cannot be 0.");
|
||||
this.Id = id;
|
||||
this._getPackage = getPackage;
|
||||
}
|
||||
|
||||
public PackageInfo(string name, uint id, Func<IPackageInfo, ContentPackage> getPackage)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException($"{nameof(PackageInfo)}: name cannot be null or empty.");
|
||||
this.SteamWorkshopId = 0;
|
||||
this.Id = id;
|
||||
this._getPackage = getPackage;
|
||||
}
|
||||
|
||||
public PackageInfo(ulong steamWorkshopId, uint id, Func<IPackageInfo, ContentPackage> getPackage)
|
||||
{
|
||||
SteamWorkshopId = steamWorkshopId != 0 ? steamWorkshopId : throw new ArgumentNullException($"{nameof(PackageInfo)}: steamid cannot be 0.");
|
||||
this.Id = id;
|
||||
this._getPackage = getPackage;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)Id;
|
||||
}
|
||||
|
||||
public virtual bool Equals(PackageInfo other)
|
||||
{
|
||||
return ((IEquatable<IPackageInfo>)this).Equals(other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public record ConfigResourceInfo : IConfigResourceInfo
|
||||
{
|
||||
public Platform SupportedPlatforms { get; init; }
|
||||
public Target SupportedTargets { get; init; }
|
||||
public int LoadPriority { get; init; }
|
||||
public ImmutableArray<string> FilePaths { get; init; }
|
||||
public bool Optional { get; init; }
|
||||
public ImmutableArray<CultureInfo> SupportedCultures { get; init; }
|
||||
public ImmutableArray<IPackageDependency> Dependencies { get; init; }
|
||||
public string InternalName { get; init; }
|
||||
public ContentPackage OwnerPackage { get; init; }
|
||||
}
|
||||
|
||||
public record ConfigProfileResourceInfo : IConfigProfileResourceInfo
|
||||
{
|
||||
public Platform SupportedPlatforms { get; init; }
|
||||
public Target SupportedTargets { get; init; }
|
||||
public int LoadPriority { get; init; }
|
||||
public ImmutableArray<string> FilePaths { get; init; }
|
||||
public bool Optional { get; init; }
|
||||
public ImmutableArray<CultureInfo> SupportedCultures { get; init; }
|
||||
public ImmutableArray<IPackageDependency> Dependencies { get; init; }
|
||||
public string InternalName { get; init; }
|
||||
public ContentPackage OwnerPackage { get; init; }
|
||||
}
|
||||
|
||||
public readonly struct LuaScriptsResourceInfo : ILuaScriptResourceInfo
|
||||
{
|
||||
public ContentPackage OwnerPackage { get; init; }
|
||||
public Platform SupportedPlatforms { get; init; }
|
||||
public Target SupportedTargets { get; init; }
|
||||
public int LoadPriority { get; init; }
|
||||
public ImmutableArray<string> FilePaths { get; init; }
|
||||
public ImmutableArray<CultureInfo> SupportedCultures { get; init; }
|
||||
public ImmutableArray<IPackageDependency> Dependencies { get; init; }
|
||||
public bool Optional { get; init; }
|
||||
public string InternalName { get; init; }
|
||||
public bool IsAutorun { get; init; }
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface IResourceInfo : IPlatformInfo
|
||||
/// Resource absolute file paths.
|
||||
/// </summary>
|
||||
[Required]
|
||||
ImmutableArray<string> FilePaths { get; }
|
||||
ImmutableArray<ContentPath> FilePaths { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Marks this resource as optional (ie. Cross-CP content). Setting this to true will allow the dependency system to
|
||||
@@ -45,14 +45,3 @@ public interface IResourceInfo : IPlatformInfo
|
||||
/// </summary>
|
||||
bool Optional { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Information about supported cultures. It is intended to be ignored if the array is ImmutableArray.Empty .
|
||||
/// </summary>
|
||||
public interface IResourceCultureInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// List of supported cultures by this resource.
|
||||
/// </summary>
|
||||
ImmutableArray<CultureInfo> SupportedCultures { get; }
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using Barotrauma;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
|
||||
namespace Barotrauma.LuaCs.Data;
|
||||
|
||||
public interface IPackageDependency : IDataInfo, IEquatable<IPackageDependency>
|
||||
{
|
||||
public IPackageInfo Dependency { get; }
|
||||
|
||||
bool IEquatable<IPackageDependency>.Equals(IPackageDependency other)
|
||||
{
|
||||
return other is not null && Dependency.Equals(other.Dependency);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPackageInfo : IEquatable<IPackageInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the content package.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
/// <summary>
|
||||
/// Steam ID of the package.
|
||||
/// </summary>
|
||||
public ulong SteamWorkshopId { get; }
|
||||
/// <summary>
|
||||
/// The Guid for the runtime instance of the package.
|
||||
/// </summary>
|
||||
public uint Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reference to the best-match target ContentPackage that meets the requirement.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="ContentPackage"/> reference, or null if none was found.</returns>
|
||||
public ContentPackage GetPackage();
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve the current best <see cref="ContentPackage"/> and returns true if none was found.
|
||||
/// </summary>
|
||||
public bool IsMissing => GetPackage() is null;
|
||||
|
||||
bool IEquatable<IPackageInfo>.Equals(IPackageInfo other)
|
||||
{
|
||||
if (other is null)
|
||||
return false;
|
||||
if (ReferenceEquals(other, this))
|
||||
return true;
|
||||
if (!this.IsMissing && !other.IsMissing && ReferenceEquals(other.GetPackage, this.GetPackage))
|
||||
return true;
|
||||
if (this.SteamWorkshopId != 0 && other.SteamWorkshopId == this.SteamWorkshopId)
|
||||
return true;
|
||||
return this.Name == other.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPackageDependenciesInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// List of required packages.
|
||||
/// </summary>
|
||||
ImmutableArray<IPackageDependency> Dependencies { get; }
|
||||
}
|
||||
@@ -4,13 +4,17 @@ using System.Globalization;
|
||||
|
||||
namespace Barotrauma.LuaCs.Data;
|
||||
|
||||
public interface IConfigResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, IDataInfo { }
|
||||
public interface IConfigProfileResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, IDataInfo { }
|
||||
|
||||
public interface IBaseResourceInfo : IResourceInfo, IDataInfo {}
|
||||
|
||||
public interface IConfigResourceInfo : IBaseResourceInfo {}
|
||||
|
||||
public interface IConfigProfileResourceInfo :IBaseResourceInfo {}
|
||||
|
||||
/// <summary>
|
||||
/// Represents loadable Lua files.
|
||||
/// </summary>
|
||||
public interface ILuaScriptResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, IDataInfo
|
||||
public interface ILuaScriptResourceInfo : IBaseResourceInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Should this script be run automatically.
|
||||
@@ -18,7 +22,7 @@ public interface ILuaScriptResourceInfo : IResourceInfo, IResourceCultureInfo, I
|
||||
public bool IsAutorun { get; }
|
||||
}
|
||||
|
||||
public interface IAssemblyResourceInfo : IResourceInfo, IResourceCultureInfo, IPackageDependenciesInfo, IDataInfo
|
||||
public interface IAssemblyResourceInfo : IBaseResourceInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The friendly name of the assembly. Script files belonging to the same assembly should all have the same name.
|
||||
|
||||
Reference in New Issue
Block a user