- 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).
This commit is contained in:
Joonas Rikkonen
2018-02-25 15:03:29 +02:00
parent e02a1dc6ae
commit 9e2966e9cb
8 changed files with 68 additions and 57 deletions
@@ -313,9 +313,9 @@ namespace Barotrauma
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", GameScreen.Cam); ParticleManager = new ParticleManager(GameScreen.Cam);
ParticleManager.LoadPrefabs(); ParticleManager.LoadPrefabs();
DecalManager = new DecalManager("Content/Particles/DecalPrefabs.xml"); DecalManager = new DecalManager();
yield return CoroutineStatus.Running; yield return CoroutineStatus.Running;
LocationType.Init(); LocationType.Init();
@@ -8,22 +8,25 @@ namespace Barotrauma.Particles
{ {
private Dictionary<string, DecalPrefab> prefabs; private Dictionary<string, DecalPrefab> prefabs;
public DecalManager(string configFile) public DecalManager()
{ {
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null || doc.Root == null) return;
prefabs = new Dictionary<string, DecalPrefab>(); prefabs = new Dictionary<string, DecalPrefab>();
foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Decals))
foreach (XElement element in doc.Root.Elements())
{ {
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."); if (prefabs.ContainsKey(element.Name.ToString()))
continue; {
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) public Decal CreateDecal(string decalName, float scale, Vector2 worldPosition, Hull hull)
@@ -14,7 +14,6 @@ namespace Barotrauma.Particles
class ParticleManager class ParticleManager
{ {
public readonly string ConfigFile;
public static int particleCount; public static int particleCount;
private const int MaxOutOfViewDist = 500; private const int MaxOutOfViewDist = 500;
@@ -26,9 +25,8 @@ namespace Barotrauma.Particles
private Camera cam; private Camera cam;
public ParticleManager(string configFile, Camera cam) public ParticleManager(Camera cam)
{ {
ConfigFile = configFile;
this.cam = cam; this.cam = cam;
particles = new Particle[MaxParticles]; particles = new Particle[MaxParticles];
@@ -36,19 +34,21 @@ namespace Barotrauma.Particles
public void LoadPrefabs() public void LoadPrefabs()
{ {
XDocument doc = XMLExtensions.TryLoadXml(ConfigFile);
if (doc == null || doc.Root == null) return;
prefabs = new Dictionary<string, ParticlePrefab>(); prefabs = new Dictionary<string, ParticlePrefab>();
foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles))
foreach (XElement element in doc.Root.Elements())
{ {
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."); if (prefabs.ContainsKey(element.Name.ToString()))
continue; {
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));
} }
} }
@@ -162,29 +162,31 @@ namespace Barotrauma
private void SerializeAll() private void SerializeAll()
{ {
XDocument doc = XMLExtensions.TryLoadXml(GameMain.ParticleManager.ConfigFile); foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Particles))
if (doc == null || doc.Root == null) return;
var prefabList = GameMain.ParticleManager.GetPrefabList();
foreach (ParticlePrefab prefab in prefabList)
{ {
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; foreach (XElement element in doc.Root.Elements())
{
SerializableProperty.SerializeProperties(prefab, element, true); if (element.Name.ToString().ToLowerInvariant() != prefab.Name.ToLowerInvariant()) continue;
SerializableProperty.SerializeProperties(prefab, element, true);
}
} }
}
XmlWriterSettings settings = new XmlWriterSettings(); XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true; settings.Indent = true;
settings.OmitXmlDeclaration = true; settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true; settings.NewLineOnAttributes = true;
using (var writer = XmlWriter.Create(GameMain.ParticleManager.ConfigFile, settings)) using (var writer = XmlWriter.Create(configFile, settings))
{ {
doc.WriteTo(writer); doc.WriteTo(writer);
writer.Flush(); writer.Flush();
}
} }
} }
@@ -45,8 +45,11 @@
<Character file="Content/Characters/Tigerthresher/tigerthresher.xml" /> <Character file="Content/Characters/Tigerthresher/tigerthresher.xml" />
<Character file="Content/Characters/Watcher/watcher.xml" /> <Character file="Content/Characters/Watcher/watcher.xml" />
<Structure file="Content/Map/StructurePrefabs.xml" /> <Structure file="Content/Map/StructurePrefabs.xml" />
<RuinConfig file="Content/Map/RuinConfig.xml" />
<BackgroundCreaturePrefabs file="Content/BackgroundSprites/BackgroundCreaturePrefabs.xml"/> <BackgroundCreaturePrefabs file="Content/BackgroundSprites/BackgroundCreaturePrefabs.xml"/>
<BackgroundSpritePrefabs file="Content/BackgroundSprites/BackgroundSpritePrefabs.xml" /> <BackgroundSpritePrefabs file="Content/BackgroundSprites/BackgroundSpritePrefabs.xml" />
<Particles file="Content/Particles/ParticlePrefabs.xml"/>
<Decals file="Content/Particles/DecalPrefabs.xml"/>
<RandomEvents file="Content/randomevents.xml" /> <RandomEvents file="Content/randomevents.xml" />
<LocationTypes file="Content/Map/locationTypes.xml" /> <LocationTypes file="Content/Map/locationTypes.xml" />
<LevelGenerationParameters file="Content/Map/LevelGenerationParameters.xml" /> <LevelGenerationParameters file="Content/Map/LevelGenerationParameters.xml" />
@@ -19,7 +19,10 @@ namespace Barotrauma
RandomEvents, RandomEvents,
Missions, Missions,
BackgroundCreaturePrefabs, BackgroundSpritePrefabs, BackgroundCreaturePrefabs, BackgroundSpritePrefabs,
Sounds Sounds,
RuinConfig,
Particles,
Decals
} }
public class ContentPackage public class ContentPackage
@@ -13,8 +13,6 @@ namespace Barotrauma.RuinGeneration
class RuinStructure class RuinStructure
{ {
const string ConfigFile = "Content/Map/RuinConfig.xml";
private static List<RuinStructure> list; private static List<RuinStructure> list;
public readonly MapEntityPrefab Prefab; public readonly MapEntityPrefab Prefab;
@@ -37,14 +35,14 @@ namespace Barotrauma.RuinGeneration
} }
string alignmentStr = element.GetAttributeString("alignment", "Bottom"); string alignmentStr = element.GetAttributeString("alignment", "Bottom");
if (!Enum.TryParse<Alignment>(alignmentStr, true, out Alignment)) if (!Enum.TryParse(alignmentStr, true, out Alignment))
{ {
DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + alignmentStr + " is not a valid alignment"); DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + alignmentStr + " is not a valid alignment");
} }
string typeStr = element.GetAttributeString("type", ""); string typeStr = element.GetAttributeString("type", "");
if (!Enum.TryParse<RuinStructureType>(typeStr, true, out Type)) if (!Enum.TryParse(typeStr, true, out Type))
{ {
DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + typeStr + " is not a valid type"); DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + typeStr + " is not a valid type");
return; return;
@@ -58,19 +56,21 @@ namespace Barotrauma.RuinGeneration
private static void Load() private static void Load()
{ {
list = new List<RuinStructure>(); list = new List<RuinStructure>();
foreach (string configFile in GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RuinConfig))
XDocument doc = XMLExtensions.TryLoadXml(ConfigFile);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
{ {
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) public static RuinStructure GetRandom(RuinStructureType type, Alignment alignment)
{ {
if (list==null) if (list == null)
{ {
DebugConsole.Log("Loading ruin structures..."); DebugConsole.Log("Loading ruin structures...");
Load(); Load();
@@ -350,10 +350,10 @@ namespace Barotrauma.Networking
showLogButton.Visible = SaveServerLogs; showLogButton.Visible = SaveServerLogs;
#endif #endif
List<string> monsterNames = Directory.GetDirectories("Content/Characters").ToList(); List<string> monsterNames = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Character);
for (int i = 0; i < monsterNames.Count; i++) 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<string, bool>(); monsterEnabled = new Dictionary<string, bool>();
foreach (string s in monsterNames) foreach (string s in monsterNames)