Exemple #1
0
 private static void Load(string fileName)
 {
     if (File.Exists(fileName))
     {
         try
         {
             var newLap = new CompletedLap(fileName);
             if (newLap.lap == null || newLap.lap.lapTime == 0)
             {
                 // Ignored invalid lap
             }
             else
             {
                 Laps.Add(
                     new LapInfo()
                 {
                     CarNumber   = newLap.playerInfo.raceNumber.ToString(),
                     CircuitName = Constants.TrackList.First(t => t.id == newLap.circuitInfo.trackId).name,
                     FileName    = newLap.FileName(),
                     LapTime     = newLap.lap.lapTime,
                     PlayerName  = PacketHelper.GetString(newLap.playerInfo.name, 48),
                     SessionType = Constants.SessionTypeList.First(t => t.id == newLap.circuitInfo.sessionType).name,
                     TeamName    = Constants.TeamList.First(t => t.id == newLap.playerInfo.teamId)?.name,
                     Tyre        = "?", // Packet type Car Status not handled yet
                     Details     = newLap
                 });
             }
         }
         catch // (Exception e)
         {
             //lama
             // MessageDialog.Show(e);
         }
     }
 }
Exemple #2
0
 public static void Add(CompletedLap completedLap)
 {
     if (Laps.FirstOrDefault(l => l.FileName == completedLap.Pathname()) == null)
     {
         // New Lap. Save to disk
         Directory.CreateDirectory(BS(baseDir) + completedLap.Dirname());
         if (!File.Exists(BS(baseDir) + completedLap.Pathname()))
         {
             completedLap.Save(baseDir);
             Laps.Add(
                 new LapInfo()
             {
                 CarNumber   = completedLap.playerInfo.raceNumber.ToString(),
                 CircuitName = Constants.TrackList.First(t => t.id == completedLap.circuitInfo.trackId)?.name,
                 FileName    = completedLap.FileName(),
                 LapTime     = completedLap.lap.lapTime,
                 PlayerName  = PacketHelper.GetString(completedLap.playerInfo.name, 48),
                 SessionType = Constants.SessionTypeList.First(t => t.id == completedLap.circuitInfo.sessionType)?.name,
                 TeamName    = Constants.TeamList.First(t => t.id == completedLap.playerInfo.teamId)?.name,
                 Tyre        = "?", // Packet type Car Status not handled yet
                 Details     = completedLap
             });
             SaveDictionary();
         }
     }
 }
Exemple #3
0
        public void Update(PacketParticipantsData data, bool addAlways = false)
        {
            participantsData = data;
            if (circuit != null)
            {
                // LogLine("Aantal auto's: " + participantsData.numActiveCars);
                circuit.NumberOfCars = data.numActiveCars;
            }
            int participantIndex = 0;

            foreach (var participant in data.participants)
            {
                var str = PacketHelper.GetString(participant.name, 48);
                // Data might be empty if not enough cars available
                if (str != "" || participant.driverId != 0)
                {
                    var isAI = (participant.aiControlled == (byte)1 ? "AI" : "=>");
                    // LogLine($"{isAI} {(int)participant.raceNumber} {str} {PacketHelper.Country(participant.nationality)}, {participant.driverId}, Team:{participant.teamId})");
                    lock (playerInfo)
                    {
                        var player = GetPlayerByDriverID(participant.driverId);

                        if (player == null || addAlways)
                        {
                            playerInfo[participantIndex] = new PlayerInfo(participant, participantIndex);
                        }
                        else
                        {
                            if (player.CarNumber != participant.raceNumber)
                            {
                                if (participant.raceNumber == 0)
                                {
                                    playerInfo[participantIndex] = new PlayerInfo(participant, participantIndex);
                                }
                                else
                                {
                                    throw new Exception($"Car switch detected {player.Name},{player.CarNumber} => {participant.name},{participant.raceNumber} ");
                                }
                            }
                            else
                            {
                                playerInfo[participantIndex]?.Update(participant);
                            }
                        }
                    }
                }
                participantIndex++;
            }
        }
Exemple #4
0
        public PlayerInfo(ParticipantData p, int index)
        {
            participantInfo = p;
            Id       = index;
            driverId = p.driverId;
            lapStore = new Dictionary <int, LapRecording>();

            Name      = PacketHelper.GetString(participantInfo.name, 48) + " (" + PacketHelper.CountryShort(participantInfo.nationality) + ")";
            CarNumber = participantInfo.raceNumber;
            if (index < ColorSchemes.schemes.Count)
            {
                BackColor = ColorSchemes.schemes[index].Background;
                TextColor = ColorSchemes.schemes[index].Text;
            }
            else
            {
                BackColor = ColorSchemes.schemes[0].Background;
                TextColor = ColorSchemes.schemes[0].Text;
            }
        }
Exemple #5
0
 public string FileName()
 {
     return(Constants.GetName(Constants.StockType.stSessionType, circuitInfo.sessionType) + (playerInfo.aiControlled == 1 ? " AI " : " ") +
            playerInfo.raceNumber.ToString() + " " + PacketHelper.GetString(playerInfo.name, 48) + (circuitInfo.formula == 0 ? " " : " F" + (circuitInfo.formula + 1).ToString() + " ") +
            lap.lapTime.ToString("0.000").Replace(",", "."));
 }
Exemple #6
0
 public void Update(ParticipantData p)
 {
     participantInfo = p;
     Name            = PacketHelper.GetString(participantInfo.name, 48) + " (" + PacketHelper.CountryShort(participantInfo.nationality) + ")";
 }