Unstable 0.17.3.0
This commit is contained in:
+9
-1
@@ -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.");
|
||||
|
||||
+28
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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))
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -327,7 +327,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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user