Ejemplo n.º 1
0
        /// <summary>
        /// Serialize and export timing data of current checkpoints to JSON file.
        /// </summary>
        public void exportTimingSheet()
        {
            // compute the hash code of this race
            int raceHash = GetHashCode();

            // build instance of ExportableTimingSheet
            ExportableTimingSheet timingSheet = new ExportableTimingSheet()
            {
                exportDatetime = DateTime.UtcNow,
                raceHashCode   = GetHashCode(),
                timingData     = markedSectorCheckpoints.Select(chkpt => chkpt.getSimplifiedTimingData()).ToArray()
            };

            // export file
            TimingSheetExporter.serializeToJson(timingSheet, raceHash.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Import a race from a file on disk. The currently placed checkpoints will be overwritten.
        /// </summary>
        public void importRace(string path = null)
        {
            // clean up any existing race/checkpoints
            if (raceMode)
            {
                exitRaceMode();
            }
            clearAllSectorCheckpoints();

            // set placement mode active; make sure player is not in race mode (exit if need to)
            placementMode = true;

            // prompt user to enter the name of the file (with or without the file extension) to import from
            string name = path == null?GTA.Game.GetUserInput("custom_race") : path;

            try
            {
                // attempt to import from file
                ExportableRace race = RaceExporter.deserializeFromJson(name, path == null ? false : true);

                // repopulate List<SectorCheckpoint> using the imported race data
                lapRace = race.lapMode;
                for (int i = 0; i < race.checkpoints.Length; i++)
                {
                    SimplifiedCheckpoint sc    = race.checkpoints[i];
                    SectorCheckpoint     chkpt = new SectorCheckpoint(sc.number, sc.position, sc.quarternion, false);
                    markedSectorCheckpoints.Add(chkpt);
                }

                // inform user of successful load
                GTA.UI.Notification.Show("Lap Timer: successfully imported race!");

                // with the race loaded & reconstructed, try to load timing sheet. make sure all hash codes match!
                int raceHash = GetHashCode();
                ExportableTimingSheet timingSheet = TimingSheetExporter.deserializeFromJson(raceHash.ToString());
                for (int i = 0; i < timingSheet.timingData.Length; i++)
                {
                    markedSectorCheckpoints[i].setTimingDataFromSimplified(timingSheet.timingData[i]);
                }
                GTA.UI.Notification.Show("Lap Timer: successfully imported personal timing sheet for the imported race!");
            }
            catch { }
        }