Esempio n. 1
0
    public static void SaveData(this ISaveAsJson source, JSON mainData)
    {
        JSON saveData = source.Save();

        saveData.AddOrReplace(VersionKey, source.Version);
        mainData.Add(source.Key, saveData);
    }
Esempio n. 2
0
    public static bool IsOldVersion(this ISaveAsJson source, JSON data)
    {
        if (!data.ContainsKey(VersionKey))
        {
            throw new KeyNotFoundException($"El archivo NO contiene la VersionKey '{VersionKey}' para el tipo de archivo: {source.GetType()}");
        }

        int fileVersion = data.GetInt(VersionKey);

        return(fileVersion < source.Version);
    }
Esempio n. 3
0
    public static void LoadData(this ISaveAsJson source, JSON mainData)
    {
        if (!mainData.ContainsKey(source.Key))
        {
            return;
        }
        JSON loadData = mainData.GetJSON(source.Key);

        if (!mainData.ContainsKey(source.Key))
        {
            return;
        }
        if (IsOldVersion(source, loadData))
        {
            source.UpdateSaveData(loadData);
        }
        source.Load(loadData);
    }
 public static void Unregister(ISaveAsJson target) => Instance.saveAsJsonModule.Unregister(target);
 public void Unregister(ISaveAsJson saveAsJson) => saveAsJsonModule.Unregister(saveAsJson);
 public void Register(ISaveAsJson saveAsJson) => saveAsJsonModule.Register(saveAsJson);
Esempio n. 7
0
 public void Unregister(ISaveAsJson target)
 {
     OnLoad -= target.LoadData;
     OnSave -= target.SaveData;
 }
Esempio n. 8
0
 public void Register(ISaveAsJson target)
 {
     OnLoad += target.LoadData;
     OnSave += target.SaveData;
 }