ES2 File Sorting
Posted: Thu Dec 14, 2017 7:28 pm
I'm implementing a save file system that allows the user to create new saves that contain basic information and are assigned a random unique id for their names. I'm trying to return them in a list sorted by last updated (either by the file timestamp or by the timestamp that I'm saving within the file). Is there an easy way to do this? The method in question is GetSaves() - my code below.
Code: Select all
public void NewGame(string name) {
string file = CreateFile(name);
UpdateFile(file);
CreateSaveSlot(saveSlotPrefab, saveContent, SaveSlot.SlotType.SAVE, file, name);
CreateSaveSlot(loadSlotPrefab, loadContent, SaveSlot.SlotType.LOAD, file, name);
}
public void SaveGame(SaveSlot slot, string file) {
UpdateFile(file);
slot.UpdateTime(System.DateTime.Now.ToString());
}
public void LoadGame() {
//TODO:: LOGIC
}
private string CreateFile(string saveName) {
string newFile = GameManager.Instance.Mode.ToString() + "-" + System.Guid.NewGuid().ToString() + ".txt";
ES2.Save(GameManager.Instance.Mode.ToString(), newFile + "?tag=gameType");
ES2.Save(saveName, newFile + "?tag=saveName");
return newFile;
}
private void UpdateFile(string saveFile) {
ES2.Save(System.DateTime.Now.ToString(), saveFile + "?tag=saveTime");
}
private string[] GetSaves() {
//TODO:: ORDER BY SAVE TIME
string[] saves = ES2.GetFiles("", "*.txt");
return saves;
}