(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Xml.Linq;
using Barotrauma.Extensions;
namespace Barotrauma
{
@@ -34,10 +35,11 @@ namespace Barotrauma
Decals,
NPCConversations,
Afflictions,
Buffs,
Tutorials,
UIStyle,
TraitorMissions
TraitorMissions,
EventManagerSettings,
Orders
}
public class ContentPackage
@@ -61,7 +63,8 @@ namespace Barotrauma
ContentType.LevelObjectPrefabs,
ContentType.RuinConfig,
ContentType.Outpost,
ContentType.Afflictions
ContentType.Afflictions,
ContentType.Orders
};
//at least one file of each these types is required in core content packages
@@ -80,12 +83,11 @@ namespace Barotrauma
ContentType.LevelGenerationParameters,
ContentType.RandomEvents,
ContentType.Missions,
ContentType.TraitorMissions,
ContentType.BackgroundCreaturePrefabs,
ContentType.RuinConfig,
ContentType.NPCConversations,
ContentType.Afflictions,
ContentType.UIStyle
ContentType.UIStyle,
ContentType.EventManagerSettings,
ContentType.Orders
};
public static IEnumerable<ContentType> CorePackageRequiredFiles
@@ -175,7 +177,7 @@ namespace Barotrauma
if (!Enum.TryParse(subElement.Name.ToString(), true, out ContentType type))
{
errorMsgs.Add("Error in content package \"" + Name + "\" - \"" + subElement.Name.ToString() + "\" is not a valid content type.");
type = ContentType.None;
type = ContentType.None;
}
Files.Add(new ContentFile(subElement.GetAttributeString("file", ""), type));
}
@@ -191,6 +193,29 @@ namespace Barotrauma
}
}
private bool? invalid;
public bool Invalid
{
get
{
if (!invalid.HasValue)
{
invalid = !CheckValidity(out _);
}
return invalid.Value;
}
}
private List<string> errorMessages;
public IEnumerable<string> ErrorMessages
{
get
{
if (errorMessages == null) { CheckValidity(out _); }
return errorMessages;
}
}
public override string ToString()
{
return Name;
@@ -233,6 +258,58 @@ namespace Barotrauma
return missingContentTypes.Count == 0;
}
public bool CheckValidity(out List<string> errorMessages)
{
this.errorMessages = errorMessages = new List<string>();
foreach (ContentFile file in Files)
{
switch (file.Type)
{
case ContentType.Executable:
case ContentType.ServerExecutable:
case ContentType.None:
case ContentType.Outpost:
case ContentType.Submarine:
break;
default:
try
{
XDocument.Load(file.Path);
}
catch (Exception e)
{
if (TextManager.Initialized)
{
errorMessages.Add(TextManager.GetWithVariables("xmlfileinvalid",
new string[] { "[filepath]", "[errormessage]" },
new string[] { file.Path, e.Message }));
}
else
{
errorMessages.Add($"XML File Invalid. PATH: {file.Path}, ERROR: {e.Message}");
#if DEBUG
throw e;
#endif
}
}
break;
}
}
if (CorePackage && !ContainsRequiredCorePackageFiles(out List<ContentType> missingContentTypes))
{
errorMessages.Add(TextManager.GetWithVariables("ContentPackageCantMakeCorePackage",
new string[2] { "[packagename]", "[missingfiletypes]" },
new string[2] { Name, string.Join(", ", missingContentTypes) },
new bool[2] { false, true }));
}
VerifyFiles(out List<string> missingFileMessages);
errorMessages.AddRange(missingFileMessages);
invalid = errorMessages.Count > 0;
return !invalid.Value;
}
/// <summary>
/// Make sure all the files defined in the content package are present
/// </summary>
@@ -246,7 +323,6 @@ namespace Barotrauma
//dedicated server doesn't care if the client executable is present or not
if (file.Type == ContentType.Executable) { continue; }
#endif
if (!File.Exists(file.Path))
{
errorMessages.Add("File \"" + file.Path + "\" not found.");
@@ -368,12 +444,18 @@ namespace Barotrauma
{
case ContentType.Character:
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
string speciesName = doc.Root.GetAttributeString("name", "");
//TODO: check non-default paths if defined
filePaths.Add(RagdollParams.GetDefaultFile(speciesName, this));
foreach (AnimationType animationType in Enum.GetValues(typeof(AnimationType)))
var rootElement = doc.Root;
var element = rootElement.IsOverride() ? rootElement.FirstElement() : rootElement;
var speciesName = element.GetAttributeString("speciesname", element.GetAttributeString("name", ""));
var ragdollFolder = RagdollParams.GetFolder(speciesName);
if (Directory.Exists(ragdollFolder))
{
filePaths.Add(AnimationParams.GetDefaultFile(speciesName, animationType, this));
Directory.GetFiles(ragdollFolder, "*.xml").ForEach(f => filePaths.Add(f));
}
var animationFolder = AnimationParams.GetFolder(speciesName);
if (Directory.Exists(animationFolder))
{
Directory.GetFiles(animationFolder, "*.xml").ForEach(f => filePaths.Add(f));
}
break;
}
@@ -445,7 +527,7 @@ namespace Barotrauma
}
/// <summary>
/// Returns all xml files.
/// Returns all xml files from all the loaded content packages.
/// </summary>
public static IEnumerable<string> GetAllContentFiles(IEnumerable<ContentPackage> contentPackages)
{
@@ -478,12 +560,13 @@ namespace Barotrauma
}
}
string[] files = Directory.GetFiles(folder, "*.xml");
List.Clear();
string[] files = Directory.GetFiles(folder, "*.xml");
foreach (string filePath in files)
{
List.Add(new ContentPackage(filePath));
List.Add(new ContentPackage(filePath));
}
string[] modDirectories = Directory.GetDirectories("Mods");
@@ -498,12 +581,27 @@ namespace Barotrauma
}
}
public static void SortContentPackages()
{
List = List
.OrderByDescending(p => p.CorePackage)
.ThenByDescending(p => GameMain.Config?.SelectedContentPackages.Contains(p))
.ThenBy(p => GameMain.Config?.SelectedContentPackages.IndexOf(p))
.ToList();
if (GameMain.Config != null)
{
var reportList = List.Where(p => GameMain.Config.SelectedContentPackages.Contains(p));
DebugConsole.NewMessage($"Content package load order: { new string(reportList.SelectMany(cp => cp.Name + " | ").ToArray()) }");
}
}
public void Delete()
{
try
{
File.Delete(Path);
GameMain.Config.SelectedContentPackages.Remove(this);
GameMain.Config.DeselectContentPackage(this);
GameMain.Config.SaveNewPlayerConfig();
}
catch (IOException e)
@@ -512,6 +610,7 @@ namespace Barotrauma
return;
}
List.Remove(this);
SortContentPackages();
}
}