Merge branch 'master' of https://github.com/Regalis11/Barotrauma.git
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "ballastflorabehavior";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "ballastflorabehaviors";
|
||||
protected override PrefabCollection<BallastFloraPrefab> prefabs => BallastFloraPrefab.Prefabs;
|
||||
protected override PrefabCollection<BallastFloraPrefab> Prefabs => BallastFloraPrefab.Prefabs;
|
||||
|
||||
protected override BallastFloraPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "cave";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "cavegenerationparameters";
|
||||
protected override PrefabCollection<CaveGenerationParams> prefabs => CaveGenerationParams.CaveParams;
|
||||
protected override PrefabCollection<CaveGenerationParams> Prefabs => CaveGenerationParams.CaveParams;
|
||||
protected override CaveGenerationParams CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new CaveGenerationParams(element, this);
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ namespace Barotrauma
|
||||
{
|
||||
HashSet<string> texturePaths = new HashSet<string>
|
||||
{
|
||||
ragdollParams.Texture
|
||||
ContentPath.FromRaw(CharacterPrefab.Prefabs[speciesName].ContentPackage, ragdollParams.Texture).Value
|
||||
};
|
||||
foreach (RagdollParams.LimbParams limb in ragdollParams.Limbs)
|
||||
{
|
||||
|
||||
+24
-8
@@ -2,12 +2,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -69,10 +67,10 @@ namespace Barotrauma
|
||||
.ToImmutableHashSet();
|
||||
}
|
||||
|
||||
public static Result<ContentFile, string> CreateFromXElement(ContentPackage contentPackage, XElement element)
|
||||
public static Result<ContentFile, LoadError> CreateFromXElement(ContentPackage contentPackage, XElement element)
|
||||
{
|
||||
static Result<ContentFile, string> fail(string error, string? stackTrace = null)
|
||||
=> Result<ContentFile, string>.Failure(error, stackTrace);
|
||||
static Result<ContentFile, LoadError> fail(string error, Exception? exception = null)
|
||||
=> Result<ContentFile, LoadError>.Failure(new LoadError(error, exception));
|
||||
|
||||
Identifier elemName = element.NameAsIdentifier();
|
||||
var type = Types.FirstOrDefault(t => t.Names.Contains(elemName));
|
||||
@@ -95,11 +93,11 @@ namespace Barotrauma
|
||||
var file = type.CreateInstance(contentPackage, filePath);
|
||||
return file is null
|
||||
? throw new Exception($"Content type is not implemented correctly")
|
||||
: Result<ContentFile, string>.Success(file);
|
||||
: Result<ContentFile, LoadError>.Success(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return fail($"Failed to load file \"{filePath}\" of type \"{elemName}\": {e.Message}", e.StackTrace.CleanupStackTrace());
|
||||
return fail($"Failed to load file \"{filePath}\" of type \"{elemName}\": {e.Message}", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,5 +123,23 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public bool NotSyncedInMultiplayer => Types.Any(t => t.Type == GetType() && t.NotSyncedInMultiplayer);
|
||||
|
||||
public readonly struct LoadError
|
||||
{
|
||||
public readonly string Message;
|
||||
public readonly Exception? Exception;
|
||||
|
||||
public LoadError(string message, Exception? exception)
|
||||
{
|
||||
Message = message;
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> Message
|
||||
+ (Exception is { StackTrace: var stackTrace }
|
||||
? '\n' + stackTrace.CleanupStackTrace()
|
||||
: string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "corpse";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "corpses";
|
||||
protected override PrefabCollection<CorpsePrefab> prefabs => CorpsePrefab.Prefabs;
|
||||
protected override PrefabCollection<CorpsePrefab> Prefabs => CorpsePrefab.Prefabs;
|
||||
protected override CorpsePrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new CorpsePrefab(element, this);
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "EventManagerSettings";
|
||||
protected override PrefabCollection<EventManagerSettings> prefabs => EventManagerSettings.Prefabs;
|
||||
protected override PrefabCollection<EventManagerSettings> Prefabs => EventManagerSettings.Prefabs;
|
||||
protected override EventManagerSettings CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new EventManagerSettings(element, this);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "faction";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "factions";
|
||||
protected override PrefabCollection<FactionPrefab> prefabs => FactionPrefab.Prefabs;
|
||||
protected override PrefabCollection<FactionPrefab> Prefabs => FactionPrefab.Prefabs;
|
||||
protected override FactionPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new FactionPrefab(element, this);
|
||||
|
||||
+6
-6
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected abstract bool MatchesSingular(Identifier identifier);
|
||||
protected abstract bool MatchesPlural(Identifier identifier);
|
||||
protected abstract PrefabCollection<T> prefabs { get; }
|
||||
protected abstract PrefabCollection<T> Prefabs { get; }
|
||||
protected abstract T CreatePrefab(ContentXElement element);
|
||||
|
||||
private void LoadFromXElement(ContentXElement parentElement, bool overriding)
|
||||
@@ -29,14 +29,14 @@ namespace Barotrauma
|
||||
}
|
||||
else if (elemName == "clear")
|
||||
{
|
||||
prefabs.AddOverrideFile(this);
|
||||
Prefabs.AddOverrideFile(this);
|
||||
}
|
||||
else if (MatchesSingular(elemName))
|
||||
{
|
||||
T prefab = CreatePrefab(parentElement);
|
||||
try
|
||||
{
|
||||
prefabs.Add(prefab, overriding);
|
||||
Prefabs.Add(prefab, overriding);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -53,7 +53,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
DebugConsole.ThrowError($"GenericPrefabFile: Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ namespace Barotrauma
|
||||
|
||||
public override sealed void UnloadFile()
|
||||
{
|
||||
prefabs.RemoveByFile(this);
|
||||
Prefabs.RemoveByFile(this);
|
||||
}
|
||||
|
||||
public sealed override void Sort()
|
||||
{
|
||||
prefabs.SortAll();
|
||||
Prefabs.SortAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "itemassembly";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "itemassemblies";
|
||||
protected override PrefabCollection<ItemAssemblyPrefab> prefabs => ItemAssemblyPrefab.Prefabs;
|
||||
protected override PrefabCollection<ItemAssemblyPrefab> Prefabs => ItemAssemblyPrefab.Prefabs;
|
||||
protected override ItemAssemblyPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new ItemAssemblyPrefab(element, this);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "items";
|
||||
protected override PrefabCollection<ItemPrefab> prefabs => ItemPrefab.Prefabs;
|
||||
protected override PrefabCollection<ItemPrefab> Prefabs => ItemPrefab.Prefabs;
|
||||
protected override ItemPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new ItemPrefab(element, this);
|
||||
|
||||
@@ -22,11 +22,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (var element in mainElement.Elements())
|
||||
{
|
||||
if (element.NameAsIdentifier() == "nojob")
|
||||
{
|
||||
JobPrefab.NoJobElement ??= element;
|
||||
}
|
||||
else if (element.NameAsIdentifier() == "ItemRepairPriorities")
|
||||
if (element.NameAsIdentifier() == "ItemRepairPriorities")
|
||||
{
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "levelobjects";
|
||||
protected override PrefabCollection<LevelObjectPrefab> prefabs => LevelObjectPrefab.Prefabs;
|
||||
protected override PrefabCollection<LevelObjectPrefab> Prefabs => LevelObjectPrefab.Prefabs;
|
||||
protected override LevelObjectPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new LevelObjectPrefab(element, this);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "locationtypes";
|
||||
protected override PrefabCollection<LocationType> prefabs => LocationType.Prefabs;
|
||||
protected override PrefabCollection<LocationType> Prefabs => LocationType.Prefabs;
|
||||
protected override LocationType CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new LocationType(element, this);
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ namespace Barotrauma
|
||||
/*missionTypes.Any(t => identifier == t.Name)
|
||||
|| identifier == "OutpostDestroyMission" || identifier == "OutpostRescueMission";*/
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "missions";
|
||||
protected override PrefabCollection<MissionPrefab> prefabs => MissionPrefab.Prefabs;
|
||||
protected override PrefabCollection<MissionPrefab> Prefabs => MissionPrefab.Prefabs;
|
||||
protected override MissionPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new MissionPrefab(element, this);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "npcset";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "npcsets";
|
||||
protected override PrefabCollection<NPCSet> prefabs => NPCSet.Sets;
|
||||
protected override PrefabCollection<NPCSet> Prefabs => NPCSet.Sets;
|
||||
protected override NPCSet CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new NPCSet(element, this);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
DebugConsole.ThrowError($"OrdersFile: Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "OutpostConfig";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "OutpostGenerationParameters";
|
||||
protected override PrefabCollection<OutpostGenerationParams> prefabs => OutpostGenerationParams.OutpostParams;
|
||||
protected override PrefabCollection<OutpostGenerationParams> Prefabs => OutpostGenerationParams.OutpostParams;
|
||||
protected override OutpostGenerationParams CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new OutpostGenerationParams(element, this);
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "prefabs" || identifier == "particles";
|
||||
protected override PrefabCollection<ParticlePrefab> prefabs => ParticlePrefab.Prefabs;
|
||||
protected override PrefabCollection<ParticlePrefab> Prefabs => ParticlePrefab.Prefabs;
|
||||
protected override ParticlePrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new ParticlePrefab(element, this);
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
DebugConsole.ThrowError($"RandomEventsFile: Invalid {GetType().Name} element: {parentElement.Name} in {Path}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "RuinConfig";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "RuinGenerationParameters";
|
||||
protected override PrefabCollection<RuinGenerationParams> prefabs => RuinGenerationParams.RuinParams;
|
||||
protected override PrefabCollection<RuinGenerationParams> Prefabs => RuinGenerationParams.RuinParams;
|
||||
protected override RuinGenerationParams CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new RuinGenerationParams(element, this);
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Barotrauma
|
||||
{
|
||||
public SoundsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
|
||||
|
||||
protected override PrefabCollection<SoundPrefab> prefabs => SoundPrefab.Prefabs;
|
||||
protected override PrefabCollection<SoundPrefab> Prefabs => SoundPrefab.Prefabs;
|
||||
|
||||
protected override SoundPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
sealed class StartItemsFile : GenericPrefabFile<StartItemSet>
|
||||
{
|
||||
public StartItemsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "itemset";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "startitems";
|
||||
protected override PrefabCollection<StartItemSet> Prefabs => StartItemSet.Sets;
|
||||
protected override StartItemSet CreatePrefab(ContentXElement element) => new StartItemSet(element, this);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => !MatchesPlural(identifier);
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "prefabs" || identifier == "structures";
|
||||
protected override PrefabCollection<StructurePrefab> prefabs => StructurePrefab.Prefabs;
|
||||
protected override PrefabCollection<StructurePrefab> Prefabs => StructurePrefab.Prefabs;
|
||||
protected override StructurePrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new StructurePrefab(element, this);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "talenttree";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "talenttrees";
|
||||
protected override PrefabCollection<TalentTree> prefabs => TalentTree.JobTalentTrees;
|
||||
protected override PrefabCollection<TalentTree> Prefabs => TalentTree.JobTalentTrees;
|
||||
protected override TalentTree CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new TalentTree(element, this);
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "talent";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "talents";
|
||||
protected override PrefabCollection<TalentPrefab> prefabs => TalentPrefab.TalentPrefabs;
|
||||
protected override PrefabCollection<TalentPrefab> Prefabs => TalentPrefab.TalentPrefabs;
|
||||
protected override TalentPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new TalentPrefab(element, this);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ namespace Barotrauma
|
||||
|
||||
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 PrefabCollection<PrefabType> Prefabs => PrefabType.Prefabs;
|
||||
protected override PrefabType CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new PrefabType(element, this);
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ namespace Barotrauma
|
||||
protected override bool MatchesPlural(Identifier identifier) =>
|
||||
identifier == "upgrademodules";
|
||||
|
||||
protected override PrefabCollection<UpgradeContentPrefab> prefabs => UpgradeContentPrefab.PrefabsAndCategories;
|
||||
protected override PrefabCollection<UpgradeContentPrefab> Prefabs => UpgradeContentPrefab.PrefabsAndCategories;
|
||||
protected override UpgradeContentPrefab CreatePrefab(ContentXElement element)
|
||||
{
|
||||
Identifier elemName = element.NameAsIdentifier();
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace Barotrauma
|
||||
|
||||
protected override bool MatchesSingular(Identifier identifier) => identifier == "wreckaiconfig";
|
||||
protected override bool MatchesPlural(Identifier identifier) => identifier == "wreckaiconfigs";
|
||||
protected override PrefabCollection<WreckAIConfig> prefabs => WreckAIConfig.Prefabs;
|
||||
protected override PrefabCollection<WreckAIConfig> Prefabs => WreckAIConfig.Prefabs;
|
||||
protected override WreckAIConfig CreatePrefab(ContentXElement element)
|
||||
{
|
||||
return new WreckAIConfig(element, this);
|
||||
|
||||
+55
-35
@@ -14,8 +14,7 @@ namespace Barotrauma
|
||||
{
|
||||
public abstract class ContentPackage
|
||||
{
|
||||
#warning TODO: make this independent of the current version
|
||||
public static readonly Version MinimumHashCompatibleVersion = GameMain.Version;
|
||||
public static readonly Version MinimumHashCompatibleVersion = new Version(0, 18, 3, 0);
|
||||
|
||||
public const string LocalModsDir = "LocalMods";
|
||||
public static readonly string WorkshopModsDir = Barotrauma.IO.Path.Combine(
|
||||
@@ -34,11 +33,11 @@ namespace Barotrauma
|
||||
|
||||
public readonly Version GameVersion;
|
||||
public readonly string ModVersion;
|
||||
public readonly Md5Hash Hash;
|
||||
public Md5Hash Hash { get; private set; }
|
||||
public readonly DateTime? InstallTime;
|
||||
|
||||
public readonly ImmutableArray<ContentFile> Files;
|
||||
public readonly ImmutableArray<(string error, string? stackTrace)> Errors;
|
||||
public ImmutableArray<ContentFile> Files { get; private set; }
|
||||
public ImmutableArray<ContentFile.LoadError> Errors { get; private set; }
|
||||
|
||||
public async Task<bool> IsUpToDate()
|
||||
{
|
||||
@@ -56,7 +55,7 @@ namespace Barotrauma
|
||||
/// <summary>
|
||||
/// Does the content package include some content that needs to match between all players in multiplayer.
|
||||
/// </summary>
|
||||
public readonly bool HasMultiplayerSyncedContent;
|
||||
public bool HasMultiplayerSyncedContent { get; private set; }
|
||||
|
||||
protected ContentPackage(XDocument doc, string path)
|
||||
{
|
||||
@@ -85,13 +84,13 @@ namespace Barotrauma
|
||||
.ToArray();
|
||||
|
||||
Files = fileResults
|
||||
.OfType<Success<ContentFile, string>>()
|
||||
.OfType<Success<ContentFile, ContentFile.LoadError>>()
|
||||
.Select(f => f.Value)
|
||||
.ToImmutableArray();
|
||||
|
||||
Errors = fileResults
|
||||
.OfType<Failure<ContentFile, string>>()
|
||||
.Select(f => (f.Error, f.StackTrace))
|
||||
.OfType<Failure<ContentFile, ContentFile.LoadError>>()
|
||||
.Select(f => f.Error)
|
||||
.ToImmutableArray();
|
||||
|
||||
HasMultiplayerSyncedContent = Files.Any(f => !f.NotSyncedInMultiplayer);
|
||||
@@ -128,18 +127,13 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
if (doc.Root.GetAttributeBool("corepackage", false))
|
||||
{
|
||||
return new CorePackage(doc, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new RegularPackage(doc, path);
|
||||
}
|
||||
return doc.Root.GetAttributeBool("corepackage", false)
|
||||
? (ContentPackage)new CorePackage(doc, path)
|
||||
: new RegularPackage(doc, path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
while (e.InnerException != null) { e = e.InnerException; }
|
||||
e = e.GetInnermost();
|
||||
DebugConsole.ThrowError($"{e.Message}: {e.StackTrace}");
|
||||
return null;
|
||||
}
|
||||
@@ -279,12 +273,42 @@ namespace Barotrauma
|
||||
Files.ForEach(f => f.UnloadFile());
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
public void ReloadSubsAndItemAssemblies()
|
||||
{
|
||||
byte[] shortHash = Encoding.ASCII.GetBytes(Hash.StringRepresentation.Substring(0, 4));
|
||||
return (shortHash[0] << 24) | (shortHash[1] << 16) | (shortHash[2] << 8) | shortHash[3];
|
||||
XDocument doc = XMLExtensions.TryLoadXml(Path);
|
||||
List<ContentFile> newFileList = new List<ContentFile>();
|
||||
XElement rootElement = doc.Root ?? throw new NullReferenceException("XML document is invalid: root element is null.");
|
||||
|
||||
var fileResults = rootElement.Elements()
|
||||
.Select(e => ContentFile.CreateFromXElement(this, e))
|
||||
.ToArray();
|
||||
|
||||
foreach (var result in fileResults)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case Success<ContentFile, ContentFile.LoadError> { Value: var file }:
|
||||
if (file is BaseSubFile || file is ItemAssemblyFile)
|
||||
{
|
||||
newFileList.Add(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
var existingFile = Files.FirstOrDefault(f => f.Path == file.Path);
|
||||
newFileList.Add(existingFile ?? file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UnloadFilesOfType<BaseSubFile>();
|
||||
UnloadFilesOfType<ItemAssemblyFile>();
|
||||
Files = newFileList.ToImmutableArray();
|
||||
Hash = CalculateHash();
|
||||
LoadFilesOfType<BaseSubFile>();
|
||||
LoadFilesOfType<ItemAssemblyFile>();
|
||||
}
|
||||
|
||||
|
||||
public static bool PathAllowedAsLocalModFile(string path)
|
||||
{
|
||||
#if DEBUG
|
||||
@@ -306,21 +330,17 @@ namespace Barotrauma
|
||||
|
||||
public void LogErrors()
|
||||
{
|
||||
if (Errors.Any())
|
||||
if (!Errors.Any())
|
||||
{
|
||||
DebugConsole.AddWarning(
|
||||
$"The following errors occurred while loading the content package\"{Name}\". The package might not work correctly.\n" +
|
||||
string.Join('\n', Errors.Select(e => errorToStr(e.error, e.stackTrace))));
|
||||
static string errorToStr(string error, string? stackTrace)
|
||||
{
|
||||
string str = error;
|
||||
if (stackTrace != null)
|
||||
{
|
||||
str += '\n' + stackTrace;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
DebugConsole.AddWarning(
|
||||
$"The following errors occurred while loading the content package \"{Name}\". The package might not work correctly.\n" +
|
||||
string.Join('\n', Errors.Select(errorToStr)));
|
||||
|
||||
static string errorToStr(ContentFile.LoadError error)
|
||||
=> error.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -430,9 +430,9 @@ namespace Barotrauma
|
||||
public static void LoadVanillaFileList()
|
||||
{
|
||||
VanillaCorePackage = new CorePackage(XDocument.Load(VanillaFileList), VanillaFileList);
|
||||
foreach ((string error, string? stackTrace) in VanillaCorePackage.Errors)
|
||||
foreach (ContentFile.LoadError error in VanillaCorePackage.Errors)
|
||||
{
|
||||
DebugConsole.ThrowError(error + (stackTrace == null ? string.Empty : '\n' + stackTrace));
|
||||
DebugConsole.ThrowError(error.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,10 @@ namespace Barotrauma
|
||||
.Replace(string.Format(OtherModDirFmt, ContentPackage.SteamWorkshopId.ToString(CultureInfo.InvariantCulture)), modPath, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
var allPackages = ContentPackageManager.EnabledPackages.All;
|
||||
var allPackages = ContentPackageManager.AllPackages;
|
||||
#if CLIENT
|
||||
if (GameMain.ModDownloadScreen?.DownloadedPackages != null) { allPackages = allPackages.Concat(GameMain.ModDownloadScreen.DownloadedPackages); }
|
||||
#endif
|
||||
foreach (Identifier otherModName in otherMods)
|
||||
{
|
||||
if (!UInt64.TryParse(otherModName.Value, out UInt64 workshopId)) { workshopId = 0; }
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Barotrauma
|
||||
|
||||
public string BaseUri => Element.BaseUri;
|
||||
|
||||
public XDocument Document => Element.Document ?? throw new NullReferenceException("XML element is invalid: document is null.");
|
||||
public XDocument? Document => Element.Document;
|
||||
|
||||
public ContentXElement? FirstElement() => Elements().FirstOrDefault();
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Barotrauma
|
||||
{
|
||||
Message = $"\"{whoAsked?.Name ?? "[NULL]"}\" depends on a package " +
|
||||
$"with name or ID \"{missingPackage ?? "[NULL]"}\" " +
|
||||
$"that is not currently enabled.";
|
||||
$"that is not currently installed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user