From 9e2966e9cb9090a770c81cb46ea1050701032bb2 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 25 Feb 2018 15:03:29 +0200 Subject: [PATCH] - Fixed creature disable list only taking config files in the Content/Characters folder into account (making it impossible to disable spawning of custom monsters outside the folder) - Removed hard-coded ruin structure, particle & decal config paths and moved them to content package (custom ones can be added now without modifying the original files). --- .../BarotraumaClient/Source/GameMain.cs | 4 +- .../Source/Particles/DecalManager.cs | 23 ++++++----- .../Source/Particles/ParticleManager.cs | 26 ++++++------- .../Source/Screens/ParticleEditorScreen.cs | 38 ++++++++++--------- .../Data/ContentPackages/Vanilla 0.8.xml | 3 ++ .../BarotraumaShared/Source/ContentPackage.cs | 5 ++- .../Source/Map/Levels/Ruins/RuinStructure.cs | 22 +++++------ .../Source/Networking/GameServerSettings.cs | 4 +- 8 files changed, 68 insertions(+), 57 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index a85b426ad..1227f15d0 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -313,9 +313,9 @@ namespace Barotrauma yield return CoroutineStatus.Running; - ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", GameScreen.Cam); + ParticleManager = new ParticleManager(GameScreen.Cam); ParticleManager.LoadPrefabs(); - DecalManager = new DecalManager("Content/Particles/DecalPrefabs.xml"); + DecalManager = new DecalManager(); yield return CoroutineStatus.Running; LocationType.Init(); diff --git a/Barotrauma/BarotraumaClient/Source/Particles/DecalManager.cs b/Barotrauma/BarotraumaClient/Source/Particles/DecalManager.cs index b7b8946e7..c8580d725 100644 --- a/Barotrauma/BarotraumaClient/Source/Particles/DecalManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Particles/DecalManager.cs @@ -8,22 +8,25 @@ namespace Barotrauma.Particles { private Dictionary prefabs; - public DecalManager(string configFile) + public DecalManager() { - XDocument doc = XMLExtensions.TryLoadXml(configFile); - if (doc == null || doc.Root == null) return; - prefabs = new Dictionary(); - - foreach (XElement element in doc.Root.Elements()) + foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Decals)) { - if (prefabs.ContainsKey(element.Name.ToString())) + XDocument doc = XMLExtensions.TryLoadXml(configFile); + if (doc == null || doc.Root == null) continue; + + foreach (XElement element in doc.Root.Elements()) { - DebugConsole.ThrowError("Error in " + configFile + "! Each decal prefab must have a unique name."); - continue; + if (prefabs.ContainsKey(element.Name.ToString())) + { + DebugConsole.ThrowError("Error in " + configFile + "! Each decal prefab must have a unique name."); + continue; + } + prefabs.Add(element.Name.ToString(), new DecalPrefab(element)); } - prefabs.Add(element.Name.ToString(), new DecalPrefab(element)); } + } public Decal CreateDecal(string decalName, float scale, Vector2 worldPosition, Hull hull) diff --git a/Barotrauma/BarotraumaClient/Source/Particles/ParticleManager.cs b/Barotrauma/BarotraumaClient/Source/Particles/ParticleManager.cs index 2562abbda..8500bd60d 100644 --- a/Barotrauma/BarotraumaClient/Source/Particles/ParticleManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Particles/ParticleManager.cs @@ -14,7 +14,6 @@ namespace Barotrauma.Particles class ParticleManager { - public readonly string ConfigFile; public static int particleCount; private const int MaxOutOfViewDist = 500; @@ -26,9 +25,8 @@ namespace Barotrauma.Particles private Camera cam; - public ParticleManager(string configFile, Camera cam) + public ParticleManager(Camera cam) { - ConfigFile = configFile; this.cam = cam; particles = new Particle[MaxParticles]; @@ -36,20 +34,22 @@ namespace Barotrauma.Particles public void LoadPrefabs() { - XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); - if (doc == null || doc.Root == null) return; - prefabs = new Dictionary(); - - foreach (XElement element in doc.Root.Elements()) + foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles)) { - if (prefabs.ContainsKey(element.Name.ToString())) + XDocument doc = XMLExtensions.TryLoadXml(configFile); + if (doc == null || doc.Root == null) continue; + + foreach (XElement element in doc.Root.Elements()) { - DebugConsole.ThrowError("Error in " + ConfigFile + "! Each particle prefab must have a unique name."); - continue; + if (prefabs.ContainsKey(element.Name.ToString())) + { + DebugConsole.ThrowError("Error in " + configFile + "! Each particle prefab must have a unique name."); + continue; + } + prefabs.Add(element.Name.ToString(), new ParticlePrefab(element)); } - prefabs.Add(element.Name.ToString(), new ParticlePrefab(element)); - } + } } public Particle CreateParticle(string prefabName, Vector2 position, float angle, float speed, Hull hullGuess = null) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ParticleEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ParticleEditorScreen.cs index 9c79b27a9..67cc6e402 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ParticleEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ParticleEditorScreen.cs @@ -162,29 +162,31 @@ namespace Barotrauma private void SerializeAll() { - XDocument doc = XMLExtensions.TryLoadXml(GameMain.ParticleManager.ConfigFile); - if (doc == null || doc.Root == null) return; - - var prefabList = GameMain.ParticleManager.GetPrefabList(); - foreach (ParticlePrefab prefab in prefabList) + foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles)) { - foreach (XElement element in doc.Root.Elements()) + XDocument doc = XMLExtensions.TryLoadXml(configFile); + if (doc == null || doc.Root == null) continue; + + var prefabList = GameMain.ParticleManager.GetPrefabList(); + foreach (ParticlePrefab prefab in prefabList) { - if (element.Name.ToString().ToLowerInvariant() != prefab.Name.ToLowerInvariant()) continue; - - SerializableProperty.SerializeProperties(prefab, element, true); + foreach (XElement element in doc.Root.Elements()) + { + if (element.Name.ToString().ToLowerInvariant() != prefab.Name.ToLowerInvariant()) continue; + SerializableProperty.SerializeProperties(prefab, element, true); + } } - } - XmlWriterSettings settings = new XmlWriterSettings(); - settings.Indent = true; - settings.OmitXmlDeclaration = true; - settings.NewLineOnAttributes = true; + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + settings.OmitXmlDeclaration = true; + settings.NewLineOnAttributes = true; - using (var writer = XmlWriter.Create(GameMain.ParticleManager.ConfigFile, settings)) - { - doc.WriteTo(writer); - writer.Flush(); + using (var writer = XmlWriter.Create(configFile, settings)) + { + doc.WriteTo(writer); + writer.Flush(); + } } } diff --git a/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml b/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml index 47757fe05..3cf2d11fd 100644 --- a/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml +++ b/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml @@ -45,8 +45,11 @@ + + + diff --git a/Barotrauma/BarotraumaShared/Source/ContentPackage.cs b/Barotrauma/BarotraumaShared/Source/ContentPackage.cs index 7297ffc9d..e0ab20d53 100644 --- a/Barotrauma/BarotraumaShared/Source/ContentPackage.cs +++ b/Barotrauma/BarotraumaShared/Source/ContentPackage.cs @@ -19,7 +19,10 @@ namespace Barotrauma RandomEvents, Missions, BackgroundCreaturePrefabs, BackgroundSpritePrefabs, - Sounds + Sounds, + RuinConfig, + Particles, + Decals } public class ContentPackage diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs index 8be78eaf3..62dd85d19 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs @@ -13,8 +13,6 @@ namespace Barotrauma.RuinGeneration class RuinStructure { - const string ConfigFile = "Content/Map/RuinConfig.xml"; - private static List list; public readonly MapEntityPrefab Prefab; @@ -37,14 +35,14 @@ namespace Barotrauma.RuinGeneration } string alignmentStr = element.GetAttributeString("alignment", "Bottom"); - if (!Enum.TryParse(alignmentStr, true, out Alignment)) + if (!Enum.TryParse(alignmentStr, true, out Alignment)) { DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + alignmentStr + " is not a valid alignment"); } string typeStr = element.GetAttributeString("type", ""); - if (!Enum.TryParse(typeStr, true, out Type)) + if (!Enum.TryParse(typeStr, true, out Type)) { DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + typeStr + " is not a valid type"); return; @@ -58,19 +56,21 @@ namespace Barotrauma.RuinGeneration private static void Load() { list = new List(); - - XDocument doc = XMLExtensions.TryLoadXml(ConfigFile); - if (doc == null || doc.Root == null) return; - - foreach (XElement element in doc.Root.Elements()) + foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RuinConfig)) { - new RuinStructure(element); + XDocument doc = XMLExtensions.TryLoadXml(configFile); + if (doc == null || doc.Root == null) continue; + + foreach (XElement element in doc.Root.Elements()) + { + new RuinStructure(element); + } } } public static RuinStructure GetRandom(RuinStructureType type, Alignment alignment) { - if (list==null) + if (list == null) { DebugConsole.Log("Loading ruin structures..."); Load(); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs index 0d4d62841..4c658ce2b 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServerSettings.cs @@ -350,10 +350,10 @@ namespace Barotrauma.Networking showLogButton.Visible = SaveServerLogs; #endif - List monsterNames = Directory.GetDirectories("Content/Characters").ToList(); + List monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character); for (int i = 0; i < monsterNames.Count; i++) { - monsterNames[i] = monsterNames[i].Replace("Content/Characters", "").Replace("/", "").Replace("\\", ""); + monsterNames[i] = Path.GetFileName(Path.GetDirectoryName(monsterNames[i])); } monsterEnabled = new Dictionary(); foreach (string s in monsterNames)