(628aa768f) Fix characters always being created in the default folder (#1330).
This commit is contained in:
@@ -1226,7 +1226,7 @@ namespace Barotrauma
|
|||||||
Cam.Position = character.WorldPosition;
|
Cam.Position = character.WorldPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CreateCharacter(string name, bool isHumanoid, params object[] ragdollConfig)
|
private bool CreateCharacter(string name, string mainFolder, bool isHumanoid, params object[] ragdollConfig)
|
||||||
{
|
{
|
||||||
var contentPackage = GameMain.Config.SelectedContentPackages.LastOrDefault();
|
var contentPackage = GameMain.Config.SelectedContentPackages.LastOrDefault();
|
||||||
if (contentPackage == null)
|
if (contentPackage == null)
|
||||||
@@ -1245,17 +1245,16 @@ namespace Barotrauma
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
string speciesName = name;
|
string speciesName = name;
|
||||||
string mainFolder = $"Content/Characters/{speciesName}";
|
|
||||||
// Config file
|
// Config file
|
||||||
string configFilePath = $"{mainFolder}/{speciesName}.xml";
|
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).None(path => path.Contains(speciesName)))
|
||||||
{
|
{
|
||||||
// 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),
|
||||||
new XAttribute("humanoid", isHumanoid),
|
new XAttribute("humanoid", isHumanoid),
|
||||||
new XElement("ragdolls"),
|
new XElement("ragdolls", new XAttribute("folder", Path.Combine(mainFolder, $"Ragdolls/").Replace(@"\", @"/"))),
|
||||||
new XElement("animations"),
|
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);
|
||||||
@@ -1270,13 +1269,13 @@ namespace Barotrauma
|
|||||||
DebugConsole.NewMessage(GetCharacterEditorTranslation("ContentPackageSaved").Replace("[path]", contentPackage.Path));
|
DebugConsole.NewMessage(GetCharacterEditorTranslation("ContentPackageSaved").Replace("[path]", contentPackage.Path));
|
||||||
}
|
}
|
||||||
// Ragdoll
|
// Ragdoll
|
||||||
string ragdollFolder = RagdollParams.GetDefaultFolder(speciesName);
|
string ragdollFolder = RagdollParams.GetFolder(speciesName);
|
||||||
string ragdollPath = RagdollParams.GetDefaultFile(speciesName);
|
string ragdollPath = RagdollParams.GetDefaultFile(speciesName);
|
||||||
RagdollParams ragdollParams = isHumanoid
|
RagdollParams ragdollParams = isHumanoid
|
||||||
? RagdollParams.CreateDefault<HumanRagdollParams>(ragdollPath, speciesName, ragdollConfig)
|
? RagdollParams.CreateDefault<HumanRagdollParams>(ragdollPath, speciesName, ragdollConfig)
|
||||||
: RagdollParams.CreateDefault<FishRagdollParams>(ragdollPath, speciesName, ragdollConfig) as RagdollParams;
|
: RagdollParams.CreateDefault<FishRagdollParams>(ragdollPath, speciesName, ragdollConfig) as RagdollParams;
|
||||||
// Animations
|
// Animations
|
||||||
string animFolder = AnimationParams.GetDefaultFolder(speciesName);
|
string animFolder = AnimationParams.GetFolder(speciesName);
|
||||||
foreach (AnimationType animType in Enum.GetValues(typeof(AnimationType)))
|
foreach (AnimationType animType in Enum.GetValues(typeof(AnimationType)))
|
||||||
{
|
{
|
||||||
if (animType != AnimationType.NotDefined)
|
if (animType != AnimationType.NotDefined)
|
||||||
@@ -4663,7 +4662,7 @@ namespace Barotrauma
|
|||||||
LimbXElements.Values,
|
LimbXElements.Values,
|
||||||
JointXElements
|
JointXElements
|
||||||
};
|
};
|
||||||
if (CharacterEditorScreen.instance.CreateCharacter(Name, IsHumanoid, ragdollParams))
|
if (CharacterEditorScreen.instance.CreateCharacter(Name, Path.GetDirectoryName(XMLPath), IsHumanoid, ragdollParams))
|
||||||
{
|
{
|
||||||
GUI.AddMessage(GetCharacterEditorTranslation("CharacterCreated").Replace("[name]", Name), Color.Green, font: GUI.Font);
|
GUI.AddMessage(GetCharacterEditorTranslation("CharacterCreated").Replace("[name]", Name), Color.Green, font: GUI.Font);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ namespace Barotrauma
|
|||||||
public static string GetDefaultFolder(string speciesName) => $"Content/Characters/{speciesName.CapitaliseFirstInvariant()}/Animations/";
|
public static string GetDefaultFolder(string speciesName) => $"Content/Characters/{speciesName.CapitaliseFirstInvariant()}/Animations/";
|
||||||
public static string GetDefaultFile(string speciesName, AnimationType animType) => $"{GetFolder(speciesName)}{GetDefaultFileName(speciesName, animType)}.xml";
|
public static string GetDefaultFile(string speciesName, AnimationType animType) => $"{GetFolder(speciesName)}{GetDefaultFileName(speciesName, animType)}.xml";
|
||||||
|
|
||||||
protected static string GetFolder(string speciesName)
|
public static string GetFolder(string speciesName)
|
||||||
{
|
{
|
||||||
var folder = XMLExtensions.TryLoadXml(Character.GetConfigFile(speciesName))?.Root?.Element("animations")?.GetAttributeString("folder", string.Empty);
|
var folder = XMLExtensions.TryLoadXml(Character.GetConfigFile(speciesName))?.Root?.Element("animations")?.GetAttributeString("folder", string.Empty);
|
||||||
if (string.IsNullOrEmpty(folder) || folder.ToLowerInvariant() == "default")
|
if (string.IsNullOrEmpty(folder) || folder.ToLowerInvariant() == "default")
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ namespace Barotrauma
|
|||||||
new XAttribute("sourcerect", $"0, 0, 1, 1")))
|
new XAttribute("sourcerect", $"0, 0, 1, 1")))
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static string GetFolder(string speciesName)
|
public static string GetFolder(string speciesName)
|
||||||
{
|
{
|
||||||
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user