Пример #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);
    }
Пример #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);
    }
Пример #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);
Пример #7
0
 public void Unregister(ISaveAsJson target)
 {
     OnLoad -= target.LoadData;
     OnSave -= target.SaveData;
 }
Пример #8
0
 public void Register(ISaveAsJson target)
 {
     OnLoad += target.LoadData;
     OnSave += target.SaveData;
 }