(158a62970) Don't allow to replace an existing character. TODO: should make this possible later on, but requires additional logic. Fixes #1375.

This commit is contained in:
Joonas Rikkonen
2019-04-15 12:00:21 +03:00
parent 359b8280d3
commit 455fbb013f
2 changed files with 26 additions and 19 deletions
@@ -1296,8 +1296,13 @@ namespace Barotrauma
string speciesName = name; string speciesName = name;
// Config file // Config file
string configFilePath = Path.Combine(mainFolder, $"{speciesName}.xml").Replace(@"\", @"/"); string configFilePath = Path.Combine(mainFolder, $"{speciesName}.xml").Replace(@"\", @"/");
if (ContentPackage.GetFilesOfType(GameMain.SelectedPackages, ContentType.Character).None(path => path.Contains(speciesName))) if (ContentPackage.GetFilesOfType(GameMain.SelectedPackages, ContentType.Character).Any(path => path.Contains(speciesName)))
{ {
GUI.AddMessage(GetCharacterEditorTranslation("ExistingCharacterFound"), Color.Red, font: GUI.LargeFont);
// TODO: add a prompt: "Do you want to replace it?" + functionality
return false;
}
// Create the config file // Create the config file
XElement mainElement = new XElement("Character", XElement mainElement = new XElement("Character",
new XAttribute("name", speciesName), new XAttribute("name", speciesName),
@@ -1306,6 +1311,7 @@ namespace Barotrauma
new XElement("animations", new XAttribute("folder", Path.Combine(mainFolder, $"Animations/").Replace(@"\", @"/"))), new XElement("animations", new XAttribute("folder", Path.Combine(mainFolder, $"Animations/").Replace(@"\", @"/"))),
new XElement("health"), new XElement("health"),
new XElement("ai")); new XElement("ai"));
XDocument doc = new XDocument(mainElement); XDocument doc = new XDocument(mainElement);
if (!Directory.Exists(mainFolder)) if (!Directory.Exists(mainFolder))
{ {
@@ -1316,7 +1322,7 @@ namespace Barotrauma
contentPackage.AddFile(configFilePath, ContentType.Character); contentPackage.AddFile(configFilePath, ContentType.Character);
contentPackage.Save(contentPackage.Path); contentPackage.Save(contentPackage.Path);
DebugConsole.NewMessage(GetCharacterEditorTranslation("ContentPackageSaved").Replace("[path]", contentPackage.Path)); DebugConsole.NewMessage(GetCharacterEditorTranslation("ContentPackageSaved").Replace("[path]", contentPackage.Path));
}
// Ragdoll // Ragdoll
string ragdollFolder = RagdollParams.GetFolder(speciesName); string ragdollFolder = RagdollParams.GetFolder(speciesName);
string ragdollPath = RagdollParams.GetDefaultFile(speciesName); string ragdollPath = RagdollParams.GetDefaultFile(speciesName);
@@ -84,6 +84,7 @@ namespace Barotrauma
var folder = XMLExtensions.TryLoadXml(Character.GetConfigFile(speciesName))?.Root?.Element("ragdolls")?.GetAttributeString("folder", string.Empty); var folder = XMLExtensions.TryLoadXml(Character.GetConfigFile(speciesName))?.Root?.Element("ragdolls")?.GetAttributeString("folder", string.Empty);
if (string.IsNullOrEmpty(folder) || folder.ToLowerInvariant() == "default") if (string.IsNullOrEmpty(folder) || folder.ToLowerInvariant() == "default")
{ {
//DebugConsole.NewMessage("[RagollParams] Using the default folder.");
folder = GetDefaultFolder(speciesName); folder = GetDefaultFolder(speciesName);
} }
return folder; return folder;