ES2 File Sorting

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
brandoncluff
Posts: 4
Joined: Sun Dec 03, 2017 9:47 pm

ES2 File Sorting

Post by brandoncluff »

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;
    }
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES2 File Sorting

Post by Joel »

Hi there,

You would need to load the timestamp from each file, and then sort these. There is no built-in method of doing this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked