Exemplo n.º 1
0
        private void HandleSample(DataSample sample)
        {
            if (!_hasSentSessionData)
            {
                _hasSentSessionData = true;
                NewSessionInfo?.Invoke(SessionInfo.FromSessionData(sample.SessionData));
            }

            _subject.OnNext(new TelemetryUpdate
            {
                MyCar            = MyCarState.FromDataSample(sample),
                CompetitorStates = CarState.FromSample(sample)
            });
        }
        internal static MyCarState FromDataSample(DataSample data)
        {
            var t      = data.Telemetry;
            var carIdx = (int)data.SessionData.DriverInfo.DriverCarIdx;

            var driver = data.SessionData.DriverInfo.Drivers[carIdx];

            var result = new MyCarState
            {
                CarIdx                = carIdx,
                Position              = t.PlayerCarPosition,
                PositionInClass       = t.PlayerCarClassPosition,
                Lap                   = t.Lap,
                LapCompleted          = t.LapCompleted,
                IsInPits              = t.OnPitRoad,
                DriverName            = driver.UserName,
                DriverID              = driver.UserID,
                TeamID                = driver.TeamID,
                FuelLevel             = t.FuelLevel,
                FuelLevelPercent      = t.FuelLevelPct,
                FuelUsePerHour        = t.FuelUsePerHour,
                PitRepairLeft         = t.PitRepairLeft,
                PitOptionalRepairLeft = t.PitOptRepairLeft,
                CurrentLapTime        = t.LapCurrentLapTime,
                LastLapTime           = t.LapLastLapTime
            };

            if (t.CarIdxPitStopCount != null)
            {
                result.PitStopCount = t.CarIdxPitStopCount[result.CarIdx];
            }

            if (t.HasRetired != null)
            {
                result.HasRetired = t.HasRetired[result.CarIdx];
            }

            return(result);
        }