/// <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 { } }
/// <summary> /// Create an instance of <c>ExportableRace</c> with data provided. /// </summary> /// <param name="name">Name of race</param> /// <param name="chkpts">List of SectorCheckpoints</param> /// <param name="lapMode">Whether the race should run in lap mode</param> /// <returns></returns> public static ExportableRace createExportableRace(string name, List <SectorCheckpoint> chkpts, bool lapMode) { // create new instance of ExportableRace & set metadata ExportableRace race = new ExportableRace(); race.name = name; race.lapMode = lapMode; race.numCheckpoints = chkpts.Count; race.version = scriptVersion; // iterate over list of SectorCheckpoints and simplify each before adding to ExportableRace race.checkpoints = new SimplifiedCheckpoint[chkpts.Count]; for (int i = 0; i < chkpts.Count; i++) { SimplifiedCheckpoint sc = new SimplifiedCheckpoint(); sc.position = chkpts[i].position; sc.quarternion = chkpts[i].quarternion; sc.number = chkpts[i].number; race.checkpoints[i] = sc; } return(race); }