Merge branch 'Better_Rounds_Handling' into develop

Conflicts:
	Vocaluxe/Screens/CScreenNames.cs
This commit is contained in:
Flamefire committed 2014-03-11 22:38:31 +01:00
commit 45bc144559
12 files changed
+238 -243

No files matched your search

+106 -106
View File
@@ -63,8 +63,16 @@ namespace Vocaluxe.Base
_CreditsRessourcesFilePath = Path.Combine(Environment.CurrentDirectory, CSettings.FileCreditsRessourcesDB);
_InitHighscoreDB();
_InitCoverDB();
_InitCreditsRessourcesDB();
if (!_InitCoverDB())
{
CLog.LogError("Error initializing Cover-DB", true, true);
return;
}
if (!_InitCreditsRessourcesDB())
{
CLog.LogError("Error initializing Cover-DB", true, true);
return;
}
GC.Collect();
}
@@ -93,26 +101,6 @@ namespace Vocaluxe.Base
return _GetDataBaseSongInfos(songID, out sArtist, out sTitle, out numPlayed, out dateAdded, _HighscoreFilePath);
}
public static void IncreaseSongCounter(SPlayer player)
{
using (var connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + _HighscoreFilePath;
try
{
connection.Open();
}
catch (Exception) {}
using (var command = new SQLiteCommand(connection))
{
int dataBaseSongID = _GetDataBaseSongID(player, command);
_IncreaseSongCounter(dataBaseSongID, command);
}
}
}
public static void IncreaseSongCounter(int dataBaseSongID)
{
using (var connection = new SQLiteConnection())
@@ -170,11 +158,27 @@ namespace Vocaluxe.Base
return -1;
}
int medley = 0;
int duet = 0;
int shortSong = 0;
switch (player.GameMode)
{
case EGameMode.TR_GAMEMODE_MEDLEY:
medley = 1;
break;
case EGameMode.TR_GAMEMODE_DUET:
duet = 1;
break;
case EGameMode.TR_GAMEMODE_SHORTSONG:
shortSong = 1;
break;
}
using (var command = new SQLiteCommand(connection))
{
int dataBaseSongID = CSongs.GetSong(player.SongID).DataBaseSongID;
return _AddScore(CProfiles.GetPlayerName(player.ProfileID), (int)Math.Round(player.Points), player.VoiceNr, player.DateTicks, player.Medley ? 1 : 0,
player.Duet ? 1 : 0, player.ShortSong ? 1 : 0, (int)CProfiles.GetDifficulty(player.ProfileID), dataBaseSongID, command);
return _AddScore(CProfiles.GetPlayerName(player.ProfileID), (int)Math.Round(player.Points), player.VoiceNr, player.DateTicks, medley,
duet, shortSong, (int)CProfiles.GetDifficulty(player.ProfileID), dataBaseSongID, command);
}
}
}
@@ -243,70 +247,74 @@ namespace Vocaluxe.Base
return lastInsertID;
}
public static void LoadScore(out List<SScores> scores, SPlayer player)
public static List<SDBScoreEntry> LoadScore(int songID, EGameMode gameMode)
{
var scores = new List<SDBScoreEntry>();
using (var connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + _HighscoreFilePath;
scores = new List<SScores>();
try
{
connection.Open();
}
catch (Exception)
{
return;
return scores;
}
using (var command = new SQLiteCommand(connection))
{
int medley = 0;
if (player.Medley)
medley = 1;
int duet = 0;
if (player.Duet)
duet = 1;
int shortSong = 0;
if (player.ShortSong)
shortSong = 1;
int dataBaseSongID = _GetDataBaseSongID(player, command);
if (dataBaseSongID >= 0)
switch (gameMode)
{
command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " +
"WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " +
"ORDER BY [Score] DESC";
command.Parameters.Add("@SongID", DbType.Int32, 0).Value = dataBaseSongID;
command.Parameters.Add("@Medley", DbType.Int32, 0).Value = medley;
command.Parameters.Add("@Duet", DbType.Int32, 0).Value = duet;
command.Parameters.Add("@ShortSong", DbType.Int32, 0).Value = shortSong;
case EGameMode.TR_GAMEMODE_MEDLEY:
medley = 1;
break;
case EGameMode.TR_GAMEMODE_DUET:
duet = 1;
break;
case EGameMode.TR_GAMEMODE_SHORTSONG:
shortSong = 1;
break;
}
SQLiteDataReader reader = command.ExecuteReader();
if (reader != null && reader.HasRows)
int dataBaseSongID = _GetDataBaseSongID(songID, command);
if (dataBaseSongID < 0)
return scores;
command.CommandText = "SELECT PlayerName, Score, Date, Difficulty, LineNr, id FROM Scores " +
"WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " +
"ORDER BY [Score] DESC";
command.Parameters.Add("@SongID", DbType.Int32, 0).Value = dataBaseSongID;
command.Parameters.Add("@Medley", DbType.Int32, 0).Value = medley;
command.Parameters.Add("@Duet", DbType.Int32, 0).Value = duet;
command.Parameters.Add("@ShortSong", DbType.Int32, 0).Value = shortSong;
SQLiteDataReader reader = command.ExecuteReader();
if (reader != null && reader.HasRows)
{
while (reader.Read())
{
while (reader.Read())
{
var score = new SScores
{
Name = reader.GetString(0),
Score = reader.GetInt32(1),
Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"),
Difficulty = (EGameDifficulty)reader.GetInt32(3),
LineNr = reader.GetInt32(4),
ID = reader.GetInt32(5)
};
var score = new SDBScoreEntry
{
Name = reader.GetString(0),
Score = reader.GetInt32(1),
Date = new DateTime(reader.GetInt64(2)).ToString("dd/MM/yyyy"),
Difficulty = (EGameDifficulty)reader.GetInt32(3),
VoiceNr = reader.GetInt32(4),
ID = reader.GetInt32(5)
};
scores.Add(score);
}
reader.Dispose();
scores.Add(score);
}
reader.Dispose();
}
}
}
return scores;
}
private static void _IncreaseSongCounter(int dataBaseSongID, SQLiteCommand command)
@@ -316,9 +324,9 @@ namespace Vocaluxe.Base
command.ExecuteNonQuery();
}
private static int _GetDataBaseSongID(SPlayer player, SQLiteCommand command)
private static int _GetDataBaseSongID(int songID, SQLiteCommand command)
{
CSong song = CSongs.GetSong(player.SongID);
CSong song = CSongs.GetSong(songID);
if (song == null)
return -1;
@@ -430,21 +438,35 @@ namespace Vocaluxe.Base
{
if (File.Exists(_HighscoreFilePath))
{
_CreateOrConvert(oldDBFilePath);
_CreateOrConvert(_HighscoreFilePath);
_ImportData(oldDBFilePath);
File.Delete(oldDBFilePath);
if (!_CreateOrConvert(oldDBFilePath))
{
CLog.LogError("Cannot init Highscore DB: Error opening database: " + oldDBFilePath, true, true);
return;
}
if (!_CreateOrConvert(_HighscoreFilePath))
{
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
return;
}
if (!_ImportData(oldDBFilePath))
{
CLog.LogError("Cannot init Highscore DB: Error importing data", true, true);
return;
}
}
else
{
File.Copy(oldDBFilePath, _HighscoreFilePath);
_CreateOrConvert(_HighscoreFilePath);
File.Delete(oldDBFilePath);
if (!_CreateOrConvert(_HighscoreFilePath))
{
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
return;
}
}
File.Delete(oldDBFilePath);
}
else
_CreateOrConvert(_HighscoreFilePath);
else if (!_CreateOrConvert(_HighscoreFilePath))
CLog.LogError("Cannot init Highscore DB: Error opening database: " + _HighscoreFilePath, true, true);
}
private static void _CreateHighscoreDB(string filePath)
@@ -525,6 +547,7 @@ namespace Vocaluxe.Base
/// <returns></returns>
private static bool _CreateOrConvert(string filePath)
{
bool result = true;
using (var connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + filePath;
@@ -565,46 +588,24 @@ namespace Vocaluxe.Base
}
catch (Exception) {}
if (reader == null)
if (reader == null || reader.FieldCount == 0)
{
// create new database/tables
if (version == 1)
{
//Check for USDX 1.1 DB
_CreateHighscoreDBV1(filePath);
_ConvertFrom110(filePath);
_UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
result &= !_ConvertFrom110(filePath);
result &= _UpdateDatabase(1, connection);
result &= _UpdateDatabase(2, connection);
}
else if (version == 0 && scoresTableExists)
{
//Check for USDX 1.01 or CMD Mod DB
_CreateHighscoreDBV1(filePath);
_ConvertFrom101(filePath);
_UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
}
else
_CreateHighscoreDB(filePath);
}
else if (reader.FieldCount == 0)
{
// create new database/tables
if (version == 1)
{
//Check for USDX 1.1 DB
_CreateHighscoreDBV1(filePath);
_ConvertFrom110(filePath);
_UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
}
else if (version == 0 && scoresTableExists)
{
//Check for USDX 1.01 or CMD Mod DB
_CreateHighscoreDBV1(filePath);
_ConvertFrom101(filePath);
_UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
result &= _ConvertFrom101(filePath);
result &= _UpdateDatabase(1, connection);
result &= _UpdateDatabase(2, connection);
}
else
_CreateHighscoreDB(filePath);
@@ -616,7 +617,7 @@ namespace Vocaluxe.Base
if (currentVersion < CSettings.DatabaseHighscoreVersion)
{
// update database
_UpdateDatabase(currentVersion, connection);
result &= _UpdateDatabase(currentVersion, connection);
}
}
@@ -625,7 +626,7 @@ namespace Vocaluxe.Base
}
}
return true;
return result;
}
/// <summary>
@@ -972,8 +973,7 @@ namespace Vocaluxe.Base
lastDateAdded = dateAdded;
}
}
if (reader != null)
reader.Dispose();
reader.Dispose();
foreach (int id in ids)
_IncreaseSongCounter(id, command);
+6 -11
View File
@@ -131,7 +131,7 @@ namespace Vocaluxe.Base
public static void NextRound()
{
_SongQueue.NextRound(Players);
_SongQueue.StartNextRound(Players);
}
public static bool IsFinished()
@@ -149,14 +149,14 @@ namespace Vocaluxe.Base
return _SongQueue.GetSong();
}
public static CSong GetSong(int num)
public static CSong GetSong(int round)
{
return _SongQueue.GetSong(num);
return _SongQueue.GetSong(round);
}
public static EGameMode GetGameMode(int num)
public static EGameMode GetGameMode(int round)
{
return _SongQueue.GetGameMode(num);
return _SongQueue.GetGameMode(round);
}
public static int GetNumSongs()
@@ -197,9 +197,7 @@ namespace Vocaluxe.Base
Players[i].CurrentLine = -1;
Players[i].CurrentNote = -1;
Players[i].SongID = -1;
Players[i].Medley = false;
Players[i].Duet = false;
Players[i].ShortSong = false;
Players[i].GameMode = EGameMode.TR_GAMEMODE_NORMAL;
Players[i].DateTicks = DateTime.Now.Ticks;
Players[i].SongFinished = false;
}
@@ -413,9 +411,6 @@ namespace Vocaluxe.Base
}
Players[p].SungLines.RemoveRange(deleteLine, Players[p].SungLines.Count - deleteLine);
}
//CSong song = GetSong();
//for (int i = 0; i < GetSong().Notes.Voices[0].Lines.Length; i++)
// CLog.LogError((i + 1) + ". " + song.Notes.Voices[0].Lines[i].NoteCount + " - " + Players[0].SungLines[i].NoteCount);
CSound.SetPosition(soundStream, time);
CVideo.Skip(vidStream, time, GetSong().VideoGap);
+17 -13
View File
@@ -183,24 +183,28 @@ namespace Vocaluxe.Screens
public override void LoadTheme(string xmlPath)
{
bool ressourceOK = true;
//Vocaluxe-Logo
CDataBase.GetCreditsRessource("Logo_voc.png", ref _TexLogo);
ressourceOK &= CDataBase.GetCreditsRessource("Logo_voc.png", ref _TexLogo);
//Little stars for logo
CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref _TexPerfectNoteStar);
ressourceOK &= CDataBase.GetCreditsRessource("PerfectNoteStar.png", ref _TexPerfectNoteStar);
CDataBase.GetCreditsRessource("redDot.png", ref _TexRedDot);
CDataBase.GetCreditsRessource("blueDot.png", ref _TexBlueDot);
ressourceOK &= CDataBase.GetCreditsRessource("redDot.png", ref _TexRedDot);
ressourceOK &= CDataBase.GetCreditsRessource("blueDot.png", ref _TexBlueDot);
CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel);
CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice);
CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep);
CDataBase.GetCreditsRessource("flamefire.png", ref _TexNameFlamefire);
CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning);
CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand);
CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03);
CDataBase.GetCreditsRessource("pantero.png", ref _TexNamePantero);
CDataBase.GetCreditsRessource("Pinky007.png", ref _TexNamePinky007);
ressourceOK &= CDataBase.GetCreditsRessource("brunzel.png", ref _TexNameBrunzel);
ressourceOK &= CDataBase.GetCreditsRessource("Darkice.png", ref _TexNameDarkice);
ressourceOK &= CDataBase.GetCreditsRessource("flokuep.png", ref _TexNameFlokuep);
ressourceOK &= CDataBase.GetCreditsRessource("flamefire.png", ref _TexNameFlamefire);
ressourceOK &= CDataBase.GetCreditsRessource("bohning.png", ref _TexNameBohning);
ressourceOK &= CDataBase.GetCreditsRessource("mesand.png", ref _TexNameMesand);
ressourceOK &= CDataBase.GetCreditsRessource("babene03.png", ref _TexNameBabene03);
ressourceOK &= CDataBase.GetCreditsRessource("pantero.png", ref _TexNamePantero);
ressourceOK &= CDataBase.GetCreditsRessource("Pinky007.png", ref _TexNamePinky007);
if (!ressourceOK)
CLog.LogError("Could not load all ressources!", true, true);
//Prepare Text
int lastY = 280;
+14 -32
View File
@@ -44,7 +44,7 @@ namespace Vocaluxe.Screens
private string[] _TextDate;
private string[] _ParticleEffectNew;
private List<SScores>[] _Scores;
private List<SDBScoreEntry>[] _Scores;
private List<int> _NewEntryIDs;
private int _Round;
private int _Pos;
@@ -169,7 +169,7 @@ namespace Vocaluxe.Screens
string name = _Scores[_Round][_Pos + p].Name;
name += " [" + CLanguage.Translate(Enum.GetName(typeof(EGameDifficulty), _Scores[_Round][_Pos + p].Difficulty)) + "]";
if (_IsDuet)
name += " (P" + (_Scores[_Round][_Pos + p].LineNr + 1) + ")";
name += " (P" + (_Scores[_Round][_Pos + p].VoiceNr + 1) + ")";
_Texts[_TextName[p]].Text = name;
_Texts[_TextScore[p]].Text = _Scores[_Round][_Pos + p].Score.ToString("00000");
@@ -194,10 +194,6 @@ namespace Vocaluxe.Screens
base.OnShow();
_Round = 0;
_Pos = 0;
CPoints points = CGame.GetPoints();
_Scores = new List<SScores>[points.NumRounds];
for (int i = 0; i < _Scores.Length; i++)
_Scores[i] = new List<SScores>();
_NewEntryIDs.Clear();
_AddScoresToDB();
_LoadScores();
@@ -231,15 +227,14 @@ namespace Vocaluxe.Screens
private void _LoadScores()
{
CPoints points = CGame.GetPoints();
if (points == null)
return;
_Pos = 0;
for (int round = 0; round < points.NumRounds; round++)
int rounds = CGame.NumRounds;
_Scores = new List<SDBScoreEntry>[rounds];
for (int round = 0; round < rounds; round++)
{
SPlayer player = points.GetPlayer(round, CGame.NumPlayer)[0];
CDataBase.LoadScore(out _Scores[round], player);
int songID = CGame.GetSong(round).ID;
EGameMode gameMode = CGame.GetGameMode(round);
_Scores[round] = CDataBase.LoadScore(songID, gameMode);
}
}
@@ -247,7 +242,7 @@ namespace Vocaluxe.Screens
{
_IsDuet = false;
CPoints points = CGame.GetPoints();
CSong song = CGame.GetSong(_Round + 1);
CSong song = CGame.GetSong(_Round);
if (song == null)
return;
@@ -255,7 +250,7 @@ namespace Vocaluxe.Screens
if (points.NumRounds > 1)
_Texts[_TextSongName].Text += " (" + (_Round + 1) + "/" + points.NumRounds + ")";
switch (CGame.GetGameMode(_Round + 1))
switch (CGame.GetGameMode(_Round))
{
case EGameMode.TR_GAMEMODE_NORMAL:
_Texts[_TextSongMode].Text = "TR_GAMEMODE_NORMAL";
@@ -284,28 +279,15 @@ namespace Vocaluxe.Screens
private void _ChangePos(int num)
{
if (num > 0)
{
if (_Pos + num + _NumEntrys < _Scores[_Round].Count)
_Pos += num;
}
if (num < 0)
{
_Pos += num;
if (_Pos < 0)
_Pos = 0;
}
_Pos += num;
_Pos = _Pos.Clamp(0, _Scores[_Round].Count - 1);
}
private void _ChangeRound(int num)
{
CPoints points = CGame.GetPoints();
if (_Round + num < points.NumRounds && _Round + num > -1)
_Round += num;
else if (_Round + num >= points.NumRounds)
_Round = points.NumRounds - 1;
else if (_Round + num < 0)
_Round = 0;
_Round += num;
_Round = _Round.Clamp(0, points.NumRounds - 1);
_UpdateRound();
}
+5 -6
View File
@@ -241,7 +241,7 @@ namespace Vocaluxe.Screens
break;
case Keys.F10:
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet)
{
CSelectSlide selectSlideDuetPart = _SelectSlides[_SelectSlideDuetPlayer[_SelectingFastPlayerNr - 1]];
selectSlideDuetPart.Selection = (selectSlideDuetPart.Selection + 1) % 2;
@@ -599,7 +599,7 @@ namespace Vocaluxe.Screens
_CheckMics();
_CheckPlayers();
CSong firstSong = CGame.GetSong(1);
CSong firstSong = CGame.GetSong(0);
for (int i = 0; i < CSettings.MaxNumPlayer; i++)
{
@@ -627,12 +627,11 @@ namespace Vocaluxe.Screens
private void _StartSong()
{
for (int i = 0; i < CGame.NumPlayer; i++)
if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet)
{
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
for (int i = 0; i < CGame.NumPlayer; i++)
CGame.Players[i].VoiceNr = _SelectSlides[_SelectSlideDuetPlayer[i]].Selection;
}
CGraphics.FadeTo(EScreens.ScreenSing);
}
@@ -658,7 +657,7 @@ namespace Vocaluxe.Screens
if (_Texts["TextPlayer" + i].Text == "")
_Texts["TextPlayer" + i].Text = CProfiles.GetPlayerName(-1, i);
_Equalizers["EqualizerPlayer" + i].Visible = true;
if (CGame.GetNumSongs() == 1 && CGame.GetSong(1).IsDuet)
if (CGame.GetNumSongs() == 1 && CGame.GetSong(0).IsDuet)
_SelectSlides["SelectSlideDuetPlayer" + i].Visible = true;
}
else
+15 -16
View File
@@ -124,7 +124,8 @@ namespace Vocaluxe.Screens
public override void OnShow()
{
base.OnShow();
_Round = CGame.NumRounds > 1 ? 0 : 1;
//-1 --> Show average
_Round = CGame.NumRounds > 1 ? -1 : 0;
_Points = CGame.GetPoints();
_SavePlayedSongs();
@@ -137,8 +138,8 @@ namespace Vocaluxe.Screens
public override bool UpdateGame()
{
var players = new SPlayer[CGame.NumPlayer];
if (_Round != 0)
players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer);
if (_Round >= 0)
players = _Points.GetPlayer(_Round, CGame.NumPlayer);
else
{
for (int i = 0; i < CGame.NumRounds; i++)
@@ -274,7 +275,7 @@ namespace Vocaluxe.Screens
{
CSong song = null;
var players = new SPlayer[CGame.NumPlayer];
if (_Round != 0)
if (_Round >= 0)
{
song = CGame.GetSong(_Round);
if (song == null)
@@ -282,8 +283,8 @@ namespace Vocaluxe.Screens
_Texts[_TextSong].Text = song.Artist + " - " + song.Title;
if (_Points.NumRounds > 1)
_Texts[_TextSong].Text += " (" + _Round + "/" + _Points.NumRounds + ")";
players = _Points.GetPlayer(_Round - 1, CGame.NumPlayer);
_Texts[_TextSong].Text += " (" + (_Round + 1) + "/" + _Points.NumRounds + ")";
players = _Points.GetPlayer(_Round, CGame.NumPlayer);
}
else
{
@@ -395,16 +396,14 @@ namespace Vocaluxe.Screens
private void _ChangeRound(int num)
{
if ((_Round + num) <= _Points.NumRounds && (_Round + num > 0))
{
_Round += num;
_UpdateRatings();
}
else if (num < 0 && _Round == 1 && CGame.NumRounds > 1)
{
_Round = 0;
_UpdateRatings();
}
if (_Points.NumRounds < 1)
return;
_Round += num;
_Round = _Round.Clamp(-1, _Points.NumRounds - 1);
if (_Round >= _Points.NumRounds)
_Round = _Points.NumRounds - 1;
_UpdateRatings();
}
private void _SavePlayedSongs()
+49 -29
View File
@@ -39,7 +39,7 @@ namespace Vocaluxe.SongQueue
class CSongQueue : ISongQueue
{
private List<SSongQueueEntry> _SongQueue;
private int _CurrentSong;
private int _CurrentRound;
private CPoints _Points;
#region Implementation
@@ -52,9 +52,7 @@ namespace Vocaluxe.SongQueue
public EGameMode GetCurrentGameMode()
{
if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count)
return _SongQueue[_CurrentSong].GameMode;
return EGameMode.TR_GAMEMODE_NORMAL;
return GetGameMode(_CurrentRound);
}
public bool AddVisibleSong(int visibleIndex, EGameMode gameMode)
@@ -105,7 +103,7 @@ namespace Vocaluxe.SongQueue
public void Reset()
{
_CurrentSong = -1;
_CurrentRound = -1;
}
public void Start(SPlayer[] players)
@@ -113,39 +111,51 @@ namespace Vocaluxe.SongQueue
_Points = new CPoints(_SongQueue.Count, players);
}
public void NextRound(SPlayer[] players)
public void StartNextRound(SPlayer[] players)
{
if (_CurrentSong < _SongQueue.Count && _SongQueue.Count > 0)
if (IsFinished())
return;
if (_CurrentRound > -1)
{
if (_CurrentSong > -1)
{
_Points.SetPoints(
_CurrentSong,
_SongQueue[_CurrentSong].SongID,
players,
_SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY,
_SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET,
_SongQueue[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_SHORTSONG);
}
_CurrentSong++;
_Points.SetPoints(
_CurrentRound,
_SongQueue[_CurrentRound].SongID,
players,
_SongQueue[_CurrentRound].GameMode);
}
_CurrentRound++;
}
public bool IsFinished()
{
return _CurrentSong == _SongQueue.Count || _SongQueue.Count == 0;
return _CurrentRound >= _SongQueue.Count || _SongQueue.Count == 0;
}
/// <summary>
/// Get current round nr (1 ~ n)
/// </summary>
/// <returns>current round nr (1 ~ n)</returns>
public int GetCurrentRoundNr()
{
return _CurrentSong + 1;
return _CurrentRound + 1;
}
/// <summary>
/// Returns current round
/// </summary>
/// <returns>Current round (0 based)</returns>
public int GetCurrentRound()
{
return _CurrentRound;
}
/// <summary>
/// Get current song
/// </summary>
/// <returns>Song of current round or null if there is none/game finished</returns>
public CSong GetSong()
{
if (_CurrentSong >= 0 && _CurrentSong < _SongQueue.Count)
return CGameModes.Get(_SongQueue[_CurrentSong].GameMode).GetSong(_SongQueue[_CurrentSong].SongID);
return null;
return GetSong(_CurrentRound);
}
public int GetNumSongs()
@@ -153,18 +163,28 @@ namespace Vocaluxe.SongQueue
return _SongQueue.Count;
}
public CSong GetSong(int num)
/// <summary>
/// Get song of specified round
/// </summary>
/// <param name="round">Round (0 based)</param>
/// <returns>Current song or null if out of bounds</returns>
public CSong GetSong(int round)
{
if (num - 1 < _SongQueue.Count && num > 0)
return CSongs.GetSong(_SongQueue[num - 1].SongID);
if (round < _SongQueue.Count && round >= 0)
return CSongs.GetSong(_SongQueue[round].SongID);
return null;
}
public EGameMode GetGameMode(int num)
/// <summary>
/// Get gameMode of specified round
/// </summary>
/// <param name="round">Round (0 based)</param>
/// <returns>Current song or null if out of bounds</returns>
public EGameMode GetGameMode(int round)
{
if (num - 1 < _SongQueue.Count && num > 0)
return _SongQueue[num - 1].GameMode;
if (round < _SongQueue.Count && round >= 0)
return _SongQueue[round].GameMode;
return EGameMode.TR_GAMEMODE_NORMAL;
}
+6 -6
View File
@@ -25,8 +25,6 @@ namespace Vocaluxe.SongQueue
{
void Init();
EGameMode GetCurrentGameMode();
bool AddVisibleSong(int visibleIndex, EGameMode gameMode);
bool AddSong(int absoluteIndex, EGameMode gameMode);
bool RemoveVisibleSong(int visibleIndex);
@@ -35,15 +33,17 @@ namespace Vocaluxe.SongQueue
void Reset();
void Start(SPlayer[] players);
void NextRound(SPlayer[] players);
void StartNextRound(SPlayer[] players);
bool IsFinished();
int GetCurrentRoundNr();
CPoints GetPoints();
int GetNumSongs();
int GetCurrentRoundNr();
CSong GetSong();
CSong GetSong(int num);
EGameMode GetGameMode(int num);
CSong GetSong(int round);
EGameMode GetCurrentGameMode();
EGameMode GetGameMode(int round);
}
}
+9
View File
@@ -47,6 +47,15 @@ namespace VocaluxeLib
return (int)result;
}
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0)
return min;
if (val.CompareTo(max) > 0)
return max;
return val;
}
/// <summary>
/// Concat strings into one string with ", " as separator.
/// </summary>
+4 -10
View File
@@ -35,15 +35,13 @@ namespace VocaluxeLib.Game
_Rounds[round, player].Points = 0f;
_Rounds[round, player].PointsGoldenNotes = 0f;
_Rounds[round, player].PointsLineBonus = 0f;
_Rounds[round, player].Medley = false;
_Rounds[round, player].Duet = false;
_Rounds[round, player].ShortSong = false;
_Rounds[round, player].GameMode = EGameMode.TR_GAMEMODE_NORMAL;
_Rounds[round, player].SongFinished = false;
}
}
}
public void SetPoints(int round, int songID, SPlayer[] players, bool medley, bool duet, bool shortSong)
public void SetPoints(int round, int songID, SPlayer[] players, EGameMode gameMode)
{
long dateTicks = DateTime.Now.Ticks;
for (int player = 0; player < players.Length; player++)
@@ -53,9 +51,7 @@ namespace VocaluxeLib.Game
_Rounds[round, player].Points = players[player].Points;
_Rounds[round, player].PointsGoldenNotes = players[player].PointsGoldenNotes;
_Rounds[round, player].PointsLineBonus = players[player].PointsLineBonus;
_Rounds[round, player].Medley = medley;
_Rounds[round, player].Duet = duet;
_Rounds[round, player].ShortSong = shortSong;
_Rounds[round, player].GameMode = gameMode;
_Rounds[round, player].DateTicks = dateTicks;
_Rounds[round, player].SongFinished = players[player].SongFinished;
}
@@ -87,9 +83,7 @@ namespace VocaluxeLib.Game
players[p].PointsLineBonus = _Rounds[round, p].PointsLineBonus;
players[p].SongID = _Rounds[round, p].SongID;
players[p].VoiceNr = _Rounds[round, p].VoiceNr;
players[p].Medley = _Rounds[round, p].Medley;
players[p].Duet = _Rounds[round, p].Duet;
players[p].ShortSong = _Rounds[round, p].ShortSong;
players[p].GameMode = _Rounds[round, p].GameMode;
players[p].DateTicks = _Rounds[round, p].DateTicks;
players[p].SongFinished = _Rounds[round, p].SongFinished;
players[p].ProfileID = _Rounds[round, p].ProfileID;
+4 -9
View File
@@ -63,15 +63,10 @@ namespace VocaluxeLib.Songs
{
get
{
int min = int.MaxValue;
int max = int.MinValue;
foreach (T note in _Notes)
{
if (note.Tone < min)
min = note.Tone;
if (note.Tone > max)
max = note.Tone;
}
if (_Notes.Count == 0)
return 0;
int min = _Notes.Min(note => note.Tone);
int max = _Notes.Max(note => note.Tone);
return min - (max - min) / 4;
}
+3 -5
View File
@@ -190,20 +190,18 @@ namespace VocaluxeLib
public int CurrentNote;
public int SongID;
public bool Medley;
public bool Duet;
public bool ShortSong;
public EGameMode GameMode;
public long DateTicks;
public bool SongFinished;
}
public struct SScores
public struct SDBScoreEntry
{
public string Name;
public int Score;
public string Date;
public EGameDifficulty Difficulty;
public int LineNr;
public int VoiceNr;
public int ID;
}