Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -1,93 +1,37 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
internal class NPCSet : IDisposable
internal class NPCSet : Prefab
{
private static List<NPCSet>? Sets { get; set; }
public readonly static PrefabCollection<NPCSet> Sets = new PrefabCollection<NPCSet>();
private string Identifier { get; }
private readonly List<HumanPrefab> Humans = new List<HumanPrefab>();
private readonly ImmutableArray<HumanPrefab> Humans;
private bool Disposed { get; set; }
private NPCSet(XElement element, string filePath)
public NPCSet(ContentXElement element, NPCSetsFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
{
Identifier = element.GetAttributeString("identifier", string.Empty);
foreach (XElement npcElement in element.Elements())
{
Humans.Add(new HumanPrefab(npcElement, filePath));
}
Humans = element.Elements().Select(npcElement => new HumanPrefab(npcElement, file)).ToImmutableArray();
}
public static HumanPrefab? Get(string identifier, string npcidentifier)
public static HumanPrefab? Get(Identifier setIdentifier, Identifier npcidentifier)
{
HumanPrefab prefab = Sets.Where(set => set.Identifier == identifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();
HumanPrefab? prefab = Sets.Where(set => set.Identifier == setIdentifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();
if (prefab == null)
{
DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{identifier}\".");
DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{setIdentifier}\".");
return null;
}
return new HumanPrefab(prefab.Element, prefab.FilePath);
}
public static void LoadSets()
{
Sets?.ForEach(set => set.Dispose());
Sets = new List<NPCSet>();
IEnumerable<ContentFile> files = GameMain.Instance.GetFilesOfType(ContentType.NPCSets);
foreach (ContentFile file in files)
{
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
XElement? rootElement = doc?.Root;
if (doc == null || rootElement == null) { continue; }
if (doc.Root.IsOverride())
{
Sets.Clear();
DebugConsole.NewMessage($"Overriding all NPC sets with '{file.Path}'", Color.Yellow);
}
foreach (XElement element in rootElement.Elements())
{
bool isOverride = element.IsOverride();
XElement sourceElement = isOverride ? element.FirstElement() : element;
string elementName = sourceElement.Name.ToString().ToLowerInvariant();
string identifier = sourceElement.GetAttributeString("identifier", null);
if (string.IsNullOrWhiteSpace(identifier))
{
DebugConsole.ThrowError($"No identifier defined for the NPC set config '{elementName}' in file '{file.Path}'");
continue;
}
var existingParams = Sets.Find(set => set.Identifier == identifier);
if (existingParams != null)
{
if (isOverride)
{
DebugConsole.NewMessage($"Overriding NPC set config '{identifier}' using the file '{file.Path}'", Color.Yellow);
Sets.Remove(existingParams);
}
else
{
DebugConsole.ThrowError($"Duplicate NPC set config: '{identifier}' defined in {elementName} of '{file.Path}'");
continue;
}
}
Sets.Add(new NPCSet(element, file.Path));
}
}
return prefab;
}
private void Dispose(bool disposing)
@@ -103,7 +47,7 @@ namespace Barotrauma
Disposed = true;
}
public void Dispose()
public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);