Beispiel #1
0
    public void CopyTrack(string track, string newName = "")
    {
        if (string.IsNullOrEmpty(newName))
        {
            newName = track + "_copy";
        }

        string destinationDirectory = TracksRootFolder + "/" + newName;

        // Get the subdirectories for the specified directory.
        DirectoryInfo dir = new DirectoryInfo(TracksRootFolder + "/" + track);

        if (!dir.Exists)
        {
            throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + track);
        }

        if (!Directory.Exists(destinationDirectory))
        {
            Directory.CreateDirectory(destinationDirectory);
        }

        // Get the files in the directory and copy them to the new location.
        FileInfo[] files = dir.GetFiles();
        foreach (FileInfo file in files)
        {
            string temppath = Path.Combine(destinationDirectory, newName + file.Name.Substring(file.Name.IndexOf('.'))); //TODO: DO NOT ALLOW Extra '.' in map names. will break this naive solution
            file.CopyTo(temppath, false);
        }

        var trackXMLEditor = new TrackXMLDataEditor(newName);

        trackXMLEditor.ChangeTrackName(newName);
    }
    public void UpdateStandings(List <CarRaceData> lapinfo)
    {
        //Order points
        for (int i = 0; i < lapinfo.Count; i++)
        {
            PlayerStandings[lapinfo[i].car.Player].Points     += RacePointTemplate.PointOrder[i];
            PlayerStandings[lapinfo[i].car.Player].PointsAdded = RacePointTemplate.PointOrder[i];
        }

        //Fastest lap points
        var lapInfoWithTime        = lapinfo.FindAll(x => x.LastLapTime > 0);
        var carsWithFastestLapTime = lapInfoWithTime.OrderBy(x => x.FastestLapTime);

        if (carsWithFastestLapTime.Any())
        {
            var fastestCarRaceData = carsWithFastestLapTime.First();

            if (fastestCarRaceData != null)
            {
                var fastestPlayer = fastestCarRaceData.car.Player;
                PlayerStandings[fastestPlayer].Points     += RacePointTemplate.FastestLap;
                PlayerStandings[fastestPlayer].TrackRecord = true;

                //Update TrackRecord
                if (Track.Instance.Metadata.TrackRecord == 0 || Track.Instance.Metadata.TrackRecord > fastestCarRaceData.FastestLapTime)
                {
                    var trackXMLEditor = new TrackXMLDataEditor(Track.Instance.Metadata.Name);
                    trackXMLEditor.ChangeTrackRecord(fastestCarRaceData.FastestLapTime);
                }
            }
        }

        //Player did not finish points
        foreach (var linfo in lapinfo.FindAll(x => x.Finished == false).ToList())
        {
            PlayerStandings[linfo.car.Player].Points -= RacePointTemplate.DidNotFinish;
        }

        SortDictionaryByValue();
    }