OWClock/ClockLib/EventFile.cs
Adam Kauffman 7dca739904 Version 0.5.0 Compatible with OWML 2.1.0
Update to Framework 4.8
Update all NuGet packages to latest
Remove unused references
Add NetAnalyzers
Close all messages from new NetAnalyzers
2021-10-23 01:03:23 -07:00

36 lines
963 B
C#

using System;
using System.Collections.Generic;
namespace Clock
{
[Serializable]
public class EventFile
{
public List<TimeEvent> eventList = new List<TimeEvent>();
private const string _fileName = "events.json";
public void AddEvent(float timestamp, string name)
{
eventList.Add(new TimeEvent((float)Math.Truncate(timestamp), name));
eventList.Sort(SortTimestamp);
Save();
}
private void Save()
{
OWClock.Helper.Storage.Save(this, _fileName);
}
public static EventFile LoadSaveFile()
{
var save = OWClock.Helper.Storage.Load<EventFile>(_fileName);
save.eventList.Sort(SortTimestamp);
return save ?? new EventFile();
}
private static int SortTimestamp(TimeEvent e1, TimeEvent e2)
{
return e1.Timestamp.CompareTo(e2.Timestamp);
}
}
}