public void Load(int i) { string filename = "data" + i + ".sav"; string toLoad = SaveLoadTool.LoadFile(SaveLoadTool.GetSavePath(filename)); LoadDataFromJson(toLoad); }
public void ChangeSave() { string sysSave = JsonConvert.SerializeObject(tempData.saveInfo); SaveLoadTool.SaveFile(SaveLoadTool.GetSavePath("datasv.sav"), sysSave); RefreshSavePic(); }
/// <summary> /// 初始化多周目数据 /// </summary> private void InitMultiplay() { string filename = "datamp.sav"; string savepath = SaveLoadTool.GetSavePath(filename); //判断是否含有datamp文件 if (!SaveLoadTool.IsFileExists(savepath)) { //若不存在 则生成默认数据表 DefaultMultiData(); //并写入本地文件 string toSave = JsonConvert.SerializeObject(multiData); SaveLoadTool.SaveFile(savepath, toSave); } else { try { //若文件存在 则读取二周目数据 string toLoad = SaveLoadTool.LoadFile(savepath); multiData = JsonConvert.DeserializeObject <MultiData>(toLoad); } catch { Debug.LogError("存档文件不符,已重置"); //出差错则覆盖本地文件 DefaultMultiData(); string toSave = JsonConvert.SerializeObject(multiData); SaveLoadTool.SaveFile(savepath, toSave); } } }
private void InitSystem() { string filename = "config.sav"; string savepath = SaveLoadTool.GetSavePath(filename); if (!SaveLoadTool.IsFileExists(savepath)) { //若不存在则创建默认数据 ResetSysConfig(); string toSave = JsonConvert.SerializeObject(configData); SaveLoadTool.SaveFile(savepath, toSave); } else { try { //读取config string toLoad = SaveLoadTool.LoadFile(savepath); configData = JsonConvert.DeserializeObject <ConfigData>(toLoad); } catch { Debug.LogError("存档文件不符,已重置"); //出错则采用默认 并覆盖原文件 ResetSysConfig(); string toSave = JsonConvert.SerializeObject(configData); SaveLoadTool.SaveFile(savepath, toSave); } } }
/// <summary> /// 初始化存档 /// </summary> private void InitSaving() { Dictionary <int, SavingInfo> list = new Dictionary <int, SavingInfo>(); string filename = "datasv.sav"; string savepath = SaveLoadTool.GetSavePath(filename); if (SaveLoadTool.IsFileExists(savepath)) { //读取存档列表 string toLoad = SaveLoadTool.LoadFile(savepath); list = JsonConvert.DeserializeObject <Dictionary <int, SavingInfo> >(toLoad); } tempData.saveInfo = list; RefreshSavePic(); }
/// <summary> /// 读取存档的图片并写入Data /// </summary> public void RefreshSavePic() { Dictionary <int, SavingInfo> list = tempData.saveInfo; Dictionary <string, byte[]> savepic = new Dictionary <string, byte[]>(); foreach (KeyValuePair <int, SavingInfo> kv in list) { string picname = "data" + kv.Key + ".png"; string picpath = SaveLoadTool.GetSavePath(picname); FileStream fs = new FileStream(picpath, FileMode.Open, FileAccess.Read); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, (int)fs.Length); fs.Close(); savepic.Add(kv.Value.picPath, bytes); } tempData.WriteTempVar("存档缩略图", savepic); }
public void Delete(int i) { //删除存档 string filename = "data" + i + ".sav"; SaveLoadTool.DeleteFile(SaveLoadTool.GetSavePath(filename)); //删除截图 string picname = "data" + i + ".png"; SaveLoadTool.DeleteFile(SaveLoadTool.GetSavePath(picname)); //更新存档信息 Dictionary <int, SavingInfo> savedic = tempData.saveInfo; if (savedic.ContainsKey(i)) { savedic.Remove(i); } //写入系统存档 string sysSave = JsonConvert.SerializeObject(savedic); SaveLoadTool.SaveFile(SaveLoadTool.GetSavePath("datasv.sav"), sysSave); RefreshSavePic(); }
/* demo 1.22 去除 * public void SetGameVar(string key, object value) * { * datapool.WriteGameVar(key, value); * } * * public void SetInTurnVar(string key, object value) * { * datapool.WriteInTurnVar(key, value); * } * * public void SetSystemVar(string key, object value) * { * datapool.WriteSystemVar(key, value); * } * public T GetGameVar<T>(string key) * { * return (T)datapool.GetGameVar(key); * } * * public T GetInTurnVar<T>(string key) * { * return (T)datapool.GetInTurnVar(key); * } * * public T GetSystemVar<T>(string key) * { * return (T)datapool.GetSystemVar(key); * } * * public bool ContainsGameVar(string key) { return datapool.GetGameVarTable().ContainsKey(key); } * * public bool ContainsInTurnVar(string key) { return datapool.GetInTurnVarTable().ContainsKey(key); } * * DataPool GetDataPool() { return datapool; } * * public Hashtable GetGameVars() * { * return datapool.GetGameVarTable(); * } * public Hashtable GetInTurnVars() * { * return datapool.GetInTurnVarTable(); * } * public Hashtable GetSystemVars() * { * return datapool.GetSystemTable(); * } */ #endregion #region 存读档用 public void Save(int i) { string toSave = DataToJsonString(); string filename = "data" + i + ".sav"; SaveLoadTool.SaveFile(SaveLoadTool.GetSavePath(filename), toSave); //储存截图 string picname = "data" + i + ".png"; byte[] picdata = (byte[])tempData.GetTempVar("缩略图"); SaveLoadTool.CreatByteFile(SaveLoadTool.GetSavePath(picname), picdata); //更新存档信息 Dictionary <int, SavingInfo> savedic = tempData.saveInfo; //TODO: 获取状态 SavingInfo info = new SavingInfo(); info.gameMode = gameData.MODE; info.saveTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm"); info.saveText = "存档了!"; info.currentText = tempData.currentText; info.picPath = picname; //SavingInfo info = new SavingInfo(gamemode, savetime, customtext, picname); if (savedic.ContainsKey(i)) { savedic[i] = info; } else { savedic.Add(i, info); } //写入系统存档 string sysSave = JsonConvert.SerializeObject(savedic); SaveLoadTool.SaveFile(SaveLoadTool.GetSavePath("datasv.sav"), sysSave); RefreshSavePic(); }