Unstable 0.17.4.0

This commit is contained in:
Markus Isberg
2022-03-30 00:08:09 +09:00
parent 2968e23ae8
commit c1b8e5a341
177 changed files with 3388 additions and 1977 deletions
@@ -30,6 +30,7 @@ namespace Barotrauma
public readonly bool NotSyncedInMultiplayer;
public readonly ImmutableHashSet<Type>? AlternativeTypes;
public readonly ImmutableHashSet<Identifier> Names;
private readonly MethodInfo? contentPathMutator;
public TypeInfo(Type type)
{
@@ -40,9 +41,11 @@ namespace Barotrauma
var notSyncedInMultiplayerAttribute = type.GetCustomAttribute<NotSyncedInMultiplayer>();
NotSyncedInMultiplayer = notSyncedInMultiplayerAttribute != null;
AlternativeTypes = reqByCoreAttribute?.AlternativeTypes;
contentPathMutator
= Type.GetMethod(nameof(MutateContentPath), BindingFlags.Static | BindingFlags.Public);
HashSet<Identifier> names = new HashSet<Identifier> { type.Name.RemoveFromEnd("File").ToIdentifier() };
if (type.GetCustomAttribute<AlternativeContentTypeNames>()?.Names is { } altNames)
if (type.GetCustomAttribute<AlternativeContentTypeNames>(inherit: false)?.Names is { } altNames)
{
names.UnionWith(altNames);
}
@@ -50,6 +53,10 @@ namespace Barotrauma
Names = names.ToImmutableHashSet();
}
public ContentPath MutateContentPath(ContentPath path)
=> (ContentPath?)contentPathMutator?.Invoke(null, new object[] { path })
?? path;
public ContentFile? CreateInstance(ContentPackage contentPackage, ContentPath path) =>
(ContentFile?)Activator.CreateInstance(Type, contentPackage, path);
}
@@ -80,6 +87,7 @@ namespace Barotrauma
}
try
{
filePath = type.MutateContentPath(filePath);
if (!File.Exists(filePath.FullPath))
{
return fail($"Failed to load file \"{filePath}\" of type \"{elemName}\": file not found.");
@@ -0,0 +1,28 @@
using System;
using Barotrauma.IO;
namespace Barotrauma
{
sealed class ServerExecutableFile : OtherFile
{
//This content type doesn't do very much on its own, it's handled manually by the Host Server menu
public ServerExecutableFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
public static ContentPath MutateContentPath(ContentPath path)
{
if (File.Exists(path.FullPath)) { return path; }
string rawValueWithoutExtension()
=> Barotrauma.IO.Path.Combine(
Barotrauma.IO.Path.GetDirectoryName(path.RawValue ?? ""),
Barotrauma.IO.Path.GetFileNameWithoutExtension(path.RawValue ?? "")).CleanUpPath();
path = ContentPath.FromRaw(path.ContentPackage, rawValueWithoutExtension());
if (File.Exists(path.FullPath)) { return path; }
path = ContentPath.FromRaw(path.ContentPackage,
rawValueWithoutExtension() + ".exe");
return path;
}
}
}
@@ -110,7 +110,7 @@ namespace Barotrauma
!expectedHash.IsNullOrWhiteSpace() &&
!expectedHash.Equals(Hash.StringRepresentation, StringComparison.OrdinalIgnoreCase);
public IEnumerable<T> GetFiles<T>() where T : ContentFile => Files.Where(f => f is T).Cast<T>();
public IEnumerable<T> GetFiles<T>() where T : ContentFile => Files.OfType<T>();
public IEnumerable<ContentFile> GetFiles(Type type)
=> !type.IsSubclassOf(typeof(ContentFile))
@@ -8,7 +8,7 @@ using System.Xml.Linq;
namespace Barotrauma
{
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class RequiredByCorePackage : Attribute
{
public readonly ImmutableHashSet<Type> AlternativeTypes;
@@ -18,7 +18,7 @@ namespace Barotrauma
}
}
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class AlternativeContentTypeNames : Attribute
{
public readonly ImmutableHashSet<Identifier> Names;
@@ -51,7 +51,7 @@ namespace Barotrauma
Core?.UnloadPackage();
Core = newCore;
foreach (var p in newCore.LoadPackageEnumerable()) { yield return p; }
ThrowIfDuplicates(All);
SortContent();
yield return new LoadProgress(1.0f);
}
@@ -60,7 +60,7 @@ namespace Barotrauma
if (Core == null) { return; }
Core.UnloadPackage();
Core.LoadPackage();
ThrowIfDuplicates(All);
SortContent();
}
public static void EnableRegular(RegularPackage p)
@@ -133,7 +133,7 @@ namespace Barotrauma
}
}
public static void SortContent()
private static void SortContent()
{
ThrowIfDuplicates(All);
All
@@ -165,6 +165,20 @@ namespace Barotrauma
SetRegular(Regular.Where(p => ContentPackageManager.RegularPackages.Contains(p)).ToArray());
}
public static void RefreshUpdatedMods()
{
if (Core != null && !ContentPackageManager.CorePackages.Contains(Core))
{
SetCore(ContentPackageManager.WorkshopPackages.Core.FirstOrDefault(p => p.SteamWorkshopId == Core.SteamWorkshopId) ??
ContentPackageManager.CorePackages.First());
}
SetRegular(Regular
.Select(p => ContentPackageManager.RegularPackages.Contains(p)
? p
: ContentPackageManager.WorkshopPackages.Regular.FirstOrDefault(p2 => p2.SteamWorkshopId == p.SteamWorkshopId))
.ToArray());
}
public static void BackUp()
{
if (BackupPackages.Core != null || BackupPackages.Regular != null)
@@ -327,7 +341,8 @@ namespace Barotrauma
=> LocalPackages.Regular.CollectionConcat(WorkshopPackages.Regular);
public static IEnumerable<ContentPackage> AllPackages
=> LocalPackages.CollectionConcat(WorkshopPackages);
=> VanillaCorePackage.ToEnumerable().CollectionConcat(LocalPackages).CollectionConcat(WorkshopPackages)
.OfType<ContentPackage>();
public static void UpdateContentPackageList()
{
@@ -447,13 +462,13 @@ namespace Barotrauma
int pkgCount = 1 + enabledRegularPackages.Count; //core + regular
loadingRange = new Range<float>(0.01f, 1.0f / pkgCount);
loadingRange = new Range<float>(0.01f, 0.01f + (0.99f / pkgCount));
foreach (var p in EnabledPackages.SetCoreEnumerable(enabledCorePackage))
{
yield return p.Transform(loadingRange);
}
loadingRange = new Range<float>(1.0f / pkgCount, 1.0f);
loadingRange = new Range<float>(0.01f + (0.99f / pkgCount), 1.0f);
foreach (var p in EnabledPackages.SetRegularEnumerable(enabledRegularPackages))
{
yield return p.Transform(loadingRange);
@@ -49,7 +49,7 @@ namespace Barotrauma
.Replace(string.Format(OtherModDirFmt, ContentPackage.SteamWorkshopId.ToString(CultureInfo.InvariantCulture)), modPath, StringComparison.OrdinalIgnoreCase);
}
}
var allPackages = ContentPackageManager.AllPackages;
var allPackages = ContentPackageManager.EnabledPackages.All;
foreach (Identifier otherModName in otherMods)
{
if (!UInt64.TryParse(otherModName.Value, out UInt64 workshopId)) { workshopId = 0; }
@@ -53,8 +53,6 @@ namespace Barotrauma
public IEnumerable<ContentXElement> GetChildElements(string name)
=> Elements().Where(e => string.Equals(name, e.Name.LocalName, StringComparison.CurrentCultureIgnoreCase));
public XAttribute? Attribute(string name) => Element.Attribute(name);
public XAttribute? GetAttribute(string name) => Element.GetAttribute(name);
public IEnumerable<XAttribute> Attributes() => Element.Attributes();
@@ -11,7 +11,7 @@ namespace Barotrauma
{
Message = $"\"{whoAsked?.Name ?? "[NULL]"}\" depends on a package " +
$"with name or ID \"{missingPackage ?? "[NULL]"}\" " +
$"that is not currently installed.";
$"that is not currently enabled.";
}
}
}