Improve partymode loading (return bool instead of incomplete PM)
This commit is contained in:
1 parent
c1866c0ad5
commit
e119e46c5a
4 files changed
+26
-40
No files matched your search
+25
-31
@@ -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<int, SPartyMode> _PartyModes;
|
||||
private static Queue<int> _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<int, SPartyMode>();
|
||||
_IDs = new Queue<int>(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<string>()};
|
||||
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<string>(), NoErrors = false};
|
||||
pm = new SPartyMode {PartyModeID = _NextID++, ScreenFiles = new List<string>()};
|
||||
|
||||
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)
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using System.Xml;
|
||||
using VocaluxeLib.Xml;
|
||||
|
||||
namespace VocaluxeLib.Menu
|
||||
|
||||
@@ -371,7 +371,6 @@ namespace VocaluxeLib
|
||||
public int MinTeams;
|
||||
|
||||
public string Author;
|
||||
public bool Playable;
|
||||
public int VersionMajor;
|
||||
public int VersionMinor;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user