Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -67,6 +67,22 @@ namespace Barotrauma
.ToImmutableHashSet();
}
public static bool IsLegacyContentType(XElement contentFileElement, ContentPackage package, bool logWarning)
{
Identifier elemName = contentFileElement.NameAsIdentifier();
if (elemName == "TraitorMissions")
{
if (logWarning)
{
DebugConsole.AddWarning(
$"The content type \"TraitorMission\" in content package \"{package.Name}\" is no longer supported." +
$" Traitor missions should be implemented using the scripted event system and the content type TraitorEvents.");
}
return true;
}
return false;
}
public static Result<ContentFile, ContentPackage.LoadError> CreateFromXElement(ContentPackage contentPackage, XElement element)
{
static Result<ContentFile, ContentPackage.LoadError> fail(string error, Exception? exception = null)
@@ -28,8 +28,16 @@ namespace Barotrauma
{
foreach (var subElement in parentElement.Elements())
{
var prefab = new EventPrefab(subElement, this);
EventPrefab.Prefabs.Add(prefab, overriding);
if (subElement.NameAsIdentifier() == "traitorevent")
{
var prefab = new TraitorEventPrefab(subElement, this);
EventPrefab.Prefabs.Add(prefab, overriding);
}
else
{
var prefab = new EventPrefab(subElement, this);
EventPrefab.Prefabs.Add(prefab, overriding);
}
}
}
else if (elemName == "eventsprites")
@@ -28,6 +28,10 @@ namespace Barotrauma
{
//Overrides for subs don't exist! Should we change this?
}
// Use byte-perfect hash because this is compressed, trimming whitespace is incorrect and needlessly slow here
public override Md5Hash CalculateHash()
=> Md5Hash.CalculateForFile(Path.FullPath, Md5Hash.StringHashOptions.BytePerfect);
}
[NotSyncedInMultiplayer]
@@ -1,26 +0,0 @@
using System.Xml.Linq;
#warning TODO: This file is just about the only thing that's actually somewhat okay about the current traitor system. Gut the whole thing.
#if CLIENT
using PrefabType = Barotrauma.TraitorMissionPrefab;
#elif SERVER
using PrefabType = Barotrauma.TraitorMissionPrefab.TraitorMissionEntry;
#endif
namespace Barotrauma
{
[RequiredByCorePackage]
sealed class TraitorMissionsFile : GenericPrefabFile<PrefabType>
{
public TraitorMissionsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
protected override bool MatchesSingular(Identifier identifier) => identifier == "TraitorMission";
protected override bool MatchesPlural(Identifier identifier) => identifier == "TraitorMissions";
protected override PrefabCollection<PrefabType> Prefabs => PrefabType.Prefabs;
protected override PrefabType CreatePrefab(ContentXElement element)
{
return new PrefabType(element, this);
}
}
}
@@ -23,7 +23,7 @@ namespace Barotrauma
: string.Empty);
}
public static readonly Version MinimumHashCompatibleVersion = new Version(1, 0, 13, 2);
public static readonly Version MinimumHashCompatibleVersion = new Version(1, 1, 0, 0);
public const string LocalModsDir = "LocalMods";
public static readonly string WorkshopModsDir = Barotrauma.IO.Path.Combine(
@@ -110,6 +110,7 @@ namespace Barotrauma
InstallTime = rootElement.GetAttributeDateTime("installtime");
var fileResults = rootElement.Elements()
.Where(e => !ContentFile.IsLegacyContentType(e, this, logWarning: true))
.Select(e => ContentFile.CreateFromXElement(this, e))
.ToArray();
@@ -337,6 +338,7 @@ namespace Barotrauma
XElement rootElement = doc.Root ?? throw new NullReferenceException("XML document is invalid: root element is null.");
var fileResults = rootElement.Elements()
.Where(e => !ContentFile.IsLegacyContentType(e, this, logWarning: true))
.Select(e => ContentFile.CreateFromXElement(this, e))
.ToArray();
@@ -32,6 +32,11 @@ namespace Barotrauma
private static readonly List<RegularPackage> regular = new List<RegularPackage>();
public static IReadOnlyList<RegularPackage> Regular => regular;
/// <summary>
/// Combined hash of the currently enabled packages. Can be used to check if the enabled mods or their load order has changed.
/// </summary>
public static Md5Hash MergedHash { get; private set; } = Md5Hash.Blank;
public static IEnumerable<ContentPackage> All =>
Core != null
? (Core as ContentPackage).ToEnumerable().CollectionConcat(Regular)
@@ -149,6 +154,7 @@ namespace Barotrauma
.SelectMany(r => r.Files)
.Distinct(new TypeComparer<ContentFile>())
.ForEach(f => f.Sort());
MergedHash = Md5Hash.MergeHashes(All.Select(cp => cp.Hash));
}
public static int IndexOf(ContentPackage contentPackage)
@@ -1,10 +1,9 @@
#nullable enable
using Barotrauma.IO;
using System;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Barotrauma.IO;
namespace Barotrauma
{
@@ -93,10 +92,21 @@ namespace Barotrauma
}
public static ContentPath FromRaw(string? rawValue)
=> new ContentPath(null, rawValue);
=> FromRaw(null, rawValue);
private static ContentPath? prevCreatedRaw;
public static ContentPath FromRaw(ContentPackage? contentPackage, string? rawValue)
=> new ContentPath(contentPackage, rawValue);
{
var newRaw = new ContentPath(contentPackage, rawValue);
if (prevCreatedRaw is not null && prevCreatedRaw.ContentPackage == contentPackage &&
prevCreatedRaw.RawValue == rawValue)
{
newRaw.cachedValue = prevCreatedRaw.Value;
}
prevCreatedRaw = newRaw;
return newRaw;
}
public static ContentPath FromEvaluated(ContentPackage? contentPackage, string? evaluatedValue)
{
@@ -146,8 +156,8 @@ namespace Barotrauma
return HashCode.Combine(RawValue, ContentPackage, cachedValue, cachedFullPath);
}
public bool IsNullOrEmpty() => string.IsNullOrEmpty(Value);
public bool IsNullOrWhiteSpace() => string.IsNullOrWhiteSpace(Value);
public bool IsPathNullOrEmpty() => string.IsNullOrEmpty(Value);
public bool IsPathNullOrWhiteSpace() => string.IsNullOrWhiteSpace(Value);
public bool EndsWith(string suffix) => Value.EndsWith(suffix, StringComparison.OrdinalIgnoreCase);
@@ -52,7 +52,7 @@ namespace Barotrauma
=> Element.Descendants().Select(e => new ContentXElement(ContentPackage, e));
public IEnumerable<ContentXElement> GetChildElements(string name)
=> Elements().Where(e => string.Equals(name, e.Name.LocalName, StringComparison.InvariantCultureIgnoreCase));
=> Elements().Where(e => string.Equals(name, e.Name.LocalName, StringComparison.OrdinalIgnoreCase));
public XAttribute? GetAttribute(string name) => Element.GetAttribute(name);
@@ -76,6 +76,7 @@ namespace Barotrauma
public string[]? GetAttributeStringArray(string key, string[]? def, bool convertToLowerInvariant = false) => Element.GetAttributeStringArray(key, def, convertToLowerInvariant);
public ContentPath? GetAttributeContentPath(string key) => Element.GetAttributeContentPath(key, ContentPackage);
public int GetAttributeInt(string key, int def) => Element.GetAttributeInt(key, def);
public ushort GetAttributeUInt16(string key, ushort def) => Element.GetAttributeUInt16(key, def);
public int[]? GetAttributeIntArray(string key, int[]? def) => Element.GetAttributeIntArray(key, def);
public ushort[]? GetAttributeUshortArray(string key, ushort[]? def) => Element.GetAttributeUshortArray(key, def);
public float GetAttributeFloat(string key, float def) => Element.GetAttributeFloat(key, def);