forked from Shotnex4/LiveSplit.TimeAttackPause
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
333 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/bin | ||
/obj | ||
/.vs | ||
/.idea |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using LiveSplit.Model; | ||
|
||
namespace LiveSplit.TimeAttackPause.DTO | ||
namespace LiveSplit.TimeAttackPause.DTO; | ||
|
||
public record Run | ||
{ | ||
public record Run | ||
{ | ||
public TimingMethod TimingMethod { get; set; } | ||
public List<Split> Splits { get; set; } | ||
public int CurrentSplitIndex { get; set; } | ||
public TimeSpan? CurrentSplitTime { get; set; } | ||
public TimeSpan? CurrentTime { get; set; } | ||
} | ||
} | ||
public TimingMethod TimingMethod { get; set; } | ||
public List<Split> Splits { get; set; } | ||
public int CurrentSplitIndex { get; set; } | ||
public TimeSpan? CurrentSplitTime { get; set; } | ||
public TimeSpan? CurrentTime { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#nullable enable | ||
using System; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
using LiveSplit.Model; | ||
|
||
using Run = LiveSplit.TimeAttackPause.DTO.Run; | ||
|
||
/* using Newtonsoft.Json; */ | ||
|
||
namespace LiveSplit.TimeAttackPause.IO; | ||
|
||
public static class SplitsStateDeserializer | ||
{ | ||
public static void ImportState(string filepath, LiveSplitState state, ITimerModel timerModel) | ||
{ | ||
// read all the text from the file as string | ||
string data = File.ReadAllText(filepath); | ||
var serializer = new XmlSerializer(typeof(Run)); | ||
Run? runDto; | ||
|
||
/* if (data.IsNullOrEmpty()) | ||
{ | ||
throw new Exception("Imported file was empty or null."); | ||
} */ | ||
|
||
/* var string_reader = new StringReader(data); */ | ||
using (var stream_reader = new StreamReader(data)) | ||
{ | ||
var xml_reader = XmlReader.Create(stream_reader); | ||
/* try | ||
{ runDto = (Run)xml_reader.ReadContentAsObject(); } | ||
catch (FormatException) | ||
{ } | ||
catch (InvalidCastException) | ||
{ } | ||
catch (InvalidOperationException) | ||
{ } */ | ||
|
||
runDto = (Run)serializer.Deserialize(xml_reader); | ||
|
||
xml_reader.Dispose(); | ||
|
||
if (runDto == null) | ||
{ | ||
/* throw new Exception("Couldn't deserialize run (runDto was null)"); */ | ||
return; | ||
} | ||
} | ||
|
||
/* JsonConvert.DeserializeObject<Run>(data); */ | ||
|
||
timerModel.Start(); | ||
|
||
int i = 0; | ||
foreach (ISegment segment in state.Run) // ISegment is a split | ||
{ | ||
segment.SplitTime = new Time(runDto.TimingMethod, runDto.Splits[i].Time); | ||
i += 1; | ||
} | ||
|
||
state.CurrentSplitIndex = runDto.CurrentSplitIndex; | ||
state.AdjustedStartTime = TimeStamp.Now - runDto.CurrentTime.GetValueOrDefault(TimeSpan.Zero); | ||
state.IsGameTimeInitialized = true; | ||
timerModel.Pause(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
using LiveSplit.Model; | ||
using LiveSplit.TimeAttackPause.DTO; | ||
|
||
using Run = LiveSplit.TimeAttackPause.DTO.Run; | ||
|
||
namespace LiveSplit.TimeAttackPause.IO; | ||
|
||
public static class SplitsStateSerializer | ||
{ | ||
public static void SaveSplitsState(LiveSplitState state, string saveFilePath) | ||
{ | ||
TimingMethod timingMethod = state.CurrentTimingMethod; | ||
|
||
var splits = state.Run.ToList(); | ||
|
||
var splitsDTOs = new List<Split>(); | ||
foreach (ISegment split in splits) | ||
{ | ||
TimeSpan? time = split.SplitTime[timingMethod]; | ||
var splitDto = new Split() | ||
{ | ||
Time = time, | ||
Name = split.Name | ||
}; | ||
splitsDTOs.Add(splitDto); | ||
} | ||
|
||
var run = new Run() | ||
{ | ||
TimingMethod = timingMethod, | ||
Splits = splitsDTOs, | ||
CurrentSplitIndex = state.CurrentSplitIndex, | ||
CurrentSplitTime = state.CurrentSplit.SplitTime[timingMethod], | ||
CurrentTime = state.CurrentTime[timingMethod], | ||
}; | ||
|
||
// Use xml to serialize the run | ||
var serializer = new XmlSerializer(typeof(Run)); | ||
string data = ""; | ||
|
||
using (var string_writer = new StringWriter()) | ||
{ | ||
var xml_writer = XmlWriter.Create(string_writer); | ||
serializer.Serialize(xml_writer, run); | ||
data = string_writer.ToString(); // The run basically | ||
xml_writer.Dispose(); | ||
} | ||
|
||
// use newtonsoft json to serialize the run object to json | ||
/* string json = JsonConvert.SerializeObject(run, Newtonsoft.Json.Formatting.Indented); */ | ||
File.WriteAllText(saveFilePath, data); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.