From e119e46c5ae111abb01fbd66bda2182af9f8a29a Mon Sep 17 00:00:00 2001 From: Flamefire Date: Wed, 15 Oct 2014 15:32:16 +0200 Subject: [PATCH] Improve partymode loading (return bool instead of incomplete PM) --- Vocaluxe/Base/CParty.cs | 56 ++++++++++++++------------------ Vocaluxe/Screens/CScreenParty.cs | 8 +---- VocaluxeLib/Menu/IMenuElement.cs | 1 - VocaluxeLib/Structs.cs | 1 - 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 94df0720..03b4632a 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -43,7 +43,6 @@ namespace Vocaluxe.Base public int PartyModeVersionMajor; public int PartyModeVersionMinor; public string TargetAudience; - public bool NoErrors; public IPartyMode PartyMode; } #endregion Structs @@ -53,7 +52,7 @@ namespace Vocaluxe.Base private const int _PartyModeSystemVersion = 1; private static Dictionary _PartyModes; - private static Queue _IDs; + private static int _NextID; private static int _NormalGameModeID; private static SPartyMode _CurrentPartyMode; @@ -62,15 +61,12 @@ namespace Vocaluxe.Base public static void Init() { _PartyModes = new Dictionary(); - _IDs = new Queue(1000); - - for (int i = 0; i < 1000; i++) - _IDs.Enqueue(i); + _NextID = 0; //add dummy normal game mode and set it as default var pm = new SPartyMode {PartyMode = new CPartyModeNone(), ScreenFiles = new List()}; pm.PartyMode.Initialize(); - pm.PartyModeID = _IDs.Dequeue(); + pm.PartyModeID = _NextID++; _NormalGameModeID = pm.PartyModeID; _PartyModes.Add(pm.PartyModeID, pm); _CurrentPartyMode = pm; @@ -123,7 +119,6 @@ namespace Vocaluxe.Base Description = mode.Description, Name = mode.Name, PartyModeID = mode.PartyModeID, - Playable = mode.NoErrors, VersionMajor = mode.PartyModeVersionMajor, VersionMinor = mode.PartyModeVersionMinor, TargetAudience = mode.TargetAudience, @@ -230,51 +225,51 @@ namespace Vocaluxe.Base foreach (string file in files) { - SPartyMode pm = _LoadPartyMode(file); - if (pm.NoErrors) + SPartyMode pm; + if (_LoadPartyMode(file, out pm)) _PartyModes.Add(pm.PartyModeID, pm); } } - private static SPartyMode _LoadPartyMode(string file) + private static bool _LoadPartyMode(string file, out SPartyMode pm) { - var pm = new SPartyMode {PartyModeID = _IDs.Dequeue(), ScreenFiles = new List(), NoErrors = false}; + pm = new SPartyMode {PartyModeID = _NextID++, ScreenFiles = new List()}; CXMLReader xmlReader = CXMLReader.OpenFile(file); //Error... if (xmlReader == null) - return pm; + return false; bool loaded = true; loaded &= xmlReader.TryGetIntValue("//root/PartyModeSystemVersion", ref pm.PartyModeSystemVersion); - loaded &= xmlReader.GetValue("//root/Info/Name", out pm.Name, "ERROR Name"); - loaded &= xmlReader.GetValue("//root/Info/Description", out pm.Description, "ERROR Description"); - loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author"); - loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder"); - loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile"); + loaded &= xmlReader.GetValue("//root/Info/Name", out pm.Name); + loaded &= xmlReader.GetValue("//root/Info/Description", out pm.Description); + loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author); + loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder); + loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); - loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); + loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience); loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles); if (!loaded) { CLog.LogError("Error loading PartyMode file: " + file); - return pm; + return false; } if (pm.PartyModeSystemVersion != _PartyModeSystemVersion) { CLog.LogError("Error loading PartyMode file (wrong PartyModeSystemVersion): " + file); - return pm; + return false; } if (pm.ScreenFiles.Count == 0) { CLog.LogError("Error loading PartyMode file (no ScreenFiles found): " + file); - return pm; + return false; } string pathToPm = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNamePartyModes, pm.Folder); @@ -285,19 +280,19 @@ namespace Vocaluxe.Base Assembly output = _CompileFiles(filesToCompile.ToArray()); if (output == null) - return pm; + return false; if (!CLanguage.LoadPartyLanguageFiles(pm.PartyModeID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages))) { CLog.LogError("Error loading language files for PartyMode: " + file); - return pm; + return false; } object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Folder + "." + pm.PartyModeFile); if (instance == null) { CLog.LogError("Error creating Instance of PartyMode file: " + file); - return pm; + return false; } try @@ -307,16 +302,16 @@ namespace Vocaluxe.Base catch (Exception e) { CLog.LogError("Error casting PartyMode file: " + file + "; " + e.Message); - return pm; + return false; } pm.PartyMode.Initialize(); pm.PartyMode.SetFolder(pathToPm); if (!CThemes.ReadThemesFromFolder(Path.Combine(pathToPm, CSettings.FolderNameThemes), pm.PartyModeID)) - return pm; + return false; if (!CThemes.LoadPartymodeTheme(pm.PartyModeID)) - return pm; + return false; foreach (string screenfile in pm.ScreenFiles) { @@ -332,11 +327,10 @@ namespace Vocaluxe.Base pm.PartyMode.AddScreen(screen, screenfile); } else - return pm; + return false; } - pm.NoErrors = true; - return pm; + return true; } private static Assembly _CompileFiles(string[] files) diff --git a/Vocaluxe/Screens/CScreenParty.cs b/Vocaluxe/Screens/CScreenParty.cs index 6465b65c..504e68d3 100644 --- a/Vocaluxe/Screens/CScreenParty.cs +++ b/Vocaluxe/Screens/CScreenParty.cs @@ -173,13 +173,7 @@ namespace Vocaluxe.Screens _Texts[_TextVersion].Text = _PartyModeInfos[index].VersionMajor + "." + _PartyModeInfos[index].VersionMinor; _Texts[_TextVersion].TranslationID = _PartyModeInfos[index].PartyModeID; - if (!_PartyModeInfos[index].Playable) - { - _Buttons[_ButtonStart].Visible = false; - _Texts[_TextError].Text = "TR_SCREENPARTY_ERROR"; - _Texts[_TextError].Visible = true; - } - else if (CConfig.GetMaxNumMics() == 0) + if (CConfig.GetMaxNumMics() == 0) { _Buttons[_ButtonStart].Visible = false; _Texts[_TextError].Text = "TR_SCREENPARTY_ERROR_MICS"; diff --git a/VocaluxeLib/Menu/IMenuElement.cs b/VocaluxeLib/Menu/IMenuElement.cs index 07e7522f..48b0c2e0 100644 --- a/VocaluxeLib/Menu/IMenuElement.cs +++ b/VocaluxeLib/Menu/IMenuElement.cs @@ -15,7 +15,6 @@ // along with Vocaluxe. If not, see . #endregion -using System.Xml; using VocaluxeLib.Xml; namespace VocaluxeLib.Menu diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index fb9ff313..8b316ece 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -371,7 +371,6 @@ namespace VocaluxeLib public int MinTeams; public string Author; - public bool Playable; public int VersionMajor; public int VersionMinor; }