Sort new events

This commit is contained in:
clubby789 2020-09-20 12:54:53 +01:00
parent 0f42436f3e
commit 35da26d4be
3 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Clock
{
@ -12,6 +13,7 @@ namespace Clock
public void AddEvent(float timestamp, string name)
{
eventList.Add(new TimeEvent(timestamp, name));
eventList.Sort(SortTimestamp);
Save();
}
@ -23,7 +25,13 @@ namespace Clock
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);
}
}
}

BIN
ClockLib/Release.zip Normal file

Binary file not shown.

View File

@ -5,11 +5,11 @@
"Name": "Loop start"
},
{
"Timestamp": 15.0,
"Timestamp": 30.0,
"Name": "Event happens"
},
{
"Timestamp": 30.0,
"Timestamp": 15.0,
"Name": "Another one happens"
},
{