private void _LoadScores() { _Pos = 0; int rounds = CGame.NumRounds; _Scores = new List <SDBScoreEntry> [rounds]; for (int round = 0; round < rounds; round++) { int songID = CGame.GetSong(round).ID; EGameMode gameMode = CGame.GetGameMode(round); EHighscoreStyle style = CBase.Config.GetHighscoreStyle(); _Scores[round] = CDataBase.LoadScore(songID, gameMode, style); } }
private void _LoadScores() { _Pos = 0; int rounds = CGame.NumRounds; if (rounds == 0) { _FromScreenSong = true; _Round = (int)EGameMode.TR_GAMEMODE_NORMAL; _Scores = new List <SDBScoreEntry> [4]; int songID = CScreenSong.getSelectedSongID(); EHighscoreStyle style = CBase.Config.GetHighscoreStyle(); bool foundHighscoreEntries = false; for (int gameModeNum = 0; gameModeNum < 4; gameModeNum++) { _Scores[gameModeNum] = CDataBase.LoadScore(songID, (EGameMode)gameModeNum, style); if (!foundHighscoreEntries && _Scores[gameModeNum].Count > 0) { _Round = gameModeNum; foundHighscoreEntries = true; } } } else { _FromScreenSong = false; _Scores = new List <SDBScoreEntry> [rounds]; for (int round = 0; round < rounds; round++) { int songID = CGame.GetSong(round).ID; EGameMode gameMode = CGame.GetGameMode(round); EHighscoreStyle style = CBase.Config.GetHighscoreStyle(); _Scores[round] = CDataBase.LoadScore(songID, gameMode, style); } } }
public static List <SDBScoreEntry> LoadScore(int songID, EGameMode gameMode, EHighscoreStyle style) { return(_HighscoreDB == null ? null : _HighscoreDB.LoadScore(songID, gameMode, style)); }
public List <SDBScoreEntry> LoadScore(int songID, EGameMode gameMode, EHighscoreStyle style) { var scores = new List <SDBScoreEntry>(); using (var connection = new SQLiteConnection()) { connection.ConnectionString = "Data Source=" + _FilePath; try { connection.Open(); } catch (Exception) { return(scores); } using (var command = new SQLiteCommand(connection)) { int medley = 0; int duet = 0; int shortSong = 0; switch (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; } int dataBaseSongID = _GetDataBaseSongID(songID, command); if (dataBaseSongID < 0) { return(scores); } switch (style) { case EHighscoreStyle.TR_CONFIG_HIGHSCORE_LIST_BEST: command.CommandText = "SELECT os.PlayerName, os.Score, os.Date, os.Difficulty, os.LineNr, os.id " + "FROM Scores os " + "INNER JOIN ( " + "SELECT sc.PlayerName, sc.Score, sc.Difficulty, sc.LineNr, MIN(sc.Date) AS Date " + "FROM Scores sc " + "INNER JOIN ( " + "SELECT Playername, MAX(Score) AS Score, Difficulty, LineNr " + "FROM Scores " + "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " + "GROUP BY PlayerName, Difficulty, LineNr " + ") AS mc " + "ON sc.PlayerName = mc.PlayerName AND sc.Difficulty = mc.Difficulty AND sc.LineNr = mc.LineNr AND sc.Score = mc.Score " + "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " + "GROUP BY sc.PlayerName, sc.Difficulty, sc.LineNr, sc.Score " + ") AS iq " + "ON os.PlayerName = iq.PlayerName AND os.Difficulty = iq.Difficulty AND os.LineNr = iq.LineNr AND os.Score = iq.Score AND os.Date = iq.Date " + "WHERE [SongID] = @SongID AND [Medley] = @Medley AND [Duet] = @Duet AND [ShortSong] = @ShortSong " + "GROUP BY os.PlayerName, os.Difficulty, os.LineNr, os.Score " + "ORDER BY os.Score DESC, os.Date ASC"; break; case EHighscoreStyle.TR_CONFIG_HIGHSCORE_LIST_ALL: 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, [Date] ASC"; break; } 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()) { 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(); } } } return(scores); }