Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/SharedSource/ContentManagement/ContentFile/NPCConversationsFile.cs
2023-12-14 16:11:27 +02:00

45 lines
1.6 KiB
C#

using System.Xml.Linq;
namespace Barotrauma
{
[NotSyncedInMultiplayer]
sealed class NPCConversationsFile : ContentFile
{
public NPCConversationsFile(ContentPackage contentPackage, ContentPath path) : base(contentPackage, path) { }
public override void LoadFile()
{
XDocument doc = XMLExtensions.TryLoadXml(Path);
if (doc == null) { return; }
var mainElement = doc.Root.FromPackage(ContentPackage);
bool allowOverriding = doc.Root.IsOverride();
if (allowOverriding)
{
mainElement = mainElement.FirstElement();
}
var npcConversationCollection = new NPCConversationCollection(this, mainElement);
if (!NPCConversationCollection.Collections.ContainsKey(npcConversationCollection.Language))
{
NPCConversationCollection.Collections.Add(npcConversationCollection.Language, new PrefabCollection<NPCConversationCollection>());
}
NPCConversationCollection.Collections[npcConversationCollection.Language].Add(npcConversationCollection, allowOverriding);
}
public override void UnloadFile()
{
foreach (var collection in NPCConversationCollection.Collections.Values)
{
collection.RemoveByFile(this);
}
}
public override void Sort()
{
foreach (var collection in NPCConversationCollection.Collections.Values)
{
collection.SortAll();
}
}
}
}